Skip to content

Lab 11 - Ingress IKS

The IBM Kubernetes service free clusters consist of a single worker node with 2 CPU and 4 GB of memory for experimenting with Kubernetes. Unlike the fee-based service, these clusters do not include capabilities for application load balancing using ingress out-of-the-box.

Prerequisites

  • Free IBM Kubernetes Cluster (IKS) - upgrade your account from Lite plan to create one. In the example commands, we'll assume that this cluster is named mycluster
  • kubectl - match your cluster API version
  • Log in to IBM Cloud and configure kubectl using the ibmcloud ks cluster config --cluster mycluster command

Components

On the IKS cluster, you will install helm charts for a nginx ingress controller from NGINX. This lab already provides the templated yaml files so there is no need to use helm cli.

Set up the ingress controller

Only do this on a free IKS instance These steps assume facts that only apply to free IKS instances:

  • a single worker where the cluster administrator can create pods that bind to host ports
  • no pre-existing ingress controller or application load balancer

Using the following steps with a paid instance can cause issues. See the IBM Cloud containers documentation for information on exposing applications with the ingress/alb services for paid clusters. You have been warned

  1. Install the NGINX ingress controller with helm using a daemonset and no service resource (which will result in a single pod that binds to ports 80 and 443 on the worker node and will skip creation of a ClusterIP, LoadBalancer, or NodePort for the daemonset).

    kubectl apply -f https://cloudnative101.dev/yamls/ingress-controller/iks-ingress-v1.7.1.yaml
    

  2. You can use free domain .nip.io to get a domain name using one of the IP Address of your worker nodes. Run this command to set your DOMAIN

    export DOMAIN=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}').nip.io
    echo $DOMAIN
    

  3. You can test the ingress controller using the $DOMAIN:

    curl -I http://$DOMAIN
    
    HTTP/1.1 404 Not Found
    Server: nginx/1.17.10
    ...
    

    A 404 is expected at this point because unlike the kubernetes nginx ingress, the NGINX version of the ingress controller does not create a default backend deployment.

  4. To use the ingress controller deploy a sample application, expose a service.

    kubectl create deployment web --image=bitnami/nginx
    kubectl expose deployment web --name=web --port 8080
    

  5. Now create an Ingress resource

    cat <<EOF | kubectl apply -f -
    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      name: web
      labels:
        app: web
    spec:
      rules:
        - host: web.$DOMAIN
          http:
            paths:
              - path: /
                backend:
                  serviceName: web
                  servicePort: 8080
    EOF
    echo "Access your web app at http://web.$DOMAIN"
    

  6. List the created ingress

    kubectl get ingress web
    

  7. Access your web application

    curl http://web.$DOMAIN
    
    The output prints the html
    <p><em>Thank you for using nginx.</em></p>
    

  8. Delete all the resources created

    kubectl delete deployment,svc,ingress -l app=web