Skip to content

Commit

Permalink
docs: add an app to Kubernetes apps section
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf committed Sep 25, 2024
1 parent 5207b01 commit bdc3153
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/kubernetes/apps/statefulset/service-nginx-headless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: nginxs # Plural because it sets up DNS for each replica in the StatefulSet (e.g. nginx-0.nginxs.default.svc.cluster.local)
spec:
type: ClusterIP
clusterIP: None # This makes it a "headless" service
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
13 changes: 13 additions & 0 deletions docs/kubernetes/apps/statefulset/service-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: nginx # singular since it points to a single cluster IP
spec:
type: ClusterIP
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80

45 changes: 45 additions & 0 deletions docs/kubernetes/apps/statefulset/stateful.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx-with-init-containers
spec:
serviceName: nginxs # Headless service
replicas: 3
selector:
matchLabels:
app: nginx-app
template:
metadata:
labels:
app: nginx-app
spec:
initContainers:
- name: populate-default-html
image: nginx:1.26.0
command:
- bash
- "-c"
- |
set -ex
[[ $HOSTNAME =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
echo "<h1>Hello from pod $ordinal</h1>" > /usr/share/nginx/html/index.html
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
containers:
- name: nginx
image: nginx:1.26.0
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html

volumeClaimTemplates: # PersistentVolumeClaim templates for each replica
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "standard"
resources:
requests:
storage: 100Mi

0 comments on commit bdc3153

Please sign in to comment.