How to Forward Traffic to External Cluster with Kubernetes Service and Ingress

AH
Ahmad Lukman Hakim

Dedicated Author of LUKMANLAB

# kubernetes

Goal

  • I have external endpoint that need to be accessed via kubernetes ingress
  • Utilize nginx ingress as Reverse Proxy
  • Utilize Cert Manager that already has Let's Encrypt SSL Certificate

How-to

  • Create Kubernetes Service
apiVersion: v1
kind: Service
metadata:
  name: gitlab-api
  namespace: tools
spec:
  type: ExternalName
  externalName: 192.168.0.162
  ports:
    - port: 8443
      targetPort: 8443
  • Create Ingress and Pointed to Service
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: gitlab-api
  namespace: tools
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/proxy-ssl-verify: "false"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - gitlab.lukmanlab.com
      secretName: wcard-lukmanlab-com-tls
  rules:
  - host: gitlab.lukmanlab.com
    http:
      paths:
      - backend:
          service:
            name: gitlab-api
            port:
              number: 8443
        path: /
        pathType: ImplementationSpecific

Note

  • In this article, we also learn how bypass or not verify SSL of server origin.
  • And, we also learn how we reverse proxy GitLab Server via Kubernetes Ingress.