做教育导航的网站,关键词seo公司推荐,杭州app开发制作公司,郴州网络有限公司安装kubectl。使用Google提供商#xff08;如Google Container Engine或Amazon Web Services#xff09;创建Kubernetes群集。本教程创建一个 外部负载均衡器#xff0c;它需要一个云提供商。配置kubectl与Kubernetes API服务器通信。有关说明#xff0c;请参阅云提供商的文…安装kubectl。使用Google提供商如Google Container Engine或Amazon Web Services创建Kubernetes群集。本教程创建一个 外部负载均衡器它需要一个云提供商。配置kubectl与Kubernetes API服务器通信。有关说明请参阅云提供商的文档。
在五个pod中运行的应用程序创建一个Service
1、在群集中运行Hello World应用程序 kubectl run hello-world --replicas5 --labelsrunload-balancer-example --imagegcr.io/google-samples/node-hello:1.0 --port8080
以上命令创建一个 Deployment 对象和一个关联的 ReplicaSet 对象。ReplicaSet 有五个 Pods每个Pods都运行Hello World应用程序。
2、显示有关Deployment的信息 kubectl get deployments hello-worldkubectl describe deployments hello-world
3、显示有关ReplicaSet对象的信息 kubectl get replicasetskubectl describe replicasets
4、使用deployment创建暴露的Service对象 kubectl expose deployment hello-world --typeLoadBalancer --namemy-service
5、显示有关Service的信息 kubectl get services my-service
输出 NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEmy-service 10.3.245.137 104.198.205.71 8080/TCP 54s
注意如果外部IP地址显示为pending请等待一分钟再次输入相同的命令。
6、显示Service有关详细信息 kubectl describe services my-service
输出 Name: my-serviceNamespace: defaultLabels: runload-balancer-exampleSelector: runload-balancer-exampleType: LoadBalancerIP: 10.3.245.137LoadBalancer Ingress: 104.198.205.71Port: unset 8080/TCPNodePort: unset 32377/TCPEndpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 2 more...Session Affinity: NoneEvents:
记录Service公开的外部IP地址。在此例子中外部IP地址为104.198.205.71。还要注意Port的值。在这个例子中端口是8080。
7、在上面的输出中您可以看到该服务有多个端点10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 2 more…。这些是运行Hello World应用程序的pod的内部地址。要验证这些是pod地址请输入以下命令 kubectl get pods --outputwide
输出类似于 NAME ... IP NODEhello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afchello-world-2895499144-2e5uh ... 0.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afchello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7ahello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afchello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc
8、使用外部IP地址访问Hello World应用程序 curl http://external-ip:port
external-ip是你Service的外部IP地址并且port是Port你的Service描述中的值。
对成功请求的响应是一个hello消息 Hello Kubernetes!
删除方法
要删除服务请输入以下命令
kubectl delete services my-service
要删除DeploymentReplicaSet和运行Hello World应用程序的Pods请输入以下命令
kubectl delete deployment hello-world
原文 https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/