Using Kubernetes Ingress

Introduction

Kubernetes Ingress allows you to customize how external entities can interact with your Kubernetes applications via the network. This lab will allow you to exercise your knowledge of Kubernetes Ingress. You will use Ingress to open access from an existing service to an external server.

Solution

Log in to the server using the credentials provided:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

Create a Service to Expose the web-auth Deployment

  1. Check out the deployment:

    kubectl get deployment web-auth -o yaml
    

    Note the web-auth label on our Pods. We’ll use this label to select these Pods using our Service.

  2. Create a web-auth-svc.yml file:

    vi web-auth-svc.yml
    
  3. Paste the following YAML definitions:

    Note: To paste YAML directly into the Vi/Vim editor, first enter the command :set paste.

    apiVersion: v1
    kind: Service
    metadata:
      name: web-auth-svc
    spec:
      type: ClusterIP
      selector:
        app: web-auth
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 80
    
  4. Press Esc and enter :wq to save and exit.

  5. Create the Service:

    kubectl create -f web-auth-svc.yml
    

Create an Ingress That Maps to the New Service

  1. Create a web-auth-ingress.yml file:

    vi web-auth-ingress.yml
    
  2. Add the following YAML definitions:

    Note: To paste YAML directly into the Vi/Vim editor, first enter the command :set paste.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: web-auth-ingress
    spec:
      rules:
      - http:
          paths:
          - path: /auth
            pathType: Prefix
            backend:
              service:
                name: web-auth-svc
                port:
                  number: 80
    
  3. Press Esc and enter :wq to save and exit.

  4. Create the Ingress:

    kubectl create -f web-auth-ingress.yml
    
  5. Check the status of the Ingress:

    kubectl describe ingress web-auth-ingress
    

    Note the service endpoints in the Backends section of the output. You have successfully created an Ingress that maps to the backend Service.