Ingress

To begin routing traffic through the ingress controller, follow these steps:

  1. 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.

    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
  2. Create an Ingress that 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.

    ingress.yaml

    ---
    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
        name: echo-ingress
        annotations:
            haproxy.org/path-rewrite: "/"
    spec:
        rules:
        - http:
            paths:
            - path: /echo
              backend:
                serviceName: echo-service
                servicePort: 80
  3. 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.


Next up

Metrics