Controller-Deployment
- 1、什么是controller
- 2、 pod和controller关系
- 3、Deployment控制器应用场景
- 3.1 部署时yaml文件书写
- 3.2 实际部署应用
- 3.3 升级回滚
-
- 3.4 弹性伸缩
1、什么是controller
2、 pod和controller关系
- pod是通过Controller实现应用的运维,比如伸缩、滚动升级等
- pod和Controller之间通过label建立关系。通过下图进行深刻理解
3、Deployment控制器应用场景
- 一般部署无状态应用
- 管理Pod和ReplicaSet
- 部署,滚动升级等功能
- 应用场景:web服务、微服务
3.1 部署时yaml文件书写
[root@master example]
[root@master example]
apiVersion: apps/v1
kind: Deployment
metadata:creationTimestamp: nulllabels: app: webname: web
spec:replicas: 1selector: matchLabels:app: webstrategy: {}template: metadata:creationTimestamp: nulllabels:app: webspec:containers:- image: nginxname: nginxresources: {}
status: {}
3.2 实际部署应用
[root@master example]
[root@master example]
[root@master example]
[root@master example]
[root@master example]
apiVersion: v1
kind: Service
metadata:creationTimestamp: "2022-05-05T12:57:40Z"labels:app: webmanagedFields:- apiVersion: v1fieldsType: FieldsV1fieldsV1:f:metadata:f:labels:.: {}f:app: {}f:spec:f:externalTrafficPolicy: {}f:ports:.: {}k:{"port":80,"protocol":"TCP"}:.: {}f:port: {}f:protocol: {}f:targetPort: {}f:selector:.: {}f:app: {}f:sessionAffinity: {}f:type: {}manager: kubectl-exposeoperation: Updatetime: "2022-05-05T12:57:40Z"name: webexposenamespace: defaultresourceVersion: "184540"uid: b79e14cb-2b1b-44c1-b626-f4903786fb8a
spec:clusterIP: 10.103.24.195clusterIPs:- 10.103.24.195externalTrafficPolicy: Clusterports:- nodePort: 30605port: 80protocol: TCPtargetPort: 80selector:app: websessionAffinity: Nonetype: NodePort
status:loadBalancer: {}
[root@master example]
NAME READY STATUS RESTARTS AGE
pod/mypod 1/1 Running 0 10h
pod/nginx 1/1 Running 1 27h
pod/web-96d5df5c8-kkmsz 1/1 Running 0 10mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 57d
service/webexpose NodePort 10.103.24.195 <none> 80:30605/TCP 21s
3.3 升级回滚
3.3.1 升级
[root@master example]
[root@master example]
apiVersion: apps/v1
kind: Deployment
metadata:creationTimestamp: nulllabels:app: webname: web
spec:replicas: 2selector:matchLabels:app: webstrategy: {}template:metadata:creationTimestamp: nulllabels:app: webspec:containers:- image: nginx:1.14name: nginxresources: {}
status: {}
[root@master example]
deployment.apps/web created
[root@master example]
NAME READY STATUS RESTARTS AGE
web-5bb6fd4c98-bskvw 1/1 Running 0 3s
web-5bb6fd4c98-qtv8q 0/1 ContainerCreating 0 3s
[root@master example]
NAME READY STATUS RESTARTS AGE
web-5bb6fd4c98-bskvw 1/1 Running 0 30s
web-5bb6fd4c98-qtv8q 1/1 Running 0 30s
[root@master example]
[root@master example]
deployment "web" successfully rolled out
3.3.2 回滚
[root@master example]
deployment.apps/web
REVISION CHANGE-CAUSE
1 <none>
2 <none>[root@master example]
deployment.apps/web rolled back
[root@master example]
deployment "web" successfully rolled out
[root@master example]
NAME READY STATUS RESTARTS AGE
web-5bb6fd4c98-hm2jt 1/1 Running 0 17s
web-5bb6fd4c98-nmjcg 1/1 Running 0 16s
[root@master example]
[root@master example]
deployment.apps/web rolled back
[root@master example]
deployment "web" successfully rolled out
3.4 弹性伸缩
[root@master example]
deployment.apps/web scaled
[root@master example]
NAME READY STATUS RESTARTS AGE
web-f686c9cdf-72fhz 1/1 Running 0 4s
web-f686c9cdf-7kxgm 1/1 Running 0 4s
web-f686c9cdf-89zwq 1/1 Running 0 3m6s
web-f686c9cdf-gm6r6 1/1 Running 0 3m5s
web-f686c9cdf-q45v2 1/1 Running 0 4s