k8s-使用kubectl扩容app

本篇文章演示如何使用kubectl来扩容app,扩容是通过更改部署中的副本数量来完成的
首先我们使用kubectl get deployments来列出default namespace中的所有的development

~> kubectl get deployments
NAME             DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
my-first-nginx   2         2         2            2           51m

我们应该有1个Pob, 在上面的命令输出中:

  • DESIRED状态显示配置的副本数
  • CURRENT状态显示现在运行的副本数
  • UP-TO-DATE是被更新以匹配期望(配置)状态的副本的数量
  • AVAILABLE状态显示实际可向用户提供多少副本

接下来,让我们将部署扩展到4个副本。 我们将使用kubectl scale命令:

~> kubectl scale deployments/my-first-nginx --replicas=4
deployment "my-first-nginx" scaled
~> kubectl get deployments
NAME             DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
my-first-nginx   4         4         4            2           57m
~> kubectl get pods -o wide
NAME                              READY     STATUS    RESTARTS   AGE       IP           NODE
my-first-nginx-3504586902-pc25v   1/1       Running   0          58m       172.17.0.5   minikube
my-first-nginx-3504586902-qrpb1   1/1       Running   0          58m       172.17.0.4   minikube
my-first-nginx-3504586902-sbt1g   1/1       Running   0          53s       172.17.0.7   minikube
my-first-nginx-3504586902-t6m5v   1/1       Running   0          53s       172.17.0.6   minikube

现在这里有4个Pods,并且每一个的ip都是不一样的。同时这些改变会注册到Deployment devents log中,可以使用下面的命令来进行查看:

~> kubectl describe deployments/my-first-nginx
Name:			my-first-nginx
Namespace:		default
CreationTimestamp:	Tue, 21 Mar 2017 16:36:39 +0800
Labels:			run=my-first-nginx
Selector:		run=my-first-nginx
Replicas:		4 updated | 4 total | 4 available | 0 unavailable
StrategyType:		RollingUpdate
MinReadySeconds:	0
RollingUpdateStrategy:	1 max unavailable, 1 max surge
Conditions:
  Type		Status	Reason
  ----		------	------
  Available 	True	MinimumReplicasAvailable
OldReplicaSets:	<none>
NewReplicaSet:	my-first-nginx-3504586902 (4/4 replicas created)
Events:
  FirstSeen	LastSeen	Count	From				SubObjectPath	Type		Reason			Message
  ---------	--------	-----	----				-------------	--------	------			-------
  2m		2m		1	{deployment-controller }			Normal		ScalingReplicaSet	Scaled up replica set my-first-nginx-3504586902 to 4

此时我们检查一下Service:

~> kubectl get services
NAME                     CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
kubernetes               10.0.0.1     <none>        443/TCP        1d
my-first-nginx-service   10.0.0.174   <nodes>       80:32650/TCP   51m
~>
~>
~> kubectl describe services/my-first-nginx-service
Name:			my-first-nginx-service
Namespace:		default
Labels:			run=my-first-nginx
Selector:		run=my-first-nginx
Type:			NodePort
IP:			10.0.0.174
Port:			<unset>	80/TCP
NodePort:		<unset>	32650/TCP
Endpoints:		172.17.0.4:80,172.17.0.5:80,172.17.0.6:80 + 1 more...
Session Affinity:	None
No events.
~>

在演示完扩容以后,接下来展示一下如何降低容量。下面将会降容到2个副本:

kubectl scale deployments/kubernetes-bootcamp --replicas=2

然后使用下面的命令进行检查:

kubectl get deployments
kubectl get pods -o wide
本文版权归作者所有,禁止一切形式的转载,复制等操作
赞赏

微信赞赏支付宝赞赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注