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

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:

主站蜘蛛池模板: 济源市| 略阳县| 扶绥县| 富源县| 巴青县| 大名县| 乐亭县| 珠海市| 潢川县| 横峰县| 宜阳县| 青州市| 丽水市| 扎赉特旗| 嫩江县| 博乐市| 南投市| 威信县| 宣武区| 都兰县| 上林县| 内丘县| 婺源县| 柯坪县| 东海县| 崇左市| 子洲县| 浦江县| 碌曲县| 太仆寺旗| 招远市| 西乌珠穆沁旗| 航空| 沭阳县| 麻栗坡县| 海兴县| 永嘉县| 特克斯县| 宝清县| 营口市| 乌鲁木齐县|