首先,我们创建一个多实例的deployment,并为这个deployment创建service。
---创建deployment: nginx
[root@k8s-master ~]# kubectl create deployment nginx --image=nginx:1.20.1 --replicas=3
deployment.apps/nginx created
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-9dfb46bc4-4rf64 1/1 Running 0 3m38s 10.244.58.231 k8s-node02 <none> <none>
nginx-9dfb46bc4-7ltlw 1/1 Running 0 3m38s 10.244.58.236 k8s-node02 <none> <none>
nginx-9dfb46bc4-phft8 1/1 Running 0 3m38s 10.244.58.241 k8s-node02 <none> <none> 37s
---创建service: load-balancer
[root@k8s-master ~]# kubectl expose deployment nginx --port=80 --target-port=80 --type=NodePort --name=load-balancer
service/load-balancer ex