Skip to content

Commit 0b77ecf

Browse files
committed
feat(k8s): statefulset
1 parent 33e9c7a commit 0b77ecf

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

app/statefulset.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: training-statefulset-service
5+
labels:
6+
app: training-statefulset
7+
spec:
8+
ports:
9+
- port: 80
10+
protocol: TCP
11+
nodePort: 30008
12+
type: LoadBalancer
13+
selector:
14+
app: training-statefulset
15+
---
16+
apiVersion: apps/v1beta1
17+
kind: StatefulSet
18+
metadata:
19+
name: training-statefulset
20+
spec:
21+
serviceName: "training-statefulset-service"
22+
replicas: 2
23+
selector:
24+
matchLabels:
25+
app: training-statefulset
26+
template:
27+
metadata:
28+
labels:
29+
app: training-statefulset
30+
spec:
31+
containers:
32+
- name: nginx
33+
image: k8s.gcr.io/nginx-slim:0.8
34+
ports:
35+
- containerPort: 80
36+
volumeMounts:
37+
- name: www
38+
mountPath: /usr/share/nginx/html
39+
volumeClaimTemplates:
40+
- metadata:
41+
name: www
42+
spec:
43+
accessModes: [ "ReadWriteOnce" ]
44+
resources:
45+
requests:
46+
storage: 1Gi

commands.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,15 @@ pod=$(kubectl get pods --show-all --selector=app=training --output=jsonpath={.i
8787
kubectl exec -it $pod -c training /bin/sh
8888
cat /etc/config/training.type
8989
echo $NODE_ENV
90+
91+
### statefulset ###
92+
# terminal 1
93+
kubectl get pods -w -l app=training-statefulset
94+
# terminal 2
95+
kubectl create -f ./statefulset.yaml
96+
kubectl get statefulset training-statefulset
97+
for i in 0 1; do kubectl exec training-statefulset-$i -- sh -c 'echo $(hostname) > /usr/share/nginx/html/index.html'; done
98+
for i in 0 1; do kubectl exec -it training-statefulset-$i -- curl localhost; done
99+
minikube service training-statefulset-service
100+
kubectl delete statefulset training-statefulset
101+
# deletes statefulset and pods, use --cascade=false to keep pods

0 commit comments

Comments
 (0)