NGINX Ingress configuration for DigitalOcean’s k8s cluster.

NGINX Ingress Controller

Step 1: Install nginx-ingress

helm install nginx-ingress stable/nginx-ingress --set service.type=LoadBalancer --namespace <YOUR_NAMESPACE>

Step 2: Ingress configuration

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: codekn-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: codekn.com
    http:
      paths:
      - path: /
        backend:
          serviceName: codekn-service
          servicePort: 8081
      - path: /api
        backend:
          serviceName: codekn-service
          servicePort: 8082
  - host: dev.codekn.com
    http:
      paths:
        - path: /
          backend:
            serviceName: codekn-service
            servicePort: 8082
        - path: /api
          backend:
            serviceName: codekn-service
            servicePort: 8082

Step 3: Service configuration

apiVersion: v1  
kind: Service
metadata:
  name: codekn-service
  labels:
    app: codekn
spec:
  selector:
    app: codekn
  ports:
  - name: website
    port: 8081
    targetPort: 8081
  - name: api
    port: 8082
    targetPort: 8082

References