kubernetes 更改副本数量

 我们使用控制器复制一个tomcat.yaml 对象如下,设置myweb的副本为1.发布nodePort 为30001

apiVersion: v1
kind: ReplicationController
metadata:
 name: mysql
spec:
 replicas: 1
 selector:
  app: mysql
 template:
   metadata:
    labels:
     app: mysql
   spec:
    containers:
    - name: mysql
      image: mysql
      ports:
      - containerPort: 3306
      env:
      - name: MYSQL_ROOT_PASSWORD
        value: "123456"
---
apiVersion: v1
kind: Service
metadata:
 name: mysql
spec:
 ports:
  - port: 3306
 selector:
  app: mysql
---
apiVersion: v1
kind: ReplicationController
metadata:
 name: myweb
spec:
 replicas: 1
 selector:
  app: myweb
 template:
  metadata:
   labels:
    app: myweb
  spec:
   containers:
    - name: myweb
      image: kubeguide/tomcat-app:v1
      ports:
      - containerPort: 8080
      env:
      - name: MYSQL_SERVICE_HOST
        value: 'mysql'
      - name: MYSQL_SERVICE_PORT
        value: '3306'
---
apiVersion: v1
kind: Service
metadata:
 name: myweb
spec:
 type: NodePort
 ports:
  - port: 8080
    nodePort: 30001
 selector:
  app: myweb

拉起RC

kubectl create -f tomcat.yaml

 查看所有的服务器对象有没有启动,看到下面结果表示启动成功。


[root@centos7v4-k8s ~]# kubectl  get pod
NAME          READY   STATUS    RESTARTS   AGE
mysql-7jjdv   1/1     Running   0          5h39m
myweb-k9sd4   1/1     Running   0          5h39m
nginx         1/1     Running   0          2d
[root@centos7v4-k8s ~]# kubectl  get rc
NAME    DESIRED   CURRENT   READY   AGE
mysql   1         1         1       5h51m
myweb   1         1         1       5h51m
[root@centos7v4-k8s ~]# kubectl  get svc
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
kubernetes       ClusterIP   10.10.0.1                 443/TCP          3d8h
mysql            ClusterIP   10.10.227.248             3306/TCP         5h52m
myweb            NodePort    10.10.105.196             8080:30001/TCP   5h52m

访问服务成功,其中192.168.11.62可以是集群中的一个任意节点。

kubernetes 更改副本数量_第1张图片

启动另外2个副本

[root@centos7v4-k8s ~]#  kubectl scale rc myweb --replicas  3
replicationcontroller/myweb scaled

 过一段时间再看系统已经起来了。

[root@centos7v4-k8s ~]# kubectl  get pod
NAME          READY   STATUS    RESTARTS   AGE
mysql-7jjdv   1/1     Running   0          6h12m
myweb-fthjm   1/1     Running   0          17m
myweb-gs68w   1/1     Running   0          17m
myweb-k9sd4   1/1     Running   0          6h12m
nginx         1/1     Running   0          2d1h

 

你可能感兴趣的:(云维护及交付技术,运维及部署,kubernetes,docker,yaml)