Introduction to Kubernetes
Frank Heilmann
Platform Architect and Freelance Instructor
แอปแบบ Stateful:
เมื่อถูกหยุดหรือขัดจังหวะ Replica ใหม่ (Pod) สามารถอ่าน State ที่บันทึกไว้และทำงานต่อจากจุดนั้นได้
apiVersion, kind, metadata, spec, templatereplicas กำหนดจำนวน Pod ใน StatefulSetselector จะกล่าวถึงในภายหลังapiVersion: apps/v1
kind: StatefulSet
metadata:
name: <deployment name>
labels:
app: <a label for the application>
spec:
replicas: <number of initial replicas>
selector:
matchLabels:
app: <matches the label above>
template:
metadata:
labels:
app: <label to be given to each pod>
spec:
containers:
- name: <container name>
image: <the image to be used>
ports:
- containerPort: <ports for networking>
StatefulSet ถูก deploy คล้ายกับ Deployments:
kubectl apply -f <manifest.yml>StatefulSet จะถูกสร้างต่างจาก Deployment:pod-0, pod-1, pod-2 เป็นต้นStatefulSet ที่มี Identity ต่างกันสามารถทำหน้าที่ต่างกันในแอปพลิเคชันได้replicas ใน Manifest แล้ว apply ใหม่kubectl scale statefulsets ...pod-0, pod-1, pod-2 แล้ว pod-3
จากนั้น pod-4 จะถูกเพิ่มpod-4 ก่อน แล้วจึง pod-3kubectl สำหรับงาน Monitor พื้นฐานkubectl get pods แสดง Pod ทั้งหมดใน StatefulSet
พร้อมสถานะปัจจุบันkubectl get services แสดง Service ทั้งหมดที่
StatefulSet อาจใช้งานIntroduction to Kubernetes