1
votes

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

2
Please check if this question is related to your question: stackoverflow.com/questions/51243717/…Seth Difley
Thanks Mr.Seth, I saw that answer already. it did not work. I did add an entry in the /etc/hosts -KitKarson
@SethDifley , Thanks Seth, as you had mentioned, k8s seems to work only with some kind of external load balancers if we need to use ingress. blog.getambassador.io/…. I am not sure why you deleted your answerKitKarson

2 Answers

4
votes

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
4
votes

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.