Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit c414adf

Browse files
authored
Merge pull request #474 from buzzsurfr/master
Add EKS instructions
2 parents 889f477 + 8aaabfd commit c414adf

File tree

8 files changed

+406
-479
lines changed

8 files changed

+406
-479
lines changed

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

+51-22
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,41 @@ 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)_
70+
- heptio/authenticator _(for authentication to the EKS cluster)_
71+
- updates/configures the AWS CLI and stores necessary environment variables in bash_profile
6472
- kops _(Kubernetes Operations, which we'll also cover in detail later)_
65-
- configures the AWS CLI and stores necessary environment variables in bash_profile
6673
- creates an SSH key
6774
- clone the workshop repository into Cloud9
6875

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

71-
aws s3 cp s3://aws-kubernetes-artifacts/lab-ide-build.sh . && \
78+
aws s3 cp s3://aws-kubernetes-artifacts/v0.5/lab-ide-build.sh . && \
7279
chmod +x lab-ide-build.sh && \
7380
. ./lab-ide-build.sh
7481

7582
image:cloud9-run-script.png[Running the script in Cloud9 Terminal]
7683

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.
84+
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:
7985

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.
86+
export AWS_DEFAULT_REGION=us-east-1
87+
echo "AWS_DEFAULT_REGION=us-east-1" >> ~/.bash_profile
8188

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[]
89+
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.
8590

91+
[NOTE]
92+
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.
8693

8794
You are now ready to continue on with the workshop!
8895

@@ -100,14 +107,36 @@ You are now ready to continue on with the workshop!
100107
|link:../../operations-path.adoc[Go to Operations Index]
101108
|=====
102109

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

105112

106113
== Workshop Cleanup
107114

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

118+
Ensure that you have deleted all services, etc from the `default` namespace before proceeding.
119+
120+
=== Using EKS
121+
122+
==== Delete EKS worker nodeds
123+
124+
Go to CloudFormation console, right click template with name 'k8s-workshop-worker-nodes' and select 'Delete Stack'
125+
126+
==== Delete EKS cluster
127+
128+
In your Cloud9 IDE, check if there are any running EKS clusters
129+
130+
$ aws eks list-clusters
131+
132+
Delete EKS cluster
133+
134+
$ aws eks delete-cluster --name k8s-workshop
135+
136+
Wait until all resources are deleted by kops
137+
138+
=== Using kops
139+
111140
==== Delete Kubernetes cluster resources
112141

113142
In your Cloud9 IDE, check if there are any running kubernetes cluster
@@ -120,7 +149,7 @@ Delete kubernetes cluster
120149

121150
Wait until all resources are deleted by kops
122151

123-
==== Delete Cloud9 Envionment
152+
=== Delete Cloud9 Envionment
124153

125154
Go to CloudFormation console, right click template with name 'k8s-workshop' and select 'Delete Stack'
126155

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

+37-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
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

1720
# Install kubectl
18-
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
21+
curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/bin/linux/amd64/kubectl
1922
chmod +x kubectl && sudo mv kubectl /usr/local/bin/
20-
echo "source <(kubectl completion bash)" >> ~/.bashrc
23+
24+
# Install Heptio Authenticator
25+
curl -o heptio-authenticator-aws https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/bin/linux/amd64/heptio-authenticator-aws
26+
chmod +x ./heptio-authenticator-aws && sudo mv heptio-authenticator-aws /usr/local/bin/
2127

2228
# Install kops
2329
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
@@ -39,14 +45,38 @@ export AWS_MASTER_STACK=${AWS_MASTER_STACK%?}
3945
export AWS_MASTER_STACK=${AWS_MASTER_STACK#aws-cloud9-}
4046
export KOPS_STATE_STORE=s3://$(aws cloudformation describe-stack-resource --stack-name $AWS_MASTER_STACK --logical-resource-id "KopsStateStore" | jq -r '.StackResourceDetail.PhysicalResourceId')
4147

48+
# EKS-specific variables from CloudFormation
49+
export EKS_VPC_ID=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksVpcId")|.OutputValue')
50+
export EKS_SUBNET_IDS=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksVpcSubnetIds")|.OutputValue')
51+
export EKS_SECURITY_GROUPS=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksVpcSecurityGroups")|.OutputValue')
52+
export EKS_SERVICE_ROLE=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksServiceRoleArn")|.OutputValue')
53+
4254
# Persist lab variables
4355
echo "AWS_AVAILABILITY_ZONES=$AWS_AVAILABILITY_ZONES" >> ~/.bash_profile
4456
echo "KOPS_STATE_STORE=$KOPS_STATE_STORE" >> ~/.bash_profile
4557
echo "export AWS_AVAILABILITY_ZONES KOPS_STATE_STORE" >> ~/.bash_profile
4658

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

76+
# Create EC2 Keypair
77+
aws ec2 create-key-pair --key-name ${AWS_STACK_NAME} --query 'KeyMaterial' --output text > $HOME/.ssh/k8s-workshop.pem
78+
chmod 0400 $HOME/.ssh/k8s-workshop.pem
79+
5080
if [ ! -d "aws-workshop-for-kubernetes/" ]; then
5181
# Download lab Repository
5282
git clone https://github.com/aws-samples/aws-workshop-for-kubernetes
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

+52-1
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)