使用service访问群集中的应用程序
目的
为在两个 pod 中运行的应用程序创建 service
kubectl run hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080kubectl get deployments hello-world kubectl describe deployments hello-worldkubectl get replicasets kubectl describe replicasetskubectl expose deployment hello-world --type=NodePort --name=example-servicekubectl describe services example-serviceName: example-service Namespace: default Labels: run=load-balancer-example Selector: run=load-balancer-example Type: NodePort IP: 10.32.0.16 Port: <unset> 8080/TCP NodePort: <unset> 31496/TCP Endpoints: 10.200.1.4:8080,10.200.2.5:8080 Session Affinity: None No events.kubectl get pods --selector="run=load-balancer-example" --output=wideNAME READY STATUS ... IP NODE hello-world-2895499144-bsbk5 1/1 Running ... 10.200.1.4 worker1 hello-world-2895499144-m1pwt 1/1 Running ... 10.200.2.5 worker2curl http://<public-node-ip>:<node-port>Hello Kubernetes!
使用 Service 配置文件
Last updated