This README provides step-by-step instructions to deploy your two-tier web application (MySQL + web) on a local Kind Kubernetes cluster running on an Amazon Linux EC2 instance. It also covers building and pushing Docker images to ECR, creating namespaces, ConfigMap, pull-secrets, applying manifests, and testing.
- AWS CLI configured with appropriate credentials
- kubectl, kind, docker, git installed on your EC2 instance
- IAM Role on EC2 with ECR permissions:
ecr:GetAuthorizationToken,ecr:BatchGetImage,ecr:GetDownloadUrlForLayer - Security Group: allow ports
22(SSH) and80(HTTP)
# Update and install Docker & Git
sudo yum update -y
sudo yum install -y docker git
# Add ec2-user to docker group
sudo usermod -aG docker ec2-user
# Start Docker
echo "Starting Docker..."
sudo systemctl enable --now docker
# Install kubectl
curl -Lo kubectl https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Install Kind
curl -Lo kind "https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64"
chmod +x kind && sudo mv kind /usr/local/bin/kind create cluster --name clo835 --config kind-config.yamlEnsure your
kind-config.yamlhas:kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane extraPortMappings: - containerPort: 30000 hostPort: 80 protocol: TCP
kubectl apply -f k8s/namespaces/ns.yamlThis creates two namespaces:
mysqlweb
kubectl apply -f k8s/configmap/app-config.yamlThe ConfigMap stores available UI colors and the current selection:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: web
data:
availableColors: "blue,green,red"
currentColor: "green"Authenticate to ECR and create a Kubernetes secret in both namespaces so Pods can pull private images.
# For mysql namespace
kubectl create secret docker-registry ecr-pull-secret \
--docker-server=164340264957.dkr.ecr.us-east-1.amazonaws.com \
--docker-username=AWS \
--docker-password="$(aws ecr get-login-password --region us-east-1)" \
--docker-email=you@example.com \
-n mysql
# For web namespace
kubectl create secret docker-registry ecr-pull-secret \
--docker-server=164340264957.dkr.ecr.us-east-1.amazonaws.com \
--docker-username=AWS \
--docker-password="$(aws ecr get-login-password --region us-east-1)" \
--docker-email=you@example.com \
-n webNote: Pods and ReplicaSets are optional if using Deployments only.
# (Optional) Pods
kubectl apply -f k8s/pods/
# (Optional) ReplicaSets
kubectl apply -f k8s/replicasets/
# Deployments
kubectl apply -f k8s/deployments/
# Services
kubectl apply -f k8s/services/This will create:
- Deployments for MySQL and web (3 replicas each, rolling update strategy)
- ClusterIP Service for MySQL
- NodePort Service (port 30000) for web, exposed on VM port 80 via Kind mapping
kubectl get ns
kubectl get pods -n mysql
kubectl get pods -n web
kubectl get rs -n mysql -n web
kubectl get deploy -n mysql -n web
kubectl get svc -n mysql -n web# Logs from a web Pod
kubectl logs -n web <web-pod-name>
# Inside a web Pod
kubectl exec -n web <web-pod-name> -- curl -s localhost:8080
# From VM or laptop (HTTP on port 80)
curl http://<EC2_PUBLIC_IP>/To switch the theme color dynamically, patch the ConfigMap and roll out the update:
kubectl patch configmap app-config -n web \
--type merge \
-p '{"data":{"currentColor":"red"}}'
kubectl rollout restart deployment/web-deployment -n web
kubectl rollout status deployment/web-deployment -n webAll three web replicas will restart one-by-one and pick up the new
APP_COLORvalue.
- Kind: https://kind.sigs.k8s.io/
- Kubernetes Documentation: https://kubernetes.io/docs/
- AWS ECR: https://docs.aws.amazon.com/AmazonECR/latest/userguide/using-authorization-token.html
End of README