Simple cluster with 1 EC2 node and ready to deploy a K8 Service
Disclaimer: this is not production-fit, because security practices are not followed, but that allows a quick setup and deployment
In order to follow this guide, you should
- have basic knowledge in aws
- have basic knowledge in container-orchestration
- have aws-cli installed and configured
- have kubectl installed
- have helm installed
- have terraform installed
- have a linux (debian-based) distro
I'm using ids for my AWS Account, you should replace these with your own.
terraform init
terraform apply
aws eks update-kubeconfig --name eks-cluster
kubectl cluster-info #if this command works, you are good to continue
kubectl edit configmap aws-auth -n kube-system
and copy-paste (replace account-id
for you actual aws account-id):
apiVersion: v1
data:
mapRoles: |
- groups:
- system:bootstrappers
- system:nodes
rolearn: arn:aws:iam::accound-id:role/eks_node_role
username: system:node:{{EC2PrivateDNSName}}
mapUsers: |
- userarn: arn:aws:iam::account-id:root
groups:
- system:masters
kind: ConfigMap
metadata:
creationTimestamp: "2023-07-12T20:16:44Z" #this value varies
name: aws-auth
namespace: kube-system
resourceVersion: "892" #this value varies
uid: 2b98bfa1-29de-4120-9f74-dc25f69416f0 #this value varies
cd k8-apps/
kubectl apply -f nginx-deployment.yml
kubectl apply -f nginx-service.yml
kubectl get services #here you will get the External-IP, copy it in your browser and should work
If you want to expose the app as NodePort
this command will be useful.
kubectl get nodes -o wide | awk {'print $1" " $2 " " $7'} | column -t
cd k8-apps/
kubectl apply -f lb-controller-service-account.yml
- (double-check clusterName param)
helm repo add eks https://aws.github.io/eks-charts
helm repo update eks
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
-n kube-system \
--set clusterName=eks-cluster \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller
-
add tags to vpc-subnets
kubernetes.io/role/elb = 1
if the subnet is public, andkubernetes.io/role/internal-elb = 1
if private.
cd k8-apps/
kubectl apply -f 2048_full.yml
kubectl get ingress -n game-2048 # copy the Address in your browser and it should work
In case you want to read more: