LoadBalancer — expose Service externally via cloud load balancer.
1apiVersion: v12kind: Service3metadata:4 name: myapp-lb5 annotations:6 # AWS NLB7 service.beta.kubernetes.io/aws-load-balancer-type: "nlb"8 service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"9 service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"10 # GCP11 cloud.google.com/neg: '{"ingress": true}'12 # Azure13 service.beta.kubernetes.io/azure-load-balancer-resource-group: "my-rg"14spec:15 type: LoadBalancer16 selector:17 app: myapp18 ports:19 - name: http20 port: 8021 targetPort: 300022 protocol: TCP23 - name: https24 port: 44325 targetPort: 300026 protocol: TCP27 loadBalancerSourceRanges:28 - 10.0.0.0/829 - 192.168.0.0/1630 externalTrafficPolicy: Local31 sessionAffinity: ClientIP32 sessionAffinityConfig:33 clientIP:34 timeoutSeconds: 10800
1# Commands2kubectl get svc myapp-lb3kubectl describe svc myapp-lb45# Check external IP6kubectl get svc myapp-lb -o jsonpath='{.status.loadBalancer.ingress[0].ip}'7kubectl get svc myapp-lb -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'89# Cloud-specific commands10aws elb describe-load-balancers | grep myapp11gcloud compute forwarding-rules list | grep myapp12az network lb list | grep myapp1314# Wait for external IP15kubectl wait --for=condition=LoadBalancer svc/myapp-lb --timeout=300s
External Traffic Policy:
Load Balancer Types: