Kubernetes Ingress running behind nginx reverse proxy

0 votes

I have installed minikube on a server which I can access from the internet.

I have created a kubernetes service which is available:

>kubectl get service myservice
NAME        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
myservice   10.0.0.246   <nodes>       80:31988/TCP   14h

The IP address of minikube is:

>minikube ip
192.168.42.135

I would like the URL http://myservice.myhost.com (i.e. port 80) to map to the service in minikube.

I have nginx running on the host. I can set up a virtual host, mapping the URL to 192.168.42.135:31988 (the node port) and it works fine.

I would like to use an ingress. I've added and enabled ingress. But I am unsure of:

a) what the yaml file should contain

b) how incoming traffic on port 80, from the browser, gets redirected to the ingress and minikube.

c) do I still need to use nginx as a reverse proxy?

d) if so, what address is the ingress-nginx running on (so that I can map traffic to it)?

Sep 10, 2018 in Kubernetes by lina
• 8,220 points
8,527 views

2 answers to this question.

0 votes

First you need nginx ingress controller

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-service-ingress
annotations:
  # by default the controller redirects (301) HTTP to HTTPS,
  # the following would make it disabled.
  # ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: myservice
          servicePort: 80
Use https://{host-ip}/ to visit myservice, The host should be the one where nginx controller is running at.
We need do some port-forwards like host:80 => minikube:80, Running a reverse proxy (like nginx) in the host is an elegant way.
answered Sep 10, 2018 by Kalgi
• 52,350 points
0 votes

You need an ingress as mentioned by @kalgi.

You can enable it using the following command:

minikube addons enable ingress

After enabling ingress on minikube, creat an ingress file (myservice-ingress.yaml):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myservice-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: myservice.myhost.com
      http:
        paths:
        - path: /
          backend:
            serviceName: myservice
            servicePort: 80

Using this file, creat the ingress:

kubectl create -f myservice-ingress.yaml

Finally, add a virtual host to nginx (running outside of minikube) to proxy traffic from outside into minikube:

server {
  listen 80;
  server_name myservice.myhost.com;
  location / {
    proxy_set_header Host            $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://192.168.42.135;
  }
}

The Host header must be passed through because the ingress uses it to match the service. If it is not passed through, minikube cannot match the request to the service.

answered Sep 10, 2018 by Hannah
• 18,520 points

Related Questions In Kubernetes

0 votes
1 answer
+1 vote
1 answer

kubernetes ingress controller and resource using nginx

Ingress is just collection of rules that forwards ...READ MORE

answered Sep 12, 2018 in Kubernetes by Kalgi
• 52,350 points
1,769 views
0 votes
1 answer

Disable SSL redirect for Kubernetes NGINX ingress

Adding ingress.kubernetes.io/ssl-redirect: "false" to annotations will disable the SSL redirect: apiVersion: extensions/v1beta1 kind: ...READ MORE

answered Sep 12, 2018 in Kubernetes by Kalgi
• 52,350 points
7,661 views
0 votes
1 answer

Unable to deploy nginx ingress on kubernetes

The nginix ingress controller uses hostPort to ...READ MORE

answered Oct 1, 2018 in Kubernetes by Kalgi
• 52,350 points
830 views
+1 vote
1 answer
0 votes
3 answers

Nginx reverse proxy URL getting rewritten

Hey @Gopi, try your ingress probably like ...READ MORE

answered Feb 12, 2019 in Kubernetes by Kalgi
• 52,350 points
4,711 views
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,455 views
0 votes
1 answer

Ingress nginx loading resource 404 in kubernetes

This is not a routing problem on ...READ MORE

answered Sep 10, 2018 in Kubernetes by Kalgi
• 52,350 points
8,140 views
0 votes
1 answer

Kubernetes nginx-ingress TLS issue

You have to create a secret named test-secret. ➜ ...READ MORE

answered Sep 11, 2018 in Kubernetes by Kalgi
• 52,350 points
1,969 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP