In part 1 of this article, I have explained three possible ways of routing external traffic to your Kubernetes cluster. There I showed you the benefits of having ClusterIP as the service types for your applications. Now, I’m going to show you how to route traffic to the CuslterIP services using an Nginx proxy.

Let’s deploy below deployment in your Kubernetes cluster using a helm chart. If you are not familiar with helm please refer this blog before reading the rest of this article.

Helm is the package manager for Kubernetes and it allows you to deploy the above deployment using a single “helm install” command.

Before going through the below steps, make sure that you already have ‘kubectl’ access for your k8s cluster from your machine and install helm in it. Then you can execute the below steps,

1. git clone https://github.com/madeesha/helm-charts.git 2. cd helm-charts/ 3. helm init 4. helm install --name my-kube-deployment .

If it is deployed successfully you will be able to see the below output in your terminal.

NAME: my-kube-deployment

LAST DEPLOYED: Fri Jun 28 14:25:12 2019

NAMESPACE: default

STATUS: DEPLOYED

........................

NOTE: if you encounter with the below error when running the helm init command, please use the steps mentioned in the blog to fix it. “Error: release nginx-ingress failed: namespaces “default” is forbidden: User “system:serviceaccount:kube-system:default” cannot get resource “namespaces” in API group “” in the namespace “default””

Now you have successfully created below resources in your k8s cluster using a helm chart,

Here we only expose the Nginx service as the LoadBalancer service type and the Hello-world app is exposed as the ClusterIP service. We are now going to access this ClusterIP service from the Nginx. Likewise, we can expose multiple applications in the cluster using the ClusterIP service type and access them using the same Nginx hostname. You can get a clear idea of the deployment once you go through all the YAML template files in the helm repo https://github.com/madeesha/helm-charts.git. let’s look at the way of accessing the above hello-world application from your web browser.

If you check the services deployed in your cluster using the “kubectl get svc” command, you can see the below output.