k8s-deployment资源创建、升级、回滚
警告
本文最后更新于 2020-05-30 17:09,文中内容可能已过时。
1.创建资源(–record可以记录历史版本,方便回滚)
kubectl create -f nginx-deploy.yaml --record
nginx-deploy.yaml:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: registry:5000/nginx:1.13
ports:
- containerPort: 80
resources:
limits:
cpu: 100m
requests:
cpu: 100m
2.创建svc资源(提供网络访问、暴露端口)
apiVersion: v1
kind: Service
metadata:
name: nginx-deployment
spec:
type: NodePort
ports:
- port: 80
nodePort: 3002
targetPort: 80
selector:
app: nginx
镜像版本升级和回滚
升级镜像:
#参数说明 deployment :资源类型 nginx-deployment :资源名称 nginx=registry:5000/nginx:1.15:给指定的容器修改镜像。通过kubectl get rs -o wide查看CONTAINER(S)中容器的名称 kubectl set image deployment nginx-deployment nginx=registry:5000/nginx:1.15
查看历史版本:
#参数说明 deployment :资源类型 nginx-deployment :资源名称 kubectl rollout history deployment nginx-deployment
回滚到上一个版本:
#参数说明 deployment :资源类型 nginx-deployment :资源名称 kubectl rollout undo deployment nginx-deployment
回滚到指定版本:
#参数说明 deployment :资源类型 nginx-deployment :资源名称 --to-revision=2 :回滚到指定版本,通过history可以查看 kubectl rollout undo deployment nginx-deployment --to-revision=2
请我喝杯水
微信号
微信打赏