AKS (4) 使用AKS公網負載均衡器 Windows Azure Platform 系列文章目錄
阿新 • • 發佈:2022-03-09
《Windows Azure Platform 系列文章目錄》
我們在建立AKS的時候,預設會建立1個具有公網的負載均衡器,這個負載均衡器的作用是:
1.提供Virtual Network內部的AKS Node,具有往Internet訪問的流量。通過Node的私有IP地址,通過Outbound Rule,轉化為公網IP訪問。
2.通過把K8S Service暴露為Load Balancer,外部的使用者可以訪問到部署在AKS上的服務
請注意,Azure AKS預設建立的公網IP地址,不能被使用者重複使用。
如果使用者需要使用公網IP地址,只能在負載均衡器上新建新的公網IP地址。
1.我們新建一個AKS叢集,預設會建立1個負載均衡器
2.我們在這個負載均衡器上,新建一個公網IP地址,如下圖:
下面這個lbfront就是我手動增加的ip地址 建立完畢後 會顯示這個公網ip是52.130.254.118
3.我們準備2個yaml file,分別如下:
publiclb-nginx80,設定負載均衡器埠為80。必須在下面指定loadBalancerIP的公網IP地址
apiVersion: v1 kind: Service metadata: name: nginx80 spec: type: LoadBalancer loadBalancerIP: 52.130.254.118 ports: - port: 80 protocol: TCP targetPort: 80 selector: run: testapp01 --- apiVersion: apps/v1 kind: Deployment metadata: labels: run: testapp01 name: testapp01 spec: replicas: 1 selector: matchLabels: run: testapp01 template: metadata: labels: run: testapp01 spec: containers: - image: nginx name: nginx
publiclb-nginx81,設定負載均衡器埠為81。必須在下面指定loadBalancerIP的公網IP地址
apiVersion: v1 kind: Service metadata: name: nginx81 spec: type: LoadBalancer loadBalancerIP: 52.130.254.118 ports: - port: 81 protocol: TCP targetPort: 80 selector: run: testapp01 --- apiVersion: apps/v1 kind: Deployment metadata: labels: run: testapp01 name: testapp01 spec: replicas: 1 selector: matchLabels: run: testapp01 template: metadata: labels: run: testapp01 spec: containers: - image: nginx name: nginx
4.我們通過kubectl apply,分別執行這2個yaml file。步驟略。
可以看到nginx 80和nginx81這2個服務都起來了
5.我們分別訪問這2個服務地址:http://52.130.254.118/ 和 http://52.130.254.118:81。
可以訪問到這2個Nginx的服務。如下圖: