k8s实战三 创建无状态应用
程序员文章站
2022-03-01 17:25:14
...
k8s实战三 创建无状态应用
1 关于nginx的无状态应用
关于nginx1.7的版本
cat deployment.yaml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
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.7.9
ports:
- containerPort: 80
通过yaml创建pod
kubectl apply -f deployment.yaml
查看 deployment的细节
kubectl describe deployment nginx-deployment
查看所有相关的pod (通过selector)
kubectl get pods -l app=nginx
查看详细的pod
kubectl describe pod <pod-name>
升级deployment
更改deployment.yaml如下
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.8 # Update the version of nginx from 1.7.9 to 1.8
ports:
- containerPort: 80
开始部署
kubectl apply -f deployment.yaml
查看更新状态
kubectl get pods -l app=nginx
实时更新 replica 数
更改deployment.yaml
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 4 # Update the replicas from 2 to 4
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.8
ports:
- containerPort: 80
开始部署
kubectl apply -f deployment.yaml
查看更新状态
kubectl get pods -l app=nginx
删除deployment
kubectl delete deployment nginx-deployment
上一篇: PHP数据库操作:PDO基本操作
下一篇: ubuntu下安装微信小程序开发工具