Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 4.42 KB

external-access.adoc

File metadata and controls

70 lines (54 loc) · 4.42 KB

Accessing the frontend

Duration: 5:00

When we deployed the frontend, we needed to specify that the service needs to be externally accessible. In Kubernetes, you can instruct the underlying infrastructure to create an external load balancer, by specifying the Service Type as a LoadBalancer.

You can see it in the frontend-service.yaml:

../kubernetes/frontend-service.yaml

Kubernetes ServiceTypes allow you to specify what kind of service you want. The default and base type is ClusterIP, which exposes a service to connection from inside the cluster. NodePort and LoadBalancer are two types that expose services to external traffic.

Valid values for the ServiceType field are:

  • ClusterIP: use a cluster-internal IP only - this is the default and is discussed above. Choosing this value means that you want this service to be reachable only from inside of the cluster.

  • NodePort: on top of having a cluster-internal IP, expose the service on a port on each node of the cluster (the same port on each node). You’ll be able to contact the service on any <NodeIP>:NodePort address.

  • LoadBalancer: on top of having a cluster-internal IP and exposing service on a NodePort also, ask the cloud provider for a load balancer which forwards to the Service exposed as a <NodeIP>:NodePort for each Node.

Note that we have specified LoadBalancer, but it only works on cloud providers which support external load balancers. For example, in Google Cloud Platform (GCE), a load balancer will be created asynchronously and a new external ip will be assigned. The external ip address would be available under the field LoadBalancer Ingress. Example:

$ kubectl describe service frontend-ui
Name:                       frontend-ui
Namespace:                  sample-project
Labels:                     app=frontend-ui,lab=kubernetes-lab
Selector:                   app=frontend-ui
Type:                       LoadBalancer
IP:                         172.30.204.85
LoadBalancer Ingress:       X.X.X.X
Port:                       <unset> 80/TCP
NodePort:                   <unset> 3????/TCP
Endpoints:                  172.17.0.2:8080,172.17.0.4:8080
Session Affinity:           None
Events:
  FirstSeen LastSeen  Count  From                   Type       Reason                  Message
  --------- --------  -----  ----                   --------   ------                  -------
  9m         9m        1     {service-controller }   Normal    CreatingLoadBalancer    Creating load balancer
  8m         8m        1     {service-controller }   Normal    CreatedLoadBalancer     Created load balancer
Important
Since CDK doesn’t support the creation of external LoadBalancers, you can access the service through the NodePort. Kubernetes allocates a port (default: 30000-32767), and each Node in the cluster will proxy that port (the same port number on every Node) into the frontend PODs. Later, in this lab, you will learn an alternative to NodePorts and LoadBalancer.

First, execute kubectl describe services frontend-ui and find out which port (between: 30000-32767) Kubernetes assigned in the CDK node. Once that you have the NodePort, you can access the guestbook via the IP address and port number by navigating the browser to http://10.1.2.2:<NODEPORT>/.

Note
The NodePort (31079) is a random value. You should use the value described in NodePort via kubectl describe service frontend-service. The IP of CDK is always 10.1.2.2

You should see something like this:

App Screenshot