Kubernetes 入門
Frank Heilmann
Platform Architect and Freelance Instructor
有狀態應用:
當中斷或停止時,新的副本(Pod) 可讀取已保存的狀態並從該狀態繼續運作
apiVersion、kind、metadata、spec、templatereplicas 定義 StatefulSet 中的 Pod 數量selector 之後再說明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 與 Deployments 類似:
kubectl apply -f <manifest.yml>Deployment 不同:pod-0、pod-1、pod-2 等StatefulSet 中不同身分的 Pods
可在應用中負責不同角色replicas 並重新套用kubectl scale statefulsets ...pod-0、pod-1、pod-2,接著新增 pod-3,
再加入 pod-4pod-4,再刪 pod-3kubectl 進行基本監控kubectl get pods 會列出 StatefulSet 中所有 pods 與其目前狀態kubectl get services 會列出 StatefulSet 可能使用的所有 servicesKubernetes 入門