部署无状态应用
部署
运行两个 nginx 容器。
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
运行配置文件
kubectl apply -f https://k8s.io/examples/application/deployment.yaml
查看 deployment 信息
kubectl describe deployment nginx-deployment
查看 pods 列表
kubectl get pods -l app=nginx
查看 pod 信息
kubectl describe pod <pod-name>
升级
修改配置后重新 apply 一下配置文件即可更新,比如更新 image 版本,或者更新 replicas 的数量。
删除
kubectl delete deployment nginx-deployment