Module 7: Kubernetes Assignment - 5

Tasks To Be Performed:

  1. Use the previous deployment
  2. Deploy an NGINX deployment of 3 replicas
  3. Create an NGINX service of type ClusterIP
  4. Create an ingress service/ Apache to Apache service/ NGINX to NGINX service

%%Referencing Lecture 8 – Creating An Ingress

Not used

Ingress:

Ingress install from Hands-On-–-Kubernetes-Installation.pdf

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.49.0/deploy/static/provider/baremetal/deploy.yaml

%%

Step 1:

Continuing from Assignment 4

Instances and Their Private IP Addresses

k-master: 10.0.1.82 worker1: 10.0.1.57 worker2: 10.0.1.119

Step 2:

I use the deployment from Assignment 1 Step 2: NGINX Deployment

Step 3:

I’ll use the ClusterIP service we converted from NodePort in Assignment 4 Step 2: Changing Service

Step 4: Installing Ingress Controller

Next, I install the Nginx Ingress Controller which allows us to manage Ingress resources and control external traffic into the cluster. Ingress resources are used to configure rules for routing incoming external requests to specific services or pods within the cluster. To do this, I use the official deployment YAML file provided by the project. GitHub: Bare metal clusters

This command fetches the deployment YAML file from the official GitHub repository and applies it to the cluster.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/deploy/static/provider/baremetal/deploy.yaml


We can confirm that the Nginx Ingress Controller is successfully running within our Kubernetes cluster as a pod

We have an ingress service configured with NodePort types on the following ports:

  • HTTP: 80, mapped to 30426
  • HTTPS: 443, mapped to 31013”
    %% The Public IP that worked was worker2 Need to find

    Seem like this works with the Public IP of the node that runs at least one pod kubectl get pods -o wide #question

The above theory seem incorrect according to ChatGPT

With a NodePort service in Kubernetes, you can access the service using the public IP address of any node in the cluster along with the NodePort, regardless of which node the pod is actually running on.

Enter the public IP address of either worker node followed by the NodePort. For example: http://<Public_IPv4_of_Node>:30080.

%% %%

%%

I create an Ingress rule by crafting an ingress.yaml file with the following content: Followed Kubernetes Doc

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /nginx
        pathType: Prefix
        backend:
          service:
            name: my-nginx-deployment
            port:
              number: 80

After creating the ingress.yaml file, I apply it to my cluster:

kubectl apply -f ingress.yaml

%%

When the ingress wasn’t working ADDRESS was empty
%%

I verify the ingress was created:

Success


I test the ingress path /nginx using both the public IP addresses of worker nodes 1 and 2, along with the NodePort 30426.

I will now create an Apache deployment along with a corresponding ClusterIP service to further test our Ingress.

I have updated ingress.yaml to include an additional path /apache with the following configuration.

      - path: /apache
        pathType: Prefix
        backend:
          service:
            name: my-apache-deployment
            port:
              number: 80

I will now apply it again:

kubectl apply -f ingress.yaml


We can also try with the NodePort for https as per 80:30426 443:31013

Now, I will test both paths with both NodePorts mapped to port 80 for HTTP and port 443 for HTTPS.

Success

Using 80(HTTP) : NodePort 30426

Success

Using 443(HTTPS) : NodePort 31013

Warning

The ingress rule is configured with pathType: Prefix. This means that, for example, both /nginx and /nginx123 will match the rule, but /123nginx will not be a match.

%%

%%