Journey towards to securely deploy websites on Kubernetes (Part:2)
Soumyadip Chatterjee
??? DevOps Engineer |Istio ?? | Terraform ???, |Docker ?? | K8's??| Snowflake ?? | Argo CD?? | Helm ?? | GitLab ?? | Ansible ?? | Certifications:- 2x AWS ??, 1x Azure???, 1x OCI??, 1x Commvault
In this blog we will walk through the end to end steps to understand how a real world ecommerce application issue certificate and also expose application via Ingress controller on the most popular cloud provider such as AWS using Cert Manager , Let's Encrypt & AWS ALB Ingress controller .
Step 1: Setting Up Your Kubernetes Cluster on AWS
First things first, you need a Kubernetes cluster running on AWS. If you haven’t set up one already, Amazon EKS is a popular choice due to its seamless integration with other AWS services.
Step 2: Installing AWS Load Balancer Controller
The AWS Load Balancer Controller is essential for managing your ALB in Kubernetes. It automatically provisions an ALB when an Ingress resource is created.
helm repo add eks https://aws.github.io/eks-charts helm repo update
2. Install the AWS Load Balancer Controller:
kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=main"
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
--set clusterName=<your-cluster-name> \
--set serviceAccount.create=false \
--set region=<your-region> \
--set vpcId=<your-vpc-id> \
--set serviceAccount.name=aws-load-balancer-controller \
-n kube-system
Step3. Installing Cert Manager :- Cert Manager simplifies the process of obtaining and managing TLS certificates in your Kubernetes cluster.
helm repo add jetstack https://charts.jetstack.io helm repo update
kubectl create namespace cert-manager
helm install cert-manager jetstack/cert-manager \
--namespace cert-manager \
--version v1.12.0 \
--set installCRDs=true
领英推荐
Cert Manager uses an Issuer to request certificates. Let’s Encrypt provides free SSL/TLS certificates, and you can set up both staging and production issuers.
Create ClusterIssuer resources:
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-production
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: [email protected]
privateKeySecretRef:
name: letsencrypt-production
solvers:
- http01:
ingress:
class: alb
Please note that you can first test or undergo a POC in staging environment as well , then after you leverage the same in production . Below is the sample code .
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: mycoolwebsite-cert
spec:
secretName: mycoolwebsite-tls
issuerRef:
name: letsencrypt-staging
kind: ClusterIssuer
commonName: mycoolwebsite.com
dnsNames:
- mycoolwebsite.com
5 . Deploying Your eCommerce Application
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecommerce-app
labels:
app: ecommerce
spec:
replicas: 3
selector:
matchLabels:
app: ecommerce
template:
metadata:
labels:
app: ecommerce
spec:
containers:
- name: ecommerce-container
image: your-docker-image:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: ecommerce-service
spec:
selector:
app: ecommerce
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort
It's recommended to create a separate service manifests for this deployment .
6 . Create an Ingress Resource to expose the application
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ecommerce-ingress
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
cert-manager.io/cluster-issuer: letsencrypt-production # Use 'letsencrypt-staging' for testing
kubernetes.io/ingress.class: alb
spec:
rules:
- host: your-ecommerce-domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ecommerce-service
port:
number: 80
tls:
- hosts:
- your-ecommerce-domain.com
secretName: ecommerce-tls
Step 7: Accessing Your Application Securely
Once your Ingress resource is applied, the AWS ALB automatically routes traffic to your application. Cert Manager handles the issuance of a certificate from Let’s Encrypt, and the certificate is stored as a Kubernetes secret.
The advantage of Cert Manager with Let's Encrypt via ACME protocol is just not restricted with certificate issuance , renewal etc but it also integrates seamlessly with cloud providers to establish Ingress & expose application securely , make robust and ensure organization Audit & Compliance norms .