Exercise 3.5: Access From Outside The Cluster
Exercise 3.5: Access From Outside The Cluster
Exercise 3.5: Access From Outside The Cluster
LABS 1
You can access a Service from outside the cluster using a DNS add-on or environment variables. We will use environ-
ment variables to gain access to a Pod.
2. Choose one of the pods and use the exec command to run printenv inside the pod. The following example uses the
first pod listed above.
student@lfs458-node-1a0a:~$ kubectl exec nginx-1423793266-13p69 \
-- printenv |grep KUBERNETES
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
<output_omitted>
5. Create the service again, but this time pass the LoadBalancer type. Check to see the status and note the external ports
mentioned. The output will show the External-IP as pending. Unless a provider responds with a load balancer it will
continue to show as pending.
student@lfs458-node-1a0a:~$ kubectl expose deployment nginx --type=LoadBalancer
service/nginx exposed
6. Open a browser on your local system, not the lab exercise node, and use the public IP of your node and port 32753,
shown in the output above. If running the labs on remote nodes like AWS or GCE use the public IP you used with PuTTY
or SSH to gain access.
7. Scale the deployment to zero replicas. Then test the web page again. Once all pods have finished terminating accessing
the web page should fail.
student@lfs458-node-1a0a:~$ kubectl scale deployment nginx --replicas=0
deployment.apps/nginx scaled
8. Scale the deployment up to two replicas. The web page should work again.
student@lfs458-node-1a0a:~$ kubectl scale deployment nginx --replicas=2
deployment.apps/nginx scaled
9. Delete the deployment to recover system resources. Note that deleting a deployment does not delete the endpoints or
services.
student@lfs458-node-1a0a:~$ kubectl delete deployments nginx
deployment.apps "nginx" deleted