Enhanced Project: Deploying a Web Application with Kubernetes Ingress

Nidhi Ashtikar
3 min readApr 28, 2024

--

SSL Termination and Load Balancing

Prerequisites:

  • Kubernetes Cluster: Ensure you have a Kubernetes cluster set up and running. You can use Minikube for local development or a managed Kubernetes service like GKE, AKS, or EKS for production.
  • kubectl CLI: Install and configure kubectl to manage your Kubernetes cluster.
  • Domain Name: Obtain a domain name that you want to use to access your web application. You can purchase one from domain registrars like Namecheap, GoDaddy, etc.
  • TLS Certificate/Key Pair: Obtain an SSL/TLS certificate and private key for your domain name. You can obtain one from a trusted certificate authority (CA) like Let’s Encrypt or use a self-signed certificate for testing purposes.

Steps:

1. Deploy a Sample Application:

For this project, we’ll deploy a simple NGINX web server as our sample application.

apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app
spec:
replicas: 1
selector:
matchLabels:
app: sample-app
template:
metadata:
labels:
app: sample-app
spec:
containers:
- name: sample-app
image: nginx:latest
ports:
- containerPort: 80

2. Expose the Deployment with a Service:

Create a Kubernetes Service to expose the deployed NGINX application internally within the cluster.

apiVersion: v1
kind: Service
metadata:
name: sample-app-service
spec:
selector:
app: sample-app
ports:
- protocol: TCP
port: 80
targetPort: 80

3. Create a Secret for TLS Certificate:

If you have an SSL/TLS certificate and private key, create a Kubernetes Secret to store them. This step is necessary for SSL termination.

kubectl create secret tls tls-secret --cert=path/to/certificate.crt --key=path/to/private.key

4. Update Ingress with SSL Termination:

Modify the Ingress manifest to include SSL termination and load balancing.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: sample-app-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
tls:
- hosts:
- yourdomain.com
secretName: tls-secret
rules:
- host: yourdomain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: sample-app-service
port:
number: 80

5. Apply the Updated Ingress:

Apply the updated Ingress configuration to enable SSL termination and load balancing.

kubectl apply -f sample-app-ingress.yaml

6. Update DNS:

Ensure your domain’s DNS records point to your Kubernetes cluster’s IP address. You may need to add an A record pointing to the external IP address of your Kubernetes cluster.

7. Access the Application:

Once DNS propagation is complete, access your web application using https://yourdomain.com. You should now have SSL-encrypted access to your NGINX web server, with SSL termination and load balancing handled by Kubernetes Ingress.

Conclusion:

By following these steps, you’ve successfully deployed a web application with Kubernetes Ingress, including SSL termination and load balancing. This setup provides a secure and scalable solution for hosting your web applications on Kubernetes. Adjust configurations as needed based on your specific requirements and environment.

If there’s a specific topic you’re curious about, feel free to drop a personal note or comment. I’m here to help you explore whatever interests you!

Git Hub : github.com/nidhi-ashtikar

Thanks for spending your valuable time learning to enhance your knowledge!

--

--

Nidhi Ashtikar
Nidhi Ashtikar

Written by Nidhi Ashtikar

Experienced AWS DevOps professional with a passion for writing insightful articles.

No responses yet