minikube addons: NGINX Ingress Controller

4 min read

minikube has many built-in applications and services that may be easily deployed by just enabling them. We can get a list using minikube addons list

This is the list we would get on minikube v1.15.1:

$ minikube addons list
|-----------------------------|----------|--------------|
|         ADDON NAME          | PROFILE  |    STATUS    |
|-----------------------------|----------|--------------|
| ambassador                  | minikube | disabled     |
| csi-hostpath-driver         | minikube | disabled     |
| dashboard                   | minikube | disabled     |
| default-storageclass        | minikube | enabled ✅   |
| efk                         | minikube | disabled     |
| freshpod                    | minikube | disabled     |
| gcp-auth                    | minikube | disabled     |
| gvisor                      | minikube | disabled     |
| helm-tiller                 | minikube | disabled     |
| ingress                     | minikube | enabled ✅   |
| ingress-dns                 | minikube | disabled     |
| istio                       | minikube | disabled     |
| istio-provisioner           | minikube | disabled     |
| kubevirt                    | minikube | disabled     |
| logviewer                   | minikube | disabled     |
| metallb                     | minikube | disabled     |
| metrics-server              | minikube | disabled     |
| nvidia-driver-installer     | minikube | disabled     |
| nvidia-gpu-device-plugin    | minikube | disabled     |
| olm                         | minikube | disabled     |
| pod-security-policy         | minikube | disabled     |
| registry                    | minikube | disabled     |
| registry-aliases            | minikube | disabled     |
| registry-creds              | minikube | disabled     |
| storage-provisioner         | minikube | enabled ✅   |
| storage-provisioner-gluster | minikube | disabled     |
| volumesnapshots             | minikube | disabled     |
|-----------------------------|----------|--------------|

For example, to enable a nginx ingress controller, it is as easy as:

$ minikube addons enable ingress
🔎  Verifying ingress addon...
🌟  The 'ingress' addon is enabled

We will be able to see that it creates a deployment in the kube-system namespace:

$ kubectl get deploy -n kube-system
NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
coredns                    1/1     1            1           23d
ingress-nginx-controller   1/1     1            1           7m47s
metrics-server             1/1     1            1           23d

We can test it by creating an Ingress for an existing service, for example, for jenkins:

$ kubectl get svc -n jenkins
NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
jenkins         ClusterIP   10.104.250.250   <none>        8080/TCP    20d
jenkins-agent   ClusterIP   10.103.0.136     <none>        50000/TCP   20d

The ingress yaml would look like follows:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: jenkins
  namespace: jenkins
spec:
  rules:
  - host: jenkins.minikube
    http:
      paths:
      - backend:
          serviceName: jenkins
          servicePort: 8080

As usual, we just need to apply it using kubectl apply

$ kubectl apply -f ingress_jenkins.yaml 
ingress.extensions/jenkins created

To be able to connect we will have to get minikube IP to connect to. This IP is shown for each ingress we have configured:

$ kubectl get ingress -n jenkins
NAME      CLASS    HOSTS              ADDRESS        PORTS   AGE
jenkins   <none>   jenkins.minikube   192.168.49.2   80      2m30s

Now we can either add this IP to the /etc/hosts file or, just for testing pruposes, use the proxy option with curl:

$ curl -Ix 192.168.49.2:80 jenkins.minikube
HTTP/1.1 403 Forbidden
Date: Wed, 23 Dec 2020 16:05:12 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 793
Connection: keep-alive
X-Content-Type-Options: nosniff
Set-Cookie: JSESSIONID.54dc3858=node01465y36cnwkvv16ydy2lc4w3623345.node0; Path=/; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
X-Hudson: 1.395
X-Jenkins: 2.263.1
X-Jenkins-Session: 6f93b017
X-Hudson-CLI-Port: 50000
X-Jenkins-CLI-Port: 50000
X-Jenkins-CLI2-Port: 50000
X-You-Are-Authenticated-As: anonymous
X-You-Are-In-Group-Disabled: JENKINS-39402: use -Dhudson.security.AccessDeniedException2.REPORT_GROUP_HEADERS=true or use /whoAmI to diagnose
X-Required-Permission: hudson.model.Hudson.Read
X-Permission-Implied-By: hudson.security.Permission.GenericRead
X-Permission-Implied-By: hudson.model.Hudson.Administer

Disable it it's just as easy as enabling it:

$ minikube addons disable ingress
🌑  "The 'ingress' addon is disabled

Posted on 30/12/2020

Categories