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
Check out the deployment:
kubectl get deployment web-auth -o yamlNote the
web-authlabel on our Pods. We’ll use this label to select these Pods using our Service.Create a
web-auth-svc.ymlfile:vi web-auth-svc.ymlPaste 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: 80Press Esc and enter
:wqto save and exit.Create the Service:
kubectl create -f web-auth-svc.yml
Create an Ingress That Maps to the New Service
Create a
web-auth-ingress.ymlfile:vi web-auth-ingress.ymlAdd 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: 80Press Esc and enter
:wqto save and exit.Create the Ingress:
kubectl create -f web-auth-ingress.ymlCheck the status of the Ingress:
kubectl describe ingress web-auth-ingressNote the service endpoints in the Backends section of the output. You have successfully created an Ingress that maps to the backend Service.