Last active
July 10, 2019 14:05
-
-
Save vitor-caetano/13d0e71a13bf88874108af6866f0582c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################### | |
# Create a cluster # | |
#################### | |
# Install [AWS CLI](https://aws.amazon.com/cli/) and make sure you have AWS admin permissions | |
# Install [eksctl](https://github.com/weaveworks/eksctl) | |
source aws_oregon.sh | |
echo "nexus: | |
enabled: false | |
" | tee myvalues.yaml | |
jx create cluster eks \ | |
--cluster-name jx-rocks \ | |
--region $AWS_DEFAULT_REGION \ | |
--node-type t2.large \ | |
--nodes 3 \ | |
--nodes-min 3 \ | |
--nodes-max 6 \ | |
--default-admin-password admin \ | |
--default-environment-prefix jx-rocks \ | |
--static-jenkins | |
############################# | |
# Create Cluster Autoscaler # | |
############################# | |
ASG_NAME=$(aws autoscaling \ | |
describe-auto-scaling-groups \ | |
| jq -r ".AutoScalingGroups[] \ | |
| select(.AutoScalingGroupName \ | |
| startswith(\"eksctl-jx-rocks-nodegroup\")) \ | |
.AutoScalingGroupName") | |
echo $ASG_NAME | |
aws autoscaling \ | |
create-or-update-tags \ | |
--tags \ | |
ResourceId=$ASG_NAME,ResourceType=auto-scaling-group,Key=k8s.io/cluster-autoscaler/enabled,Value=true,PropagateAtLaunch=true \ | |
ResourceId=$ASG_NAME,ResourceType=auto-scaling-group,Key=kubernetes.io/cluster/jx-rocks,Value=true,PropagateAtLaunch=true | |
IAM_ROLE=$(aws iam list-roles \ | |
| jq -r ".Roles[] \ | |
| select(.RoleName \ | |
| startswith(\"eksctl-jx-rocks-nodegroup\")) \ | |
.RoleName") | |
echo $IAM_ROLE | |
aws iam put-role-policy \ | |
--role-name $IAM_ROLE \ | |
--policy-name jx-rocks-AutoScaling \ | |
--policy-document https://raw.githubusercontent.com/vfarcic/k8s-specs/master/scaling/eks-autoscaling-policy.json | |
mkdir -p charts | |
helm fetch stable/cluster-autoscaler \ | |
-d charts \ | |
--untar | |
mkdir -p k8s-specs/aws | |
helm template charts/cluster-autoscaler \ | |
--name aws-cluster-autoscaler \ | |
--output-dir k8s-specs/aws \ | |
--namespace kube-system \ | |
--set autoDiscovery.clusterName=jx-rocks \ | |
--set awsRegion=us-west-2 \ | |
--set sslCertPath=/etc/kubernetes/pki/ca.crt \ | |
--set rbac.create=true | |
kubectl apply \ | |
-n kube-system \ | |
-f k8s-specs/aws/cluster-autoscaler/* | |
################# | |
# Check Cluster # | |
################# | |
kubectl --namespace jx get pods | |
jx console | |
##################### | |
# Create QuickStart # | |
##################### | |
jx create quickstart | |
####################### | |
# Destroy the cluster # | |
####################### | |
eksctl delete cluster -n jx-rocks | |
# Only if there are no other ELBs in that region. Otherwise, remove the LB manually. | |
LB_ARN=$(aws elbv2 describe-load-balancers | jq -r \ | |
".LoadBalancers[0].LoadBalancerArn") | |
echo $LB_ARN | |
aws elbv2 delete-load-balancer \ | |
--load-balancer-arn $LB_ARN | |
IAM_ROLE=$(aws iam list-roles \ | |
| jq -r ".Roles[] \ | |
| select(.RoleName \ | |
| startswith(\"eksctl-jx-rocks-nodegroup\")) \ | |
.RoleName") | |
echo $IAM_ROLE | |
aws iam delete-role-policy \ | |
--role-name $IAM_ROLE \ | |
--policy-name jx-rocks-AutoScaling | |
eksctl delete cluster -n jx-rocks | |
# Delete unused volumes | |
for volume in `aws ec2 describe-volumes --output text| grep available | awk '{print $8}'`; do | |
echo "Deleting volume $volume" | |
aws ec2 delete-volume --volume-id $volume | |
done | |
################## | |
# Cleanup GitHub # | |
################## | |
GH_USER=vitor-caetano | |
hub delete -y $GH_USER/environment-jx-rocks-staging | |
hub delete -y $GH_USER/environment-jx-rocks-production | |
hub delete -y $GH_USER/jx-go | |
rm -rf ~/.jx/environments/$GH_USER/environment-jx-rocks-* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment