--- title: StatefulSet # 簡報的名稱 tags: K8s # 簡報的標籤 --- # StatefulSet > [name=李俊毅] > [time=Wed, Feb 5, 2020 1:04 PM] --- ## Agenda * 介紹 * 範例 * StatefulSet與Service的關係 * 常用的CLI --- ## 介紹 ---- StatefulSet,可縮寫為sts,管理有狀態應用,可以控制Pod與管理Pod擴展和伸縮,Pod Name為有序命名,命名規則為 Pod Name- 加上 UID --- ## 範例 ---- hello-world.yaml ``` apiVersion: apps/v1 kind: StatefulSet metadata: labels: app.kubernetes.io/name: load-balancer-example name: hello-world spec: replicas: 5 selector: matchLabels: app.kubernetes.io/name: load-balancer-example serviceName: hello-world podManagementPolicy: Parallel template: metadata: labels: app.kubernetes.io/name: load-balancer-example spec: containers: - image: gcr.io/google-samples/node-hello:1.0 name: hello-world ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: hello-world spec: type: ClusterIP clusterIP: None selector: app.kubernetes.io/name: load-balancer-example ports: - port: 8080 ``` --- ## StatefulSet 與 Service 的關係 ---- StatefulSet 在建立時,需要搭配 Service 才能建成功,因 StatefulSet 為有狀態,搭配的 Service 為 Headless Service ,透過此 Service 可以做到指定Pod為服務對象 ----   --- ## 常用的CLI ---- ### 查詢 statefulset ---- ``` kubectl get sts ```  ---- ### 確認 statefulset 狀況 ---- ``` kubectl describe sts hello-world ```  ---- ### 查看或修改運行中 statefulset ---- ``` kubectl edit sts hello-world ```  ---- ### 查看 Pod ``` kubectl get pods -o wide ``` ---- 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up