[root@centos7-docker-test1 ~]# kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
centos7 centos7 centos:7 run=centos7 3 3h
mysql mysql mysql:5.5 run=mysql 7 3h
tomcat tomcat tomcat:8.0 run=tomcat 5 22h
[root@centos7-docker-test1 ~]# kubectl get po
NAME READY STATUS RESTARTS AGE
centos7-asa0g 0/1 CrashLoopBackOff 45 3h
centos7-eow3g 0/1 CrashLoopBackOff 45 3h
centos7-qmslb 0/1 CrashLoopBackOff 42 3h
mysql-0a5tv 0/1 CrashLoopBackOff 45 3h
mysql-131lh 0/1 CrashLoopBackOff 45 3h
mysql-7cj2s 0/1 CrashLoopBackOff 46 3h
mysql-89h04 0/1 CrashLoopBackOff 46 3h
mysql-htu4u 0/1 CrashLoopBackOff 46 3h
mysql-khndm 0/1 CrashLoopBackOff 46 3h
mysql-uke1c 0/1 CrashLoopBackOff 46 3h
tomcat-1wwbn 1/1 Running 1 22h
tomcat-f83z1 1/1 Running 1 22h
tomcat-fu2qf 1/1 Running 1 22h
tomcat-l39ih 1/1 Running 1 22h
tomcat-o647v 1/1 Running 1 22h
[root@centos7-docker-test1 kubernetes]# kubectl get po -o wide
NAME READY STATUS RESTARTS AGE NODE
centos7-igbjl 0/1 CrashLoopBackOff 10 28m 10.1.1.169
centos7-jpoyx 0/1 CrashLoopBackOff 10 28m 10.1.1.169
centos7-thu24 0/1 CrashLoopBackOff 10 28m 10.1.1.171
mysql-0nxwk 0/1 CrashLoopBackOff 10 29m 10.1.1.171
mysql-47jvi 0/1 CrashLoopBackOff 10 29m 10.1.1.171
mysql-7ggtp 0/1 CrashLoopBackOff 10 29m 10.1.1.169
mysql-hoi4c 0/1 CrashLoopBackOff 10 29m 10.1.1.169
mysql-md9ir 0/1 CrashLoopBackOff 10 29m 10.1.1.171
mysql-v0y6b 0/1 CrashLoopBackOff 10 29m 10.1.1.169
mysql-x7lh1 0/1 CrashLoopBackOff 10 29m 10.1.1.169
rc-tomcat8-2-0xxs6 1/1 Running 0 8m 10.1.1.171
rc-tomcat8-2-1l4iy 1/1 Running 0 17m 10.1.1.169
rc-tomcat8-2-igirv 1/1 Running 0 13m 10.1.1.169
rc-tomcat8-2-ih5bb 1/1 Running 0 18m 10.1.1.171
rc-tomcat8-2-qklgd 1/1 Running 0 15m 10.1.1.171
tomcat-1wwbn 1/1 Running 1 23h 10.1.1.169
tomcat-f83z1 1/1 Running 1 23h 10.1.1.171
tomcat-fu2qf 1/1 Running 1 23h 10.1.1.171
tomcat-l39ih 1/1 Running 1 23h 10.1.1.169
tomcat-o647v 1/1 Running 1 23h 10.1.1.169
[root@centos7-docker-test1 ~]# kubectl get namespace
NAME LABELS STATUS AGE
default
[root@centos7-docker-test1 ~]# kubectl get nodes
NAME LABELS STATUS AGE
10.1.1.169 kubernetes.io/hostname=10.1.1.169 Ready 22h
10.1.1.171 kubernetes.io/hostname=10.1.1.171 Ready 23h
制作yaml格式的pod 复制控制文件:
[root@centos7-docker-test1 kubernetes]# more rc-tomcat.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: rc-tomcat8-1
spec:
replicas: 4
template:
metadata:
labels:
app: tomcat8-1
spec:
containers:
- name: tomcat8-1
p_w_picpath: tomcat:8.0
ports:
- containerPort: 8080
[root@centos7-docker-test1 kubernetes]# kubectl create -f rc-tomcat.yaml
可以使用rolling-update更新部署且正在运行的业务,每次起一个新的pod,然后删除一个旧的,直到替换掉所有的pod。更新内容为不同的name,version,label才可以进行。也可以中断更新,使用-rollback回滚
可以使用scale进行副本数量的扩大和缩小
kubectl scale rc rc-tomcat8-2 --replicas=5
可以使用autoscale进行副本的自动扩展和缩小,有待验证
实例:启动多个apache容器副本:
[root@centos7-docker-test1 kubernetes]# more apache.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: my-apache
labels:
app: my-apache
spec:
replicas: 2
selector:
app: my-apache
template:
metadata:
labels:
app: my-apache
spec:
containers:
- name: my-apache
p_w_picpath: index.alauda.cn/tutum/apache-php:latest
ports:
- containerPort: 80
[root@centos7-docker-test1 kubernetes]# more apache-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: my-apache
labels:
app: my-apache
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30066
selector:
app: my-apache