|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +## Create the EKS cluster |
| 5 | + |
| 6 | +There are many ways to create a cluster and which specific one to use depends on specifications that are outside of the generic scope. |
| 7 | + |
| 8 | +This is a good starting point: https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html. |
| 9 | +In doubt, [Auto Mode Cluster](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-automode.html) is a good place to start. |
| 10 | + |
| 11 | +## Ingress setup |
| 12 | + |
| 13 | +The following is inspired by https://aws.amazon.com/blogs/containers/exposing-kubernetes-applications-part-3-nginx-ingress-controller/, section "Exposing Ingress-Nginx Controller via a Load Balancer". |
| 14 | +Be aware that the article is from 2022 and it doesn't work 100%. |
| 15 | +Following the steps that worked for us on May 2025 |
| 16 | + |
| 17 | +### Setup the policy and service account |
| 18 | + |
| 19 | +Note that have to pay attention to the version of the aws-load-balancer-controller to match with the policy. Wrong version will make things fail |
| 20 | + |
| 21 | +```bash |
| 22 | +curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json |
| 23 | +aws iam create-policy --policy-name AWSLoadBalancerControllerIAMPolicy --policy-document file://iam-policy.json |
| 24 | +AWS_ACCOUNT=527966638683 |
| 25 | +eksctl create iamserviceaccount \ |
| 26 | + --cluster=metacell-dev \ |
| 27 | + --name=aws-load-balancer-controller \ |
| 28 | + --namespace=kube-system \ |
| 29 | + --attach-policy-arn=arn:aws:iam::${AWS_ACCOUNT}:policy/AWSLoadBalancerControllerIAMPolicy \ |
| 30 | + --approve |
| 31 | +``` |
| 32 | + |
| 33 | +### Install the aws-load-balancer-controller |
| 34 | + |
| 35 | +First, apply custom resource definition |
| 36 | +```bash |
| 37 | +wget https://raw.githubusercontent.com/aws/eks-charts/refs/heads/master/stable/aws-load-balancer-controller/crds/crds.yaml |
| 38 | +kubectl apply -f crds.yaml |
| 39 | +``` |
| 40 | + |
| 41 | +Then install the helm chart |
| 42 | +From https://github.com/aws/eks-charts/tree/master/stable/aws-load-balancer-controller |
| 43 | +```bash |
| 44 | +helm repo add eks https://aws.github.io/eks-charts |
| 45 | +# If using IAM Roles for service account install as follows - NOTE: you need to specify both of the chart values `serviceAccount.create=false` and `serviceAccount.name=aws-load-balancer-controller` |
| 46 | +helm install aws-load-balancer-controller eks/aws-load-balancer-controller --set clusterName=metacell-dev -n kube-system --set serviceAccount.create=false --set serviceAccount.name=aws-load-balancer-controller |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | +### Fix vpc |
| 51 | + |
| 52 | +If encounter the following error related to vpc |
| 53 | + |
| 54 | +> {"level":"info","ts":"2025-05-21T13:53:48Z","msg":"version","GitVersion":"v2.13.2","GitCommit":"4236bd7928711874ae4d8aff6b97870b5625140f","BuildDate":"2025-05-15T17:37:55+0000"} |
| 55 | +> {"level":"error","ts":"2025-05-21T13:53:53Z","logger":"setup","msg":"unable to initialize AWS cloud","error":"failed to get VPC ID: failed to fetch VPC ID from instance metadata: error in fetching vpc id through ec2 metadata: get mac metadata: operation error ec2imds: GetMetadata, canceled, context deadline exceeded"} |
| 56 | +
|
| 57 | +First get the vpc id: |
| 58 | + |
| 59 | +```bash |
| 60 | +aws eks describe-cluster \ |
| 61 | + --name metacell-dev \ |
| 62 | + --region us-west-2 \ |
| 63 | + --query "cluster.resourcesVpcConfig.vpcId" \ |
| 64 | + --output text |
| 65 | +``` |
| 66 | + |
| 67 | +Then fix the vpc id value |
| 68 | +```bash |
| 69 | +helm upgrade aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system --reuse-values --set vpcId=$VPC_ID |
| 70 | +``` |
| 71 | + |
| 72 | +### Install ingress nginx |
| 73 | + |
| 74 | +```bash |
| 75 | +helm upgrade -i ingress-nginx ingress-nginx/ingress-nginx \ |
| 76 | + --namespace kube-system \ |
| 77 | + --values ingress/values-aws.yaml |
| 78 | + |
| 79 | +kubectl -n kube-system rollout status deployment ingress-nginx-controller |
| 80 | + |
| 81 | +kubectl get deployment -n kube-system ingress-nginx-controller |
| 82 | +``` |
| 83 | + |
| 84 | +### Associate the DNS |
| 85 | + |
| 86 | +The endpoint can be assigned with 2 CNAME entries. |
| 87 | +For instance, if you run `harness-deployment ... -d myapp.mydomain.com`, |
| 88 | +the following CNAME entries are needed |
| 89 | +- myapp [LB_ADDRESS] |
| 90 | +- *.myapp [LB_ADDRESS] |
| 91 | + |
| 92 | + |
| 93 | +The easiest way to get the load balancer addressis to do the deployment and |
| 94 | +from the ingress with |
| 95 | + |
| 96 | +``` |
| 97 | +kubectl get ingress |
| 98 | +``` |
| 99 | + |
| 100 | +## Storage class |
| 101 | + |
| 102 | +EKS does not provide a default storage class. |
| 103 | +To create one, run |
| 104 | + |
| 105 | +```bash |
| 106 | +kubectl apply -f storageclass-default-aws.yaml |
| 107 | +``` |
| 108 | + |
| 109 | +## Container registry |
| 110 | + |
| 111 | +CloudHarness pushes images on a container registry, which has to be readable from EKS |
| 112 | + |
| 113 | +Any public registry can be used seamlessly, while ECR is recommended to pull private images |
| 114 | + |
| 115 | +1. Create a new ECR registry |
| 116 | +2. Create all the repositories within the deployment (ECR does not create repositories automatically on push, unless this is implemented https://aws.amazon.com/blogs/containers/dynamically-create-repositories-upon-image-push-to-amazon-ecr/) |
| 117 | +3. Give the permissions to the Node IAM role |
| 118 | +https://docs.aws.amazon.com/AmazonECR/latest/userguide/ECR_on_EKS.html (the role should be AmazonSSMRoleForInstancesQuickSetup for Auto Mode Clusters) |
| 119 | + |
| 120 | +To push images, have to authenticate to the registry. |
| 121 | + |
| 122 | +To authenticate from the local console, the command looks like the following: |
| 123 | + |
| 124 | +```bash |
| 125 | +aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 527966638683.dkr.ecr.us-west-2.amazonaws.com |
| 126 | +``` |
| 127 | + |
| 128 | +The exact command can also be viewed by hitting "View push commands" from the web console. |
0 commit comments