Deploying Nginx Helm chart on minikube using terraform

2021, May 04    

How to runn Nginx deployment in Minikube with Terraform in own namespace

Prerequisites :

  • minikube
  • terraform
  • helm 3

What we will complete by the end of this exercise :

  • Install Nginx Helm Chart
  • Set values of Helm chart via Terraform to use NodePort service and specific Port
  • Use default namespace
  • Access Nginx Deployment via minikube ip & NodePort port

Nodeport exposes the service on every node on a fixed port. In our case, will expose it on our minikube ip and fixed , dedicated port

Which makes it easy to access in combination with minikube ip

1) Start minikube :

minikube start

2) Clone this article GIT REPO

Switch into correct folder :

cd helm-provider

Edit main.tf file, and edit appropiately to point to your kubeconfig file location :

provider "kubernetes" {
  config_context_cluster   = "minikube"
  config_path = "~/.kube/config"
}

3) Initialize terraform

terraform init

4) Plan

terraform plan

5) Terraform apply

terraform apply

Enter : Yes

6) Verify helm chart is installed

helm ls

Should show :

  advissor.github.io git:(main)  helm ls
NAME                    	NAMESPACE	REVISION	UPDATED                             	STATUS  	CHART                         	APP VERSION
nginx-ingress-controller	default  	1       	2021-05-04 23:56:51.256473 +0500 +05	deployed	nginx-ingress-controller-7.6.6	0.46.0     

6) Verify Nginx pods are created

kubectl get pods

Expected output :

NAME                                                       READY   STATUS    RESTARTS   AGE
nginx-ingress-controller-64658d6659-drmzd                  1/1     Running   0          114s
nginx-ingress-controller-default-backend-8cc5f7b5d-94658   1/1     Running   0          114s

Expected output :

  applications git:(main) 
NAME                                      READY   STATUS    RESTARTS   AGE
scalable-nginx-example-5fbb9989bf-9mz9w   1/1     Running   0          82s
scalable-nginx-example-5fbb9989bf-mbhvd   1/1     Running   0          82s

7) Access Nginx deployment via NodePort IP

kubectl get svc
NAME            TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes                                 ClusterIP   10.96.0.1        <none>        443/TCP                      55d
nginx-ingress-controller                   NodePort    10.103.151.203   <none>        80:30201/TCP,443:32767/TCP   3m27s
nginx-ingress-controller-default-backend   ClusterIP   10.99.218.58     <none>        80/TCP                       3m27s

Use the port , from the output and “minikube ip”

 minikube ip
192.168.64.2

Taking into account my output :

Port : 30201

Minikube ip : 192.168.64.2

Nginx service will be accessible on :

192.168.64.2:30201

8) You will see “Welcome to nginx!” page