Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Last active October 7, 2023 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vfarcic/0ce1ccdd862f401bbacf56d3ca18b808 to your computer and use it in GitHub Desktop.
Save vfarcic/0ce1ccdd862f401bbacf56d3ca18b808 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/0ce1ccdd862f401bbacf56d3ca18b808
######################
# Create The Cluster #
######################
# Make sure that you're using eksctl v0.1.5+.
# Follow the instructions from https://github.com/weaveworks/eksctl to intall eksctl.
export AWS_ACCESS_KEY_ID=[...] # Replace [...] with AWS access key ID
export AWS_SECRET_ACCESS_KEY=[...] # Replace [...] with AWS secret access key
export AWS_DEFAULT_REGION=us-west-2
export NAME=devops25
mkdir -p cluster
eksctl create cluster \
-n $NAME \
-r $AWS_DEFAULT_REGION \
--kubeconfig cluster/kubecfg-eks \
--node-type t2.small \
--nodes-max 9 \
--nodes-min 3 \
--asg-access \
--managed
export KUBECONFIG=$PWD/cluster/kubecfg-eks
###################
# Install Ingress #
###################
kubectl apply \
-f https://raw.githubusercontent.com/kubernetes/ingress-nginx/1cd17cd12c98563407ad03812aebac46ca4442f2/deploy/mandatory.yaml
kubectl apply \
-f https://raw.githubusercontent.com/kubernetes/ingress-nginx/1cd17cd12c98563407ad03812aebac46ca4442f2/deploy/provider/aws/service-l4.yaml
kubectl apply \
-f https://raw.githubusercontent.com/kubernetes/ingress-nginx/1cd17cd12c98563407ad03812aebac46ca4442f2/deploy/provider/aws/patch-configmap-l4.yaml
##################
# Metrics Server #
##################
kubectl create namespace metrics
helm install metrics-server \
stable/metrics-server \
--version 2.0.2 \
--namespace metrics
kubectl -n metrics \
rollout status \
deployment metrics-server
##################
# Get Cluster IP #
##################
LB_HOST=$(kubectl -n ingress-nginx \
get svc ingress-nginx \
-o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
export LB_IP="$(dig +short $LB_HOST \
| tail -n 1)"
echo $LB_IP
# Repeat the `export` command if the output is empty
#######################
# Destroy the cluster #
#######################
export AWS_DEFAULT_REGION=us-west-2
eksctl delete cluster -n devops25
SG_NAME=$(aws ec2 describe-security-groups \
--filters Name=group-name,Values=k8s-elb-$LB_NAME \
| jq -r ".SecurityGroups[0].GroupId")
echo $SG_NAME
aws ec2 delete-security-group \
--group-id $SG_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment