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 与 Deployment 类似:
kubectl apply -f <manifest.yml>pod-0、pod-1、pod-2 等StatefulSet 中不同身份的 Pod 可在应用中承担不同角色replicas 并重新应用kubectl scale statefulsets ...pod-0、pod-1、pod-2,再添加 pod-3,
然后是 pod-4pod-4,再删 pod-3kubectl 执行基本监控任务kubectl get pods 返回 StatefulSet 中所有 Pod 及其状态kubectl get services 返回 StatefulSet 可能使用的所有 ServiceKubernetes 入门