赞
踩
replicationcontrollers控制器资源,简称:rc控制器;
简单理解,rc控制器就是控制相同的pod副本数量;
使用rc控制器资源创建pod,就可以设定创建pod的数量;
[root@k8s231 rc]# vim rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: rc01
spec:
#控制pod的副本数量
replicas: 5
#选择要创建副本的pod的标签(关联pod标签,把谁的副本设置成5个呀?)
selector:
k8s: xinjizhiwa
#下面就是你要控制的pod了(就是pod资源的编辑);
template:
metadata:
name: pod-01
labels:
k8s: xinjizhiwa
spec:
containers:
- name: c1
image: nginx:1.20.1-alpine
ports:
- containerPort: 80
[root@k8s231 rc]# kubectl apply -f rc.yaml
[root@k8s231 rc]# kubectl get rc
[root@k8s231 rc]# kubectl delete rc rc01
1,rc控制器创建的pod是按照标签进行副本数量控制的;
2,rc控制器资源创建的pod,直接删除pod,还会重新拉起,只有删除rc资源,pod才会消失;
3,修改rc资源,需要重新编rc资源清单,再次apply就可以修改了;
第一个镜像
[root@k8s231 dockerfile]# cat Dockerfile
FROM nginx:1.20.1-alpineCOPY code/v1 /usr/share/nginx/html/index.html
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
[root@k8s231 dockerfile]# cat code/v1
v1:xinjizhiwa-01
[root@k8s231 dockerfile]# cat b1.sh
#!/bin/bash
docker login -u admin -p 1 harbor.xinjizhiwa.comdocker image build -t harbor.xinjizhiwa.com/xinjizhiwa-nginx/nginx:v1 .
docker push harbor.xinjizhiwa.com/xinjizhiwa-nginx/nginx:v1
第二个镜像
[root@k8s231 dockerfile]# cat Dockerfile
FROM nginx:1.20.1-alpineCOPY code/v2 /usr/share/nginx/html/index.html
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
[root@k8s231 dockerfile]# cat code/v1
v2:xinjizhiwa-02
[root@k8s231 dockerfile]# cat b1.sh
#!/bin/bash
docker login -u admin -p 1 harbor.xinjizhiwa.comdocker image build -t harbor.xinjizhiwa.com/xinjizhiwa-nginx/nginx:v2 .
docker push harbor.xinjizhiwa.com/xinjizhiwa-nginx/nginx:v2
[root@k8s231 rc]# cat rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: rc-nginx
spec:
#控制pod的副本数量
replicas: 3
#选择要创建副本的pod的标签(关联pod标签,把谁的副本设置成n个呀?)
selector:
k8s: xinjizhiwa
#下面就是你要控制的pod了(就是pod资源的编辑);
template:
metadata:
name: pod-nginx
labels:
k8s: xinjizhiwa
spec:
containers:
- name: c1
image: harbor.xinjizhiwa.com/xinjizhiwa-nginx/nginx:v1
ports:
- containerPort: 80
command:
- "nginx"
- "-g"
- "daemon off;"
---
#编辑service资源用于外部访问
apiVersion: v1
kind: Service
metadata:
name: svc-rc-nginx
spec:
type: NodePort
clusterIP: 10.200.10.10
selector:
k8s: xinjizhiwa
ports:
- port: 88
targetPort: 80
nodePort: 30001
[root@k8s231 rc]# kubectl apply -f rc.yaml
[root@k8s231 rc]# cat rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: rc-nginx
spec:
#控制pod的副本数量
replicas: 3
#选择要创建副本的pod的标签(关联pod标签,把谁的副本设置成n个呀?)
selector:
k8s: xinjizhiwa
#下面就是你要控制的pod了(就是pod资源的编辑);
template:
metadata:
name: pod-nginx
labels:
k8s: xinjizhiwa
spec:
containers:
- name: c1
image: harbor.xinjizhiwa.com/xinjizhiwa-nginx/nginx:v2
ports:
- containerPort: 80
command:
- "nginx"
- "-g"
- "daemon off;"
---
#编辑service资源用于外部访问
apiVersion: v1
kind: Service
metadata:
name: svc-rc-nginx
spec:
type: NodePort
clusterIP: 10.200.10.10
selector:
k8s: xinjizhiwa
ports:
- port: 88
targetPort: 80
nodePort: 30001
[root@k8s231 rc]# kubectl apply -f rc.yaml
删除后会自动重新拉取pod,就会拉取最新的pod了;
[root@k8s231 rc]# kubectl delete pods --all
########################################
rc控制器方式,生产环境当中,从来不用;只是为了教学,模拟使用rc迭代;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。