列出现有 deployment:
$ kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
kubernetes-bootcamp 1 1 1 1 17h
- DESIRED - 配置的副本数量。
- CURRENT - 当前运行的副本数量。
- UP-TO-DATE - 为了达到期望的数量而更新的副本数量。
- AVAILABLE - 对用户可用的副本数量。
扩展副本数量:
$ kubectl scale deployments/kubernetes-bootcamp --replicas=4
deployment.extensions/kubernetes-bootcamp scaled
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
kubernetes-bootcamp 4 4 4 4 7m
可以看到副本数量已经变了,下面访问一下试试。
查看service NodePort:
$ kubectl describe services/kubernetes-bootcamp
Name: kubernetes-bootcamp
Namespace: default
Labels: run=kubernetes-bootcamp
Annotations: <none>
Selector: run=kubernetes-bootcamp
Type: NodePort
IP: 10.98.171.64
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 32042/TCP
Endpoints: 10.244.2.2:8080,10.244.2.3:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
设置环境变量:
$ export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index.spec.ports 0).nodePort}}')
$ echo NODE_PORT=$NODE_PORT
NODE_PORT=30928
发起多次请求,会看到不同的 pod,说明负载均衡是正常工作的:
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5c69669756-vxqnp | v=1
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5c69669756-vxqnp | v=1
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5c69669756-rhn9b | v=1