Nginx ingress in kubernetes

There are 3 ways to expose your service: NodePort, LoadBalancer, Ingress, next I will introduce about how to use ingress.

1.Deploy ingress controller

You need deploy ingress controller at first which will start nginx pods, then nginx will bind domains and listen to the requests.

I built a common ingress chart for different service, I only need change values-<service>.yaml and deploy script if any changes.

Another key point is that you must be clear about ingress-class, different service use different ingress-class, it will be quite messy if you mistake them.

args:
  - /nginx-ingress-controller
  - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
  - --configmap=$(POD_NAMESPACE)/nginx-configuration
  - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
  - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
  - --ingress-class={{ .Values.server.namespace }}
  - --sort-backends=true

2.Configure service ingress

Next we need configure service ingress which will append nginx server configuration dynamically.

I also built a service chart which include environment configurations, Jenkins & Helm will use different values-<env>.yaml when execute pipeline deployment.

Ingress example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ .Values.app.name }}{{ .Values.deploy.subfix }}
  namespace: {{ .Values.app.namespace }}
  annotations:
    kubernetes.io/ingress.class: "{{ .Values.ingress.class }}"
    kubernetes.io/tls-acme: "true"
    nginx.ingress.kubernetes.io/enable-cors: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/proxy-body-size: 10m
spec:
  rules:
  - host: {{ .Values.ingress.hostname }}
    http:
      paths:
      - path: {{ .Values.ingress.path }}
        backend:
          serviceName: {{ .Values.app.name }}{{ .Values.deploy.subfix }}
          servicePort: {{ .Values.container.port }}