$ kubectl expose po kubia --type=LoadBalancer --name kubia
service/kubia exposed
看看暴露的服务,我们申请了LoadBalancer,云商创建需要1-5分钟的时间,耐心等待下
$ k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubia LoadBalancer 10.100.114.238 aa4ace9d6de084763b9ca80bcccf121e-357969387.ap-east-1.elb.amazonaws.com 8080:30207/TCP 16s
看到了LoadBalancer后,测试一下,注意替换EXTERNAL-IP
$ curl http://<EXTERNAL-IP>:8080
You've hit kubia
这里因为暴露了服务给外网,在自己本地电脑也可以curl的,建议体会下
认识应用的逻辑组成
见课件
横向伸缩你的应用
首先清理之前的pod和service
zhaoying@zhaoying ~ $ kubectl delete svc kubia
service "kubia" deleted
zhaoying@zhaoying ~ $ kubectl delete po kubia
pod "kubia" deleted
$ k get replicaset
NAME DESIRED CURRENT READY AGE
kubia-69f875bf56 1 1 0 25s
$ k get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
kubia 0/3 3 0 3m5s
$ k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubia LoadBalancer 192.168.24.186 39.106.128.174 8080:31958/TCP 28s
大家需要记住一些缩写
rs:replicaset
po:pods
deploy: deployment
这样能简化指令
修改期望的副本即可以完成伸缩
$ k scale deploy kubia --replicas=3
deployment.apps/kubia scaled
$ k get po
NAME READY STATUS RESTARTS AGE
kubia-546dd5d8b6-76lx9 1/1 Running 0 5m14s
kubia-546dd5d8b6-tchln 0/1 ContainerCreating 0 30s
kubia-546dd5d8b6-zptbt 0/1 ContainerCreating 0 30s
因为我们的应用可以返回主机名,所以每次请求会获得不同的结果
$ while true; do curl http://39.106.128.174:8080; sleep 1; done
You've hit kubia-qr7r9
You've hit kubia-qr7r9
You've hit kubia-9bklf
负载均衡器到达上限时,请用左边那个ClusterIP
$ kubectl run busybox --rm -i --tty --image busybox -- sh
$ while true; do wget -O- http://<39.106.128.174>:8080; sleep 1; done
查看应用跑在哪个节点
kubectl get pods -o wide
还可以查看pod的一些细节,还有日志,试试指令吧
# kubectl describe pod <选择一个pod>
# kubectl logs <选择一个pod>