官术网_书友最值得收藏!

Exposing the frontend service

In order to make it publicly available, we have to edit the service yaml file. Run the following command to download the file:

curl -O -L https://k8s.io/examples/application/guestbook/frontend-service.yaml

 Use the online editor to edit it:

code frontend-service.yaml

Comment out the NodePort line and uncomment the type:LoadBalancer line:

apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# comment or delete the following line if you want to use a LoadBalancer
# type: NodePort # line commented out
# if your cluster supports it, uncomment the following to automatically create
# an external load-balanced IP for the frontend service.
type: LoadBalancer # line uncommented
ports:
- port: 80
selector:
app: guestbook
tier: frontend

Next, run the following command:

kubectl create -f frontend-service.yaml

This step takes some time the first time you run it. In the background, Azure has to perform lots of magic, to make it seamless. It has to create an Azure Load Balancer (ALB), and set the port-forwarding rules to forward traffic on port 80 to internal ports of the cluster.

Run the following until there is a value in the EXTERNAL-IP column:

ab443838-9b3e-4811-b287-74e417a9@Azure:~$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend LoadBalancer 10.0.89.120 52.183.18.103 80:31761/TCP 42m

In the Azure portal, if you click on All Resources and filter on Load Balancer, you will see a Kubernetes Azure Load Balancer. Clicking on it shows you something similar to the following screenshot. The highlighted sections shows the connection between the public IP (that is, External-IP):80 to the internal NodePort of 31761 across all the nodes in the cluster:

主站蜘蛛池模板: 拉萨市| 新龙县| 西乌珠穆沁旗| 清新县| 关岭| 神池县| 和静县| 尉犁县| 兴海县| 本溪市| 瑞金市| 胶州市| 方正县| 石林| 西乡县| 沁阳市| 纳雍县| 沅陵县| 广东省| 清苑县| 松江区| 青川县| 青海省| 葫芦岛市| 秦皇岛市| 资溪县| 湾仔区| 本溪| 吴堡县| 龙泉市| 岑巩县| 海门市| 和平县| 太仓市| 琼结县| 彝良县| 仁化县| 沂源县| 陇西县| 烟台市| 衡水市|