Skip to content

Commit d000552

Browse files
committed
Updates to use EKS for the cluster
1 parent b84847e commit d000552

File tree

8 files changed

+364
-521
lines changed

8 files changed

+364
-521
lines changed

01-path-basics/101-start-here/readme.adoc

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ If you are unsure, we recommend the "Launch template with an existing VPC" optio
1919
Click on the "Deploy to AWS" button and follow the CloudFormation prompts to begin.
2020

2121
[NOTE]
22-
AWS Cloud9 is currently available in 5 regions.
23-
Please choose the region closest to you.
22+
AWS Cloud9 is currently available in 5 regions, and EKS is currently available in 2 regions (us-east-1 and us-west-2).
23+
Please choose the region closest to you. If you choose a region for Cloud9 that does not support EKS, you will need to change the `AWS_DEFAULT_REGION` environment variable later.
2424

2525
|===
2626

2727
|Region | Launch template with a new VPC | Launch template with an existing VPC
2828
| *N. Virginia* (us-east-1)
29-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-vpc.template]
30-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-novpc.template]
29+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-vpc.template]
30+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-novpc.template]
3131

3232
| *Ohio* (us-east-2)
33-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-vpc.template]
34-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-novpc.template]
33+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-vpc.template]
34+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-novpc.template]
3535

3636
| *Oregon* (us-west-2)
37-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-vpc.template]
38-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-novpc.template]
37+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-vpc.template]
38+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-novpc.template]
3939

4040
| *Ireland* (eu-west-1)
41-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-vpc.template]
42-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-novpc.template]
41+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-vpc.template]
42+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-novpc.template]
4343

4444
| *Singapore* (ap-southeast-1)
45-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-vpc.template]
46-
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/lab-ide-novpc.template]
45+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-vpc.template]
46+
a| image::./deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/new?stackName=k8s-workshop&templateURL=https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/lab-ide-novpc.template]
4747

4848
|===
4949

@@ -55,34 +55,40 @@ You should see an environment similar to this:
5555

5656
image:cloud9-development-environment-welcome.png[]
5757

58+
=== Cloud9 Instance Role
59+
60+
The Cloud9 IDE needs to use the assigned IAM Instance profile. Open the "AWS Cloud9" menu, go to "Preferences", go to "AWS Settings", and disable "AWS managed temporary credentials" as depicted in the diagram here:
61+
62+
image:cloud9-disable-temp-credentials.png[]
63+
5864
=== Build Script
5965

6066
Once your Cloud9 is ready, download the build script and install in your IDE. This will prepare your IDE for running tutorials in this workshop. The build script installs the following:
6167

6268
- jq
6369
- kubectl _(the Kubernetes CLI, which we'll cover in great detail later in the workshop)_
64-
- kops _(Kubernetes Operations, which we'll also cover in detail later)_
65-
- configures the AWS CLI and stores necessary environment variables in bash_profile
70+
- heptio/authenticator _(for authentication to the EKS cluster)_
71+
- updates/configures the AWS CLI and stores necessary environment variables in bash_profile
6672
- creates an SSH key
6773
- clone the workshop repository into Cloud9
6874

6975
To install the script, run this command in the "bash" terminal tab of the Cloud9 IDE:
7076

71-
aws s3 cp s3://aws-kubernetes-artifacts/lab-ide-build.sh . && \
77+
aws s3 cp s3://aws-kubernetes-artifacts/v0.5/lab-ide-build.sh . && \
7278
chmod +x lab-ide-build.sh && \
7379
. ./lab-ide-build.sh
7480

7581
image:cloud9-run-script.png[Running the script in Cloud9 Terminal]
7682

77-
[NOTE]
78-
All shell commands _(starting with "$")_ throughout the rest of the workshop should be run in this tab. You may want to resize it upwards to make it larger.
83+
If you deployed your Cloud9 IDE in any region not supported by EKS, you will need to manually set the `AWS_DEFAULT_REGION` environment variable to a region supported by EKS:
7984

80-
At this point you can restart the Cloud9 IDE terminal session to ensure that the kublectl completion is enabled. Once a new terminal window is opened, type `kubectl get nodes`. You do not have to run the command. It is normal for this command to fail with an error message if you run it. You have not yet created the Kubernetes cluster. We are merely testing to make sure the `kubectl` tool is installed on the command line correctly and can autocomplete.
85+
export AWS_DEFAULT_REGION=us-east-1
86+
echo "AWS_DEFAULT_REGION=us-east-1" >> ~/.bash_profile
8187

82-
One last step is required so that the Cloud9 IDE uses the assigned IAM Instance profile. Open the "AWS Cloud9" menu, go to "Preferences", go to "AWS Settings", and disable "AWS managed temporary credentials" as depicted in the diagram here:
83-
84-
image:cloud9-disable-temp-credentials.png[]
88+
At this point you can restart the Cloud9 IDE terminal session to ensure that the kubectl completion is enabled. Once a new terminal window is opened, type `kubectl get nodes`. You do not have to run the command. It is normal for this command to fail with an error message if you run it. You have not yet created the Kubernetes cluster. We are merely testing to make sure the `kubectl` tool is installed on the command line correctly and can autocomplete.
8589

90+
[NOTE]
91+
All shell commands _(starting with "$")_ throughout the rest of the workshop should be run in this tab. You may want to resize it upwards to make it larger.
8692

8793
You are now ready to continue on with the workshop!
8894

@@ -100,23 +106,29 @@ You are now ready to continue on with the workshop!
100106
|link:../../operations-path.adoc[Go to Operations Index]
101107
|=====
102108

103-
The next step is link:../102-your-first-cluster[to create a Kubernetes cluster using kops].
109+
The next step is link:../102-your-first-cluster[to create a Kubernetes cluster using EKS].
104110

105111

106112
== Workshop Cleanup
107113

108114
Once you have finished with the workshop, please don't forget to spin down your cluster or you will incur additional charges.
109115
(We will also remind you at the end!)
110116

111-
==== Delete Kubernetes cluster resources
117+
Ensure that you have deleted all services, etc from the `default` namespace before proceeding.
118+
119+
==== Delete EKS worker nodeds
120+
121+
Go to CloudFormation console, right click template with name 'k8s-workshop-worker-nodes' and select 'Delete Stack'
122+
123+
==== Delete EKS cluster
112124

113-
In your Cloud9 IDE, check if there are any running kubernetes cluster
125+
In your Cloud9 IDE, check if there are any running EKS clusters
114126

115-
$ kops get cluster
127+
$ aws eks list-clusters
116128

117-
Delete kubernetes cluster
129+
Delete EKS cluster
118130

119-
$ kops delete cluster example.cluster.k8s.local --yes
131+
$ aws eks delete-cluster --name k8s-workshop
120132

121133
Wait until all resources are deleted by kops
122134

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# aws-auth ConfigMap script
2+
#title aws-auth-cm.sh
3+
#description This script will add a ConfigMap aws-auth to the EKS cluster k8s-workshop, allowing the worker nodes to join the cluster.
4+
#author @buzzsurfr
5+
#contributors @buzzsurfr @dalbhanj @cloudymind
6+
#date 2018-06-05
7+
#version 0.1
8+
#usage curl -sSL https://s3.amazonaws.com/aws-kubernetes-artifacts/v0.5/aws-auth-cm.sh | bash -s stable
9+
#==============================================================================
10+
11+
curl -O https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/aws-auth-cm.yaml
12+
export EKS_WORKER_ROLE=$(aws cloudformation describe-stacks --stack-name k8s-workshop-worker-nodes | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="NodeInstanceRole")|.OutputValue')
13+
sed -i -e "s#<ARN of instance role (not instance profile)>#${EKS_WORKER_ROLE}#g" aws-auth-cm.yaml
14+
kubectl apply -f aws-auth-cm.yaml

01-path-basics/101-start-here/scripts/lab-ide-build.sh

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# IDE-Build script
22
#title lab-ide-build.sh
3-
#description This script will make a header for a bash script.
4-
5-
#date 2018-01-19
6-
#version 0.1
3+
#description This script will setup the Cloud9 IDE with the prerequisite packages and code for the workshop.
4+
#author @buzzsurfr
5+
#contributors @buzzsurfr @dalbhanj @cloudymind
6+
#date 2018-05-12
7+
#version 0.2
78
#usage curl -sSL https://s3.amazonaws.com/lab-ide-theomazonian/lab-ide-build.sh | bash -s stable
8-
#notes Install Vim and Emacs to use this script.
99
#==============================================================================
1010

1111
# Install jq
1212
sudo yum -y install jq
1313

14+
# Update awscli
15+
sudo -H pip install -U awscli
16+
1417
# Install bash-completion
1518
sudo yum install bash-completion -y
1619

@@ -19,10 +22,9 @@ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s htt
1922
chmod +x kubectl && sudo mv kubectl /usr/local/bin/
2023
echo "source <(kubectl completion bash)" >> ~/.bashrc
2124

22-
# Install kops
23-
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
24-
chmod +x kops-linux-amd64
25-
sudo mv kops-linux-amd64 /usr/local/bin/kops
25+
# Install Heptio Authenticator
26+
go get -u github.com/heptio/authenticator/cmd/heptio-authenticator-aws
27+
export PATH=$PATH:$HOME/go/bin
2628

2729
# Configure AWS CLI
2830
availability_zone=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone)
@@ -39,14 +41,39 @@ export AWS_MASTER_STACK=${AWS_MASTER_STACK%?}
3941
export AWS_MASTER_STACK=${AWS_MASTER_STACK#aws-cloud9-}
4042
export KOPS_STATE_STORE=s3://$(aws cloudformation describe-stack-resource --stack-name $AWS_MASTER_STACK --logical-resource-id "KopsStateStore" | jq -r '.StackResourceDetail.PhysicalResourceId')
4143

44+
# EKS-specific variables from CloudFormation
45+
export EKS_VPC_ID=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksVpcId")|.OutputValue')
46+
export EKS_SUBNET_IDS=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksVpcSubnetIds")|.OutputValue')
47+
export EKS_SECURITY_GROUPS=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksVpcSecurityGroups")|.OutputValue')
48+
export EKS_SERVICE_ROLE=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksServiceRoleArn")|.OutputValue')
49+
4250
# Persist lab variables
51+
echo "export PATH=$HOME/go/bin:$PATH" >> ~/.bashrc
4352
echo "AWS_AVAILABILITY_ZONES=$AWS_AVAILABILITY_ZONES" >> ~/.bash_profile
4453
echo "KOPS_STATE_STORE=$KOPS_STATE_STORE" >> ~/.bash_profile
4554
echo "export AWS_AVAILABILITY_ZONES KOPS_STATE_STORE" >> ~/.bash_profile
4655

56+
# Persist EKS variables
57+
echo "EKS_VPC_ID=$EKS_VPC_ID" >> ~/.bash_profile
58+
echo "EKS_SUBNET_IDS=$EKS_SUBNET_IDS" >> ~/.bash_profile
59+
echo "EKS_SECURITY_GROUPS=$EKS_SECURITY_GROUPS" >> ~/.bash_profile
60+
echo "EKS_SERVICE_ROLE=$EKS_SERVICE_ROLE" >> ~/.bash_profile
61+
62+
# EKS-Optimized AMI
63+
if [ "$AWS_DEFAULT_REGION" == "us-east-1" ]; then
64+
export EKS_WORKER_AMI=ami-dea4d5a1
65+
elif [ "$AWS_DEFAULT_REGION" == "us-west-2" ]; then
66+
export EKS_WORKER_AMI=ami-73a6e20b
67+
fi
68+
echo "EKS_WORKER_AMI=$EKS_WORKER_AMI" >> ~/.bash_profile
69+
4770
# Create SSH key
4871
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
4972

73+
# Create EC2 Keypair
74+
aws ec2 create-key-pair --key-name ${AWS_STACK_NAME} --query 'KeyMaterial' --output text > $HOME/.ssh/k8s-workshop.pem
75+
chmod 0400 $HOME/.ssh/k8s-workshop.pem
76+
5077
if [ ! -d "aws-workshop-for-kubernetes/" ]; then
5178
# Download lab Repository
5279
git clone https://github.com/aws-samples/aws-workshop-for-kubernetes
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: v1
2+
clusters:
3+
- cluster:
4+
server: <endpoint-url>
5+
certificate-authority-data: <base64-encoded-ca-cert>
6+
name: kubernetes
7+
contexts:
8+
- context:
9+
cluster: kubernetes
10+
user: aws
11+
name: aws
12+
current-context: aws
13+
kind: Config
14+
preferences: {}
15+
users:
16+
- name: aws
17+
user:
18+
exec:
19+
apiVersion: client.authentication.k8s.io/v1alpha1
20+
command: heptio-authenticator-aws
21+
args:
22+
- "token"
23+
- "-i"
24+
- "<cluster-name>"
25+
# - "-r"
26+
# - "<role-arn>"

01-path-basics/101-start-here/templates/lab-ide-novpc.template

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"AWSTemplateFormatVersion": "2010-09-09",
3-
"Description": "Lab IDE using existing Subnet for container workshop v0.4",
3+
"Description": "Lab IDE using existing Subnet for container workshop v0.5",
44
"Metadata": {},
55
"Parameters": {
66
"SubnetId": {
@@ -12,6 +12,18 @@
1212
"Mappings": {},
1313
"Conditions": {},
1414
"Resources": {
15+
"EksVpc": {
16+
"Type" : "AWS::CloudFormation::Stack",
17+
"Properties" : {
18+
"TemplateURL" : "https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/amazon-eks-vpc-sample.yaml"
19+
}
20+
},
21+
"EksServiceRole": {
22+
"Type" : "AWS::CloudFormation::Stack",
23+
"Properties" : {
24+
"TemplateURL" : "https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/amazon-eks-service-role.yaml"
25+
}
26+
},
1527
"LabIDE": {
1628
"Description": "-",
1729
"Type": "AWS::Cloud9::EnvironmentEC2",
@@ -55,6 +67,25 @@
5567
}
5668
]
5769
},
70+
"Policies": [
71+
{
72+
"PolicyName": "eks-service",
73+
"PolicyDocument": {
74+
"Version": "2012-10-17",
75+
"Statement": [
76+
{
77+
"Effect": "Allow",
78+
"Action": [
79+
"eks:*",
80+
"cloudformation:CreateStack",
81+
"cloudformation:UpdateStack"
82+
],
83+
"Resource": "*"
84+
}
85+
]
86+
}
87+
}
88+
],
5889
"ManagedPolicyArns": [
5990
"arn:aws:iam::aws:policy/AmazonEC2FullAccess",
6091
"arn:aws:iam::aws:policy/AmazonRoute53FullAccess",
@@ -302,6 +333,26 @@
302333
]
303334
]
304335
}
336+
},
337+
"EksServiceRoleArn": {
338+
"Value": {
339+
"Fn::GetAtt": ["EksServiceRole", "Outputs.RoleArn"]
340+
}
341+
},
342+
"EksVpcId": {
343+
"Value": {
344+
"Fn::GetAtt": ["EksVpc", "Outputs.VpcId"]
345+
}
346+
},
347+
"EksVpcSubnetIds": {
348+
"Value": {
349+
"Fn::GetAtt": ["EksVpc", "Outputs.SubnetIds"]
350+
}
351+
},
352+
"EksVpcSecurityGroups": {
353+
"Value": {
354+
"Fn::GetAtt": ["EksVpc", "Outputs.SecurityGroups"]
355+
}
305356
}
306357
}
307358
}

0 commit comments

Comments
 (0)