How to expose a web application via ingress in Kubernetes?

Viewed 935
1 Answers

You need to create an Ingress resource and Service tied to that Ingress. For example for nginx ingress controller:

cat <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: foo-boo
  namespace: default
spec:
  rules:
  - host: foo.domain
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /mypath
EOF | kubectl apply -f -

Then you can will able to see the ingress:

$ kubectl get ingress foo-boo
NAME      HOSTS         ADDRESS                PORTS   AGE
foo-boo   foo.domain    someloadbalancer.com   80      6d11h

Then you can test it with something like curl:

$ curl -H 'Host: foo.domain' http://someloadbalancer.com/mypath

More about a Kubernetes Ingress here.

Related