您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
26、 资源控制器 - RS、Deployment
发布时间:2022-12-18 00:02:54编辑:雪饮阅读()
Step1
查看rs的相关帮助信息
kubectl explain rs
Step2
建立一个rs模板
[root@k8s-master01 ~]# cat rs.yaml
apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
name: frontend
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: myapp
image: hub.atguigu.com/library/myapp:v1
env:
- name: GET_HOSTS_FROM
value: dns
然后创建rs
[root@k8s-master01 ~]# kubectl create -f rs.yaml
replicaset.extensions/frontend created
查看pod
[root@k8s-master01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
frontend-7kz8x 1/1 Running 0 81s
frontend-fds4r 1/1 Running 0 81s
frontend-mchk4 1/1 Running 0 81s
lifecycle-demo 1/1 Running 1 26h
liveness-httpget-pod 0/1 Running 3 2d
有3个pod关联,是因为我们rs模板上配置的副本数为3
然后删除所有pod
[root@k8s-master01 ~]# kubectl delete pod --all
pod "frontend-7kz8x" deleted
pod "frontend-fds4r" deleted
pod "frontend-mchk4" deleted
pod "lifecycle-demo" deleted
pod "liveness-httpget-pod" deleted
这次查看pod并且显示lables发现这3个pod还在,毕竟是期望值为3吧
[root@k8s-master01 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
frontend-5xdss 1/1 Running 0 20s tier=frontend
frontend-6w4qw 1/1 Running 0 20s tier=frontend
frontend-fzvdg 1/1 Running 0 20s tier=frontend
Step3
给pod打标签
[root@k8s-master01 ~]# kubectl label pod frontend-5xdss tier=frontend1
error: 'tier' already has a value (frontend), and --overwrite is false
[root@k8s-master01 ~]# kubectl label pod frontend-5xdss tier=frontend1 --overwrite=true
pod/frontend-5xdss labeled
可以发现如果pod已经存在标签,则无法打标签,除非使用--overwrite=true
再次查看pod竟然达到4个了?
[root@k8s-master01 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
frontend-5xdss 1/1 Running 0 8m30s tier=frontend1
frontend-6w4qw 1/1 Running 0 8m30s tier=frontend
frontend-9ppvc 1/1 Running 0 3m40s tier=frontend
frontend-fzvdg 1/1 Running 0 8m30s tier=frontend
这是因为期望副本为3,是基于label的,由于其中一个被修改了tier,则无法达到期望副本数为3,所以所谓的打标签,再这里相当于是新建了一个新的条目。
再次删除全部
[root@k8s-master01 ~]# kubectl delete pod --all
pod "frontend-5xdss" deleted
pod "frontend-6w4qw" deleted
pod "frontend-9ppvc" deleted
pod "frontend-fzvdg" deleted
[root@k8s-master01 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
frontend-5vck6 1/1 Running 0 12s tier=frontend
frontend-7778p 1/1 Running 0 12s tier=frontend
frontend-hcjhm 1/1 Running 0 12s tier=frontend
Step4
创建deployment模板
[root@k8s-master01 ~]# cat deployment.yaml
apiVersion : extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: hub.atguigu.com/library/myapp:v1
ports:
- containerPort: 80
然后创建deployment
[root@k8s-master01 ~]# kubectl apply -f deployment.yaml --record
deployment.extensions/nginx-deployment created
然后这里删除下上面Step4中创建的rs(只是清理残余,没有什么用意)
[root@k8s-master01 ~]# kubectl delete rs frontend
replicaset.extensions "frontend" deleted
然后查看deployment
[root@k8s-master01 ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 3 3 66s
以及对应的rs
[root@k8s-master01 ~]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-5df65767f 3 3 3 2m3s
其实总体来说可以看到deployment与rs与pod之间的关联关系
[root@k8s-master01 ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 3 3 4m51s
[root@k8s-master01 ~]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-5df65767f 3 3 3 4m54s
[root@k8s-master01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deployment-5df65767f-skm5n 1/1 Running 0 4m56s
nginx-deployment-5df65767f-vbw8f 1/1 Running 0 4m56s
nginx-deployment-5df65767f-xrvsh 1/1 Running 0 4m56s
关键字词:资源控制器,RS,Deployment
相关文章
- 08-Maven坐标(groupId,artifactId,version)
- 15_Jedis_操作set&sortedset(sadd、zadd、members、zr
- 踩坑系列-php的max_input_vars, php post 最大接收数
- sqlserver連接錯誤SSL routinesssl_choose_client_ver
- workerman-redis-sMembers
- workerman-redis-sInterStore
- workerman类TcpConnection的maxSendBufferSize属性(缓
- workerman类TcpConnection的defaultMaxSendBufferSize
- workerman回调onWorkerStart
- workerman利用Timer库的persistent属性实现仅定时执行