To begin routing traffic through the ingress controller, follow these steps:
Deploy a sample application to your cluster. The following Deployment and Service definitions install a web server that echoes back information about each request. Deploy it with
kubectl apply -f sample.yaml.
apiVersion: apps/v1 kind: Deployment metadata: labels: run: echo name: echo spec: replicas: 1 selector: matchLabels: run: echo template: metadata: labels: run: echo spec: containers: - name: echo image: jmalloc/echo-server ports: - containerPort: 8080 readinessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 5 periodSeconds: 5 successThreshold: 1 --- apiVersion: v1 kind: Service metadata: name: echo-service spec: selector: run: echo ports: - name: http protocol: TCP port: 80 targetPort: 80
Ingressthat defines how the ingress controller should route traffic to the echo service. In this example, requests to /echo are rewritten to / en route to the pod. Deploy it with
kubectl apply -f ingress.yaml.
--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: echo-ingress annotations: haproxy.org/path-rewrite: "/" spec: rules: - http: paths: - path: /echo pathType: Prefix backend: service: name: echo-service port: number: 80
Make requests to the echo service through the ingress controller’s IP address and port, e.g. http://192.168.99.100:32063/echo. Define more Deployment, Service and Ingress objects and the ingress controller will detect them too.
Learn more about Ingress objects from the official Kubernetes documentation.