Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Simplified EKS cluster setup script (#2048)

Eric Bariaux40519e0f75f6
diff --git a/kubernetes/README-AWS.md b/kubernetes/README-AWS.md
index 833e5840d..30d4e46fb 100644
--- a/kubernetes/README-AWS.md
+++ b/kubernetes/README-AWS.md
@@ -112,7 +112,7 @@ See the values-eks.yaml files annotations fields for more information.
Some aspects of the setup are configurable.
-### eks-setup.sh script variables
+### eks-common.sh script variables
The script contains several variables that can be changed.
@@ -180,6 +180,4 @@ and the manager (which is not architected yet to support multiple replicas).
We could explore using storage class and not explicit binding and/or using other volume types.
We should anyway review the manager usage of persistent storage and limit the use of the file system for this purpose.
-There is some duplication in the configuration, with the same values appearing in the shell scripts and the cluster.yaml file.
-When moving to production usage, this should be reviewed.
-But also the shell script might be replaced with CloudFormation templates or using Terraform or similar tools.
+When moving to production usage, the shell script might be replaced with CloudFormation templates or using Terraform or similar tools.
diff --git a/kubernetes/cluster.yaml b/kubernetes/cluster.yaml
index 4f8a4b3ec..d39bd1836 100644
--- a/kubernetes/cluster.yaml
+++ b/kubernetes/cluster.yaml
@@ -2,17 +2,32 @@ apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
- name: testcluster
- region: eu-west-1
+ name: ${CLUSTER_NAME}
+ region: ${AWS_REGION}
# Kubernetes version to use for cluster, good idea to keep up to date
version: "1.33"
availabilityZones:
- - eu-west-1a
- - eu-west-1b
+ - ${AWS_REGION}a
+ - ${AWS_REGION}b
+
+iam:
+ withOIDC: true
+ serviceAccounts:
+ - metadata:
+ name: aws-load-balancer-controller
+ namespace: kube-system
+ wellKnownPolicies:
+ awsLoadBalancerController: true
nodeGroups:
- name: ng-1
instanceType: t2.large
volumeSize: 32
desiredCapacity: 2
+
+addons:
+ - name: aws-ebs-csi-driver
+ version: latest
+ wellKnownPolicies:
+ ebsCSIController: true
diff --git a/kubernetes/eks-common.sh b/kubernetes/eks-common.sh
index 73a2c7829..d226845b0 100755
--- a/kubernetes/eks-common.sh
+++ b/kubernetes/eks-common.sh
@@ -3,8 +3,7 @@
set -eo pipefail
# Name of cluster, not exposed but must be unique within account
-# !!! make sure to also update in cluster.yaml
-CLUSTER_NAME=testcluster
+export CLUSTER_NAME=testcluster
# Hostname to use for public access to this instance, always under the openremote.app domain
HOSTNAME=testmanager
@@ -12,8 +11,7 @@ FQDN=$HOSTNAME.openremote.app
MQTT_FQDN=mqtt.$FQDN
MQTTS_FQDN=mqtts.$FQDN
-# !!! make sure region in cluster.yaml matches
-AWS_REGION="eu-west-1"
+export AWS_REGION="eu-west-1"
AWS_ACCOUNT_ID="463235666115" # openremote
DNSCHG_ROLE_ARN="arn:aws:iam::134517981306:role/route53-full-access"
diff --git a/kubernetes/eks-setup-haproxy.sh b/kubernetes/eks-setup-haproxy.sh
index 97d086ad1..621b4dc4c 100755
--- a/kubernetes/eks-setup-haproxy.sh
+++ b/kubernetes/eks-setup-haproxy.sh
@@ -2,58 +2,11 @@
. ./eks-common.sh
-# TODO: --name $CLUSTER_NAME -> in cluster.yaml
-# TODO: region is duplicated in cluster.yaml
-eksctl create cluster -f cluster.yaml --profile or
-
-# TODO: maybe extract cluster name after cluster creation so source of truth is in cluster.yaml, not other way around
-# Not straightforward
-
-# TODO: it might be possible to replace some of the operations below by configuration options in cluster.yaml
-oidc_id=$(aws eks describe-cluster --profile or --name $CLUSTER_NAME --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
-
-eksctl utils associate-iam-oidc-provider --profile or --cluster $CLUSTER_NAME --approve
-
-eksctl create iamserviceaccount --profile or \
- --name ebs-csi-controller-sa \
- --namespace kube-system \
- --cluster $CLUSTER_NAME \
- --role-name AmazonEKS_EBS_CSI_DriverRole \
- --role-only \
- --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
- --approve
-
-eksctl create addon --profile or --cluster $CLUSTER_NAME --name aws-ebs-csi-driver --version latest \
- --service-account-role-arn arn:aws:iam::$AWS_ACCOUNT_ID:role/AmazonEKS_EBS_CSI_DriverRole --force
+envsubst < cluster.yaml | eksctl create cluster -f - --profile or
# [Installation Guide - AWS Load Balancer Controller](https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/installation/)
-curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.11.0/docs/install/iam_policy.json
-
-POLICY_NAME="AWSLoadBalancerControllerIAMPolicy"
-POLICY_ARN="arn:aws:iam::$AWS_ACCOUNT_ID:policy/$POLICY_NAME"
-
-if ! aws iam get-policy --policy-arn "$POLICY_ARN" >/dev/null 2>&1; then
- echo "Policy does not exist. Creating..."
- aws iam create-policy \
- --policy-name "$POLICY_NAME" \
- --policy-document file://iam_policy.json
-fi
-
-rm -f iam_policy.json
-
-eksctl create iamserviceaccount --profile or \
- --cluster=$CLUSTER_NAME \
- --namespace=kube-system \
- --name=aws-load-balancer-controller \
- --role-name AmazonEKSLoadBalancerControllerRole \
- --attach-policy-arn=arn:aws:iam::$AWS_ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy \
- --approve
-
-# [Install AWS Load Balancer Controller with Helm - Amazon EKS](https://docs.aws.amazon.com/eks/latest/userguide/lbc-helm.html)
-
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 \
diff --git a/kubernetes/eks-setup.sh b/kubernetes/eks-setup.sh
index c1dd8ada0..487f30c1d 100755
--- a/kubernetes/eks-setup.sh
+++ b/kubernetes/eks-setup.sh
@@ -2,58 +2,11 @@
. ./eks-common.sh
-# TODO: --name $CLUSTER_NAME -> in cluster.yaml
-# TODO: region is duplicated in cluster.yaml
-eksctl create cluster -f cluster.yaml --profile or
-
-# TODO: maybe extract cluster name after cluster creation so source of truth is in cluster.yaml, not other way around
-# Not straightforward
-
-# TODO: it might be possible to replace some of the operations below by configuration options in cluster.yaml
-oidc_id=$(aws eks describe-cluster --profile or --name $CLUSTER_NAME --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
-
-eksctl utils associate-iam-oidc-provider --profile or --cluster $CLUSTER_NAME --approve
-
-eksctl create iamserviceaccount --profile or \
- --name ebs-csi-controller-sa \
- --namespace kube-system \
- --cluster $CLUSTER_NAME \
- --role-name AmazonEKS_EBS_CSI_DriverRole \
- --role-only \
- --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
- --approve
-
-eksctl create addon --profile or --cluster $CLUSTER_NAME --name aws-ebs-csi-driver --version latest \
- --service-account-role-arn arn:aws:iam::$AWS_ACCOUNT_ID:role/AmazonEKS_EBS_CSI_DriverRole --force
+envsubst < cluster.yaml | eksctl create cluster -f - --profile or
# [Installation Guide - AWS Load Balancer Controller](https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/installation/)
-curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.11.0/docs/install/iam_policy.json
-
-POLICY_NAME="AWSLoadBalancerControllerIAMPolicy"
-POLICY_ARN="arn:aws:iam::$AWS_ACCOUNT_ID:policy/$POLICY_NAME"
-
-if ! aws iam get-policy --policy-arn "$POLICY_ARN" >/dev/null 2>&1; then
- echo "Policy does not exist. Creating..."
- aws iam create-policy \
- --policy-name "$POLICY_NAME" \
- --policy-document file://iam_policy.json
-fi
-
-rm -f iam_policy.json
-
-eksctl create iamserviceaccount --profile or \
- --cluster=$CLUSTER_NAME \
- --namespace=kube-system \
- --name=aws-load-balancer-controller \
- --role-name AmazonEKSLoadBalancerControllerRole \
- --attach-policy-arn=arn:aws:iam::$AWS_ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy \
- --approve
-
-# [Install AWS Load Balancer Controller with Helm - Amazon EKS](https://docs.aws.amazon.com/eks/latest/userguide/lbc-helm.html)
-
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 \