k8s-rc资源创建、滚动升级
警告
本文最后更新于 2020-05-30 17:09,文中内容可能已过时。
镜像需要提前准备好,registry:5000是本地私有仓库地址
1.创建一个rc资源
kubectl create -f nginx-rc.yaml
nginx-rc.yaml:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 5
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: registry:5000/nginx:1.13
ports:
- containerPort: 80
2.创建svc资源(提供网络访问、暴露端口)
kubectl create -f nginx-svc.yaml
nginx-svc.yaml:
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:
- port: 80
nodePort: 30001
targetPort: 80
selector:
app: myweb
3.查看pod状态,都为running
kubectl get all -o wide
打开测试访问:
http://10.0.0.13:3001
将nginx1.13升级到nginx1.15
镜像升级
1.指定镜像升级,每10秒升级一个
kubectl rolling-update nginx --image=registry:5000/nginx:1.15 --update-period=10s
yaml文件升级和回滚
2.基于yaml文件升级
kubectl rolling-update nginx -f nginx-rc1.15.yaml --update-period=10s #修改svc的标签选择器为myweb2 kubectl edit svc myweb selector: app: myweb2
nginx-rc1.15.yaml:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx2
spec:
replicas: 5
selector:
app: myweb2
template:
metadata:
labels:
app: myweb2
spec:
containers:
- name: myweb2
image: registry:5000/nginx:1.15
ports:
- containerPort: 80
回滚:
kubectl rolling-update nginx2 -f nginx-rc.yaml --update-period=1s #修改svc的标签选择器为myweb kubectl edit svc myweb selector: app: myweb
请我喝杯水
微信号
微信打赏