k8s日常使用命令scale彈性伸縮pod
阿新 • • 發佈:2018-10-25
tip status 增加 mas available 彈性 tar yam sta 1.
目前是三個pod
目前是三個pod
[root@k8s-master1 service_pod]# kubectl get pod NAME? ? ? ? ? ? ? ? ? ?? READY? ?? STATUS? ? RESTARTS?? AGE mysql-5bbbf49b4f-p7zkz?? 1/1? ? ?? Running?? 0? ? ? ? ? 2m mysql-5bbbf49b4f-vhj44?? 1/1? ? ?? Running?? 1? ? ? ? ? 2m mysql-5bbbf49b4f-xzpwn?? 1/1? ? ?? Running?? 1? ? ? ? ? 2m [root@k8s-master1 service_pod]#
想擴大到5個pod
官方參考命令格式,見下:
Examples: ? # Scale a replicaset named ‘foo‘ to 3. ? kubectl scale --replicas=3 rs/foo ? # Scale a resource identified by type and name specified in "foo.yaml" to 3. ? kubectl scale --replicas=3 -f foo.yaml ? # If the deployment named mysql‘s current size is 2, scale mysql to 3. ? kubectl scale --current-replicas=2 --replicas=3 deployment/mysql ? # Scale multiple replication controllers. ? kubectl scale --replicas=5 rc/foo rc/bar rc/baz ? # Scale statefulset named ‘web‘ to 3. ? kubectl scale --replicas=3 statefulset/web
2.
減少pod
測試下參考命令
[root@k8s-master1 service_pod]# kubectl get deployment NAME? ? ? DESIRED?? CURRENT?? UP-TO-DATE?? AVAILABLE?? AGE mysql? ?? 3? ? ? ?? 3? ? ? ?? 3? ? ? ? ? ? 3? ? ? ? ?? 9m [root@k8s-master1 service_pod]# kubectl scale --current-replicas=3 --replicas=1 deployment/mysql deployment.extensions "mysql" scaled [root@k8s-master1 service_pod]# kubectl get deployment NAME? ? ? DESIRED?? CURRENT?? UP-TO-DATE?? AVAILABLE?? AGE mysql? ?? 1? ? ? ?? 1? ? ? ?? 1? ? ? ? ? ? 1? ? ? ? ?? 10m
3.
增加pod
測試下命令
[root@k8s-master1 service_pod]# kubectl get deployment
NAME? ? ? DESIRED?? CURRENT?? UP-TO-DATE?? AVAILABLE?? AGE
mysql? ?? 1? ? ? ?? 1? ? ? ?? 1? ? ? ? ? ? 1? ? ? ? ?? 13m
[root@k8s-master1 service_pod]# kubectl scale --current-replicas=1 --replicas=3 deployment/mysql
deployment.extensions "mysql" scaled
[root@k8s-master1 service_pod]# kubectl get pod
NAME? ? ? ? ? ? ? ? ? ?? READY? ?? STATUS? ? RESTARTS?? AGE
mysql-5bbbf49b4f-96v7g?? 1/1? ? ?? Running?? 0? ? ? ? ? 5s
mysql-5bbbf49b4f-f6rlg?? 1/1? ? ?? Running?? 0? ? ? ? ? 5s
mysql-5bbbf49b4f-p7zkz?? 1/1? ? ?? Running?? 0? ? ? ? ? 13m
[root@k8s-master1 service_pod]#
k8s日常使用命令scale彈性伸縮pod