Kubernetes Nginx Ingress Controller expose Nginx Webserver

michidk

I basically want to access the Nginx-hello page externally by URL. I've made a (working) A-record for a subdomain to my v-server running kubernetes and Nginx ingress: vps.my-domain.com

I installed Kubernetes via kubeadm on CoreOS as a single-node cluster using these tutorials: https://kubernetes.io/docs/setup/independent/install-kubeadm/, https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/, and nginx-ingress using https://kubernetes.github.io/ingress-nginx/deploy/#bare-metal.

I also added the following entry to the /etc/hosts file:

31.214.xxx.xxx vps.my-domain.com

(xxx was replaced with the last three digits of the server IP)

I used the following file to create the deployment, service, and ingress:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
  selector:
    run: my-nginx
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-nginx
  annotations:
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/ssl-redirect: "False"
spec:
  rules:
  - host: vps.my-domain.com
    http:
      paths:
      - backend:
          serviceName: my-nginx
          servicePort: 80

Output of describe ing:

core@vps ~/k8 $ kubectl describe ing
Name:             my-nginx
Namespace:        default
Address:
Default backend:  default-http-backend:80 (<none>)
Rules:
  Host                  Path  Backends
  ----                  ----  --------
  vps.my-domain.com
                           my-nginx:80 (<none>)
Annotations:
  kubectl.kubernetes.io/last-applied-configuration:      
{"apiVersion":"extensions/v1beta1",...}

  kubernetes.io/ingress.class:         nginx
  ingress.kubernetes.io/ssl-redirect:  False
Events:
  Type    Reason  Age                From                      Message
  ----    ------  ----               ----                      -------
  Normal  UPDATE  49m (x2 over 56m)  nginx-ingress-controller  Ingress default/my-nginx

While I can curl the Nginx hello page using the nodeip and port 80 it doesn't work from outside the VM. Failed to connect to vps.my-domain.com port 80: Connection refused

Did I forgot something or is the configuration just wrong? Any help or tips would be appreciated!

Thank you

EDIT:

Visiting "vps.my-domain.com:30519` gives me the nginx welcome page. But in the config I specified port :80. I got the port from the output of get services:

core@vps ~/k8 $ kubectl get services --all-namespaces | grep "my-nginx"
default         my-nginx               ClusterIP   10.107.5.14      <none>        80/TCP                       1h

I also got it to work on port :80 by adding

externalIPs:
  - 31.214.xxx.xxx

to the my-nginx service. But this is not how it's supposed to work, right? In the tutorials and examples for kubernetes and ingress-nginx, it worked always without externalIPs. Also the ingress rules doesn't work now (e.g. if I set the path to /test).

michidk

So apparently I was missing one part: the load balancer. I'm not sure why this wasn't mentioned in those instructions as a requirement. But i followed this tutorial: https://kubernetes.github.io/ingress-nginx/deploy/baremetal/#a-pure-software-solution-metallb and now everything works.

Since metallb requires multiple ip addresses, you have to list your single ip-adress with the subnet \32: 31.214.xxx.xxx\32

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to expose localhost airflow with nginx-ingress-controller Kubernetes

kubernetes nginx ingress controller rewrites

Kibana with nginx ingress controller in Kubernetes

Kubernetes Nginx Ingress Controller on NodePort

Ingress controller nginx kubernetes not working

Trying to expose plain TCP with nginx-ingress-controller on Kubernetes Bare-Metal

kubernetes nginx ingress controller / caching static assets

413 error with Kubernetes and Nginx ingress controller

How does an Nginx Ingress Controller work on Kubernetes?

kubernetes not creating the ELB for ingress-nginx controller

Nginx Ingress Controller Returns 404 Kubernetes

Nginx ingress controller without load balancer in Kubernetes

Kubernetes nginx ingress controller with multiple ingress resource objects

Kubernetes nginx-ingress ingress controller CORS handled by application

Kubernetes with 2 ingress (nginx)

Nginx ingress controller modsecurity

Kubernetes internal nginx ingress controller with SSL termination & ssl-passthrough

Nginx Ingress Controller can't find nodes on Google Kubernetes Engine

Kubernetes NGINX Ingress Controller not picking up TLS Certificates

How to use ConfigMap configuration with Helm NginX Ingress controller - Kubernetes

kubernetes ingress controller with cluster ip service and default nginx not working as expected

NGINX controller Kubernetes: need to change Host header within ingress

How can i create mutiple nginx ingress controller in kubernetes

Hosting webapp with relative URLs behind Kubernetes NGINX ingress controller

Want (internal) name for service while running nginx ingress controller kubernetes

Kubernetes nginx ingress controller as loadbalancer gets random ports

Unable to access Kubernetes ClusterIP services via nginx-ingress-controller

Per-path rewrite in an Kubernetes NGINX reverse proxy ingress controller

Kubernetes NGINX Ingress Controller 404 Not found / Object not found