跟着官网学k8s-05运行应用程序的多个实例
一般情况下pod的数量不会是一个,多个pod可以让服务更加的可靠并且可以承受更大的流量。service的type类型可以为LoadBalancer即负载均衡。使用该类型service需要指定外部负载均衡器的ip以及nodeport和clusterip查看deployment和ReplicaSet,ReplicaSet的命名格式为【deployment】-【随机字符串】$ kubectl get d
·
一般情况下pod的数量不会是一个,多个pod可以让服务更加的可靠并且可以承受更大的流量。
service的type类型可以为LoadBalancer即负载均衡。使用该类型service需要指定外部负载均衡器的ip以及nodeport和clusterip
查看deployment和ReplicaSet,ReplicaSet的命名格式为【deployment】-【随机字符串】
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
kubernetes-bootcamp 1/1 1 1 3m21s
$ kubectl get rs
NAME DESIRED CURRENT READY AGE
kubernetes-bootcamp-fb5c67579 1 1 1 4m6s
ReplicaSet的desired为启动程序所需的副本数量,current为当前运行的副本数量
使用kubectl scale命令扩容
$ kubectl scale deployments/kubernetes-bootcamp --replicas=4
deployment.apps/kubernetes-bootcamp scaled
$ kubectl get rs
NAME DESIRED CURRENT READY AGE
kubernetes-bootcamp-fb5c67579 4 4 4 8m33s
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
kubernetes-bootcamp 4/4 4 4 9m22s
此时副本已经被扩容到了4个,对应的pod数量也随之增长
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kubernetes-bootcamp-fb5c67579-kwng8 1/1 Running 0 3m20s 172.18.0.8 minikube <none> <none>
kubernetes-bootcamp-fb5c67579-vxrl5 1/1 Running 0 9m45s 172.18.0.4 minikube <none> <none>
kubernetes-bootcamp-fb5c67579-w7w4s 1/1 Running 0 3m20s 172.18.0.9 minikube <none> <none>
kubernetes-bootcamp-fb5c67579-zfl6g 1/1 Running 0 3m20s 172.18.0.7 minikube <none> <none>
这些deployment的变化被记录在deployment时事件日志中
$ kubectl describe deployments/kubernetes-bootcamp
Name: kubernetes-bootcamp
Namespace: default
CreationTimestamp: Wed, 10 Nov 2021 15:52:21 +0000
Labels: app=kubernetes-bootcamp
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=kubernetes-bootcamp
Replicas: 4 desired | 4 updated | 4 total | 4 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=kubernetes-bootcamp
Containers:
kubernetes-bootcamp:
Image: gcr.io/google-samples/kubernetes-bootcamp:v1
Port: 8080/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: kubernetes-bootcamp-fb5c67579 (4/4 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 11m deployment-controller Scaled up replica set kubernetes-bootcamp-fb5c67579 to 1
Normal ScalingReplicaSet 4m52s deployment-controller Scaled up replica set kubernetes-bootcamp-fb5c67579 to 4
events显示了刚才操作的扩容事件
service负载均衡会把请求分流到不同的pod上
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-fb5c67579-zfl6g | v=1
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-fb5c67579-w7w4s | v=1
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-fb5c67579-vxrl5 | v=1
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-fb5c67579-kwng8 | v=1
同样的,可以使用scale缩容,但是副本数量没有变化,只是根据所需的副本数量停掉其他的pod
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kubernetes-bootcamp-fb5c67579-kwng8 1/1 Terminating 0 10m 172.18.0.8 minikube <none> <none>
kubernetes-bootcamp-fb5c67579-vxrl5 1/1 Running 0 17m 172.18.0.4 minikube <none> <none>
kubernetes-bootcamp-fb5c67579-w7w4s 1/1 Terminating 0 10m 172.18.0.9 minikube <none> <none>
kubernetes-bootcamp-fb5c67579-zfl6g 1/1 Running 0 10m 172.18.0.7 minikube <none>
更多推荐
已为社区贡献2条内容
所有评论(0)