This section continues from the previous section - make sure you do the tutorial in sequence.
In-Cluster Load Balancer
A Kubernetes Service acts as an internal L4 load balancer only accessible from within the same Kubernetes Cluster. See the Service section for more information.
Internal Network Load Balancer
The setup of the Internal Network Load Balancer is similar to the External Network Load Balancer, but with an additional annotation.
Service YAML
In k8s/service.yaml, use the cloud.google.com/load-balancer-type annotation to mark the service to use the Internal Network Load Balancer:
k8s/service.yaml
apiVersion:v1kind:Servicemetadata:name:helloworldannotations:# Indicate this is an Internal Network Load Balancercloud.google.com/load-balancer-type:"Internal"labels:app:helloworldspec:ports: - name:8080-8080port:8080protocol:TCPtargetPort:8080selector:app:helloworld# Use LoadBalancer type instead of ClusterIPtype:LoadBalancer
Internal Static IP
You can assign an internal static IP address to the Network Load Balancer.
Update the k8s/service.yaml to pin the Load Balancer IP address:
k8s/service.yaml
apiVersion:v1kind:Servicemetadata:name:helloworldannotations:cloud.google.com/load-balancer-type:"Internal"labels:app:helloworldspec:ports: - name:8080-8080port:8080protocol:TCPtargetPort:8080selector:app:helloworldtype:LoadBalancer# Replace the value with the IP address you reservedloadBalancerIP:RESERVED_IP_ADDRESS
Internal HTTP(s) Load Balancer
The setup of the Internal Network Load Balancer is similar to the External HTTP(s) Load Balancer, but with an additional annotation.
Service YAML
In the k8s/service.yaml, use the cloud.google.com/neg annotation to enable Network Endpoint Group (NEG) in order to use container-native load balancing:
k8s/service.yaml
apiVersion:v1kind:Servicemetadata:name:helloworldlabels:app:helloworld# Add the NEG annotation to enable Network Endpoint Group# in order to use container-native load balancingannotations:cloud.google.com/neg:'{"ingress": true}'spec:ports: - name:8080-8080port:8080protocol:TCPtargetPort:8080selector:app:helloworldtype:ClusterIP
Ingress YAML
Create a Kubernetes Ingress configuration that will create the HTTP Load Balancer. Create a k8s/ingress.yaml, but also use kubernetes.io/ingress.class annotation to indicate this is an Internal HTTP(s) Load Balancer
k8s/ingress.yaml
apiVersion:networking.k8s.io/v1beta1kind:Ingressmetadata:name:helloworldannotations:# Add the Ingress Class annotation to use Internal HTTP(s) Load Balancerkubernetes.io/ingress.class:"gce-internal"spec:rules: - http:paths: - path:/*backend:serviceName:helloworldservicePort:8080