Kubernetes - Ingress with Minikube

11/11/2018

I am learning kubernetes by playing with minikube.

This is my pod deployment file which is fine.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      component: web
  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
        - name: myapp
          image: myid/myimage

I am exposing the above pods using NodePort. I am able to access using minikube IP at port 30002.

apiVersion: v1
kind: Service
metadata:
  name: my-ip-service
spec:
  type: NodePort
  externalIPs:
  - 192.168.99.100
  selector:
    component: web
  ports:
    - port: 3000
      nodePort: 30002
      targetPort: 8080

Now i would like to use ingress to access the application at port 80 which will forward the request the ip-service at port 3000. It does NOT work

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
spec:
  backend:
    serviceName: my-ip-service
    servicePort: 3000

If i try to access to ingress, address is blank.

NAME           HOSTS   ADDRESS   PORTS   AGE
test-ingress   *                 80      41m

How to use ingress with minikube? Or how to bind the minikube ip with ingress service - so that the app can be exposed outside without using nodeport

-- KitKarson
kubernetes
kubernetes-ingress
minikube

2 Answers

11/12/2018

I think you are missing the ingress controller resource on minikube itself. There are many possible ways to create an ingress-controller resource on K8s , but i think for you the best way to start on minikube is to follow this documentation.

Don't forget to read about Ingress in general once you get this working.

-- fatcook
Source: StackOverflow

11/11/2018

You can get your minikube node's IP address with:

minikube ip

The ingress' IP address will not populate in minikube because minikube lacks a load balancer. If you'd like something that behaves like a load balancer for your minikube cluster, https://github.com/knative/serving/blob/master/docs/creating-a-kubernetes-cluster.md#loadbalancer-support-in-minikube suggests running the following commands to patch your cluster:

sudo ip route add $(cat ~/.minikube/profiles/minikube/config.json | jq -r ".KubernetesConfig.ServiceCIDR") via $(minikube ip)
kubectl run minikube-lb-patch --replicas=1 --image=elsonrodriguez/minikube-lb-patch:0.1 --namespace=kube-system
-- Seth Difley
Source: StackOverflow