Nginx Ingress Failing to Serve

6/29/2019

I am new to k8s I have a deployment file that goes below

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      component: web
  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
        - name: jenkins
          image: jenkins
          ports:
            - containerPort: 8080
            - containerPort: 50000

My Service File is as following:

apiVersion: v1
kind: Service
metadata:
   name: jenkins-svc
spec:
   type: ClusterIP
   ports:
   - port: 80
     targetPort: 8080
     name: http
   selector:
      component: web

My Ingress File is

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

I am using the nginx ingress project and my cluster is created using kubeadm with 3 nodes nginx ingress

I first ran the mandatory command

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

when I tried hitting jenkins.xyz.com it didn't work when I tried the command

  kubectl get ing

the ing resource doesnt get an IP address assigned to it

-- pawarchinmay27
kubeadm
kubectl
kubernetes
kubernetes-ingress
nginx-ingress

2 Answers

7/1/2019

In order to access you local Kubernetes Cluster PODs a NodePort needs to be created. The NodePort will publish your service in every node using using its public IP and a port. Then you can access the service using any of the cluster IPs and the assigned port.

Defining a NodePort in Kubernetes:

Kubernetes NodePort and proxy

apiVersion: v1
kind: Service
metadata:
  name: nginx-service-np
  labels:
    name: nginx-service-np
spec:
  type: NodePort
  ports:
    - port: 8082        # Cluster IP, i.e. http://10.103.75.9:8082
      targetPort: 8080  # Application port
      nodePort: 30000   # (EXTERNAL-IP VirtualBox IPs) i.e. http://192.168.50.11:30000/ http://192.168.50.12:30000/ http://192.168.50.13:30000/
      protocol: TCP
      name: http
  selector:
    app: nginx 

See a full example with source code at Building a Kubernetes Cluster with Vagrant and Ansible (without Minikube).

The nginx ingress controller can be replaced also with Istio if you want to benefit from a service mesh architecture for:

  • Load Balance traffic, external o internal
  • Control failures, retries, routing
  • Apply limits and monitor network traffic between services
  • Secure communication

See Installing Istio in Kubernetes under VirtualBox (without Minikube).

-- Javier Ruiz
Source: StackOverflow

6/30/2019

The ingress resource is nothing but the configuration of a reverse proxy (the Ingress controller).

It is normal that the Ingress doesn't get an IP address assigned.

What you need to do is connect to your ingress controller instance(s).

In order to do so, you need to understand how they're exposed in your cluster.

Considering the YAML you claim you used to get the ingress controller running, there is no sign of exposition to the outside network.

You need at least to define a Service to expose your controller (might be a load balancer if the provider where you put your cluster supports it), you can use HostNetwork: true or a NodePort.

To use the latest option (NodePort) you could apply this YAML:

https://github.com/kubernetes/ingress-nginx/blob/master/deploy/static/provider/baremetal/service-nodeport.yaml

I suggest you read the Ingress documentation page to get a clearer idea about how all this stuff works.

https://kubernetes.io/docs/concepts/services-networking/ingress/

-- whites11
Source: StackOverflow