This section walks you through the creating a Kubernetes development environment using AWS Cloud9. This will provide you with a cloud-based integrated development environment (IDE) that will let you write, run, and debug containerized workloads using just a web browser.
We can create the Cloud9 development environment via CloudFormation. This CloudFormation template will spin up the Cloud9 IDE, as well as configure the IDE environment for the rest of the workshop.
The CloudFormation template can create a new VPC, or you can choose an existing VPC if needed. If you are unsure, we recommend the "Launch template with an existing VPC" option.
Click on the "Deploy to AWS" button and follow the CloudFormation prompts to begin.
Note
|
AWS Cloud9 is currently available in 5 regions, and EKS is currently available in 2 regions (us-east-1 and us-west-2).
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.
|
- FOR THE SPANNING LAB, WE REQUEST YOU ONLY USE US-WEST-2 FOR THIS LAB.
- WE HAVE REMOVED THE OTHER CLOUDFORMATION SCRIPTS FOR OTHER REGIONS,
- BUT WE CAN PROVIDE LINKS IF YOU ARE INTERESTED
-
- WE ALSO RECOMMEND YOU USE 'new VPC' INSTEAD OF 'existing VPC' IN YOUR
- LAB ACCOUNT.
Region |
Launch template with a new VPC |
Launch template with an existing VPC |
Oregon (us-west-2) |
To open the Cloud9 IDE environment, click on the "Outputs" tab in CloudFormation Console and click on the "Cloud9IDE" URL.
You should see an environment similar to this:
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:
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:
-
jq
-
kubectl (the Kubernetes CLI, which we’ll cover in great detail later in the workshop)
-
heptio/authenticator (for authentication to the EKS cluster)
-
updates/configures the AWS CLI and stores necessary environment variables in bash_profile
-
kops (Kubernetes Operations, which we’ll also cover in detail later)
-
creates an SSH key
-
clone the workshop repository into Cloud9
To install the script, run this command in the "bash" terminal tab of the Cloud9 IDE:
aws s3 cp s3://jrschutz-public-stuff/lab-ide-build.sh . && \ chmod +x lab-ide-build.sh && \ . ./lab-ide-build.sh
You will need to set the AWS_DEFAULT_REGION
environment variable to a region with EKS support, so that your AWS CLI commands will successfully execute. If not running in the us-east-1
region, replace it in the commands below with the appropriate region.
export AWS_DEFAULT_REGION=us-west-2 echo "export AWS_DEFAULT_REGION=us-west-2" >> ~/.bash_profile
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.
Note
|
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. |
You are now ready to continue on with the workshop!
The next step is to create a Kubernetes cluster.
Once you have finished with the workshop, please don’t forget to spin down your cluster or you will incur additional charges. (We will also remind you at the end!)
Ensure that you have deleted all services, etc from the default
namespace before proceeding.
Go to CloudFormation console, right click template with name 'k8s-workshop-worker-nodes' and select 'Delete Stack'
This appendix provides instructions for those who don’t want to use the provided CloudFormation template, or who would like to configure Cloud9 manually.
AWS Cloud9 is only available in 5 regions currently. Please choose the region closest to you geographically.
Once there, follow these steps:
-
Provide a name for your environment. Feel free to use something simple, such as
k8s-workshop
. Then click "Next Step". -
Change the "Instance Type" to
t2.small (2 GiB RAM + 1 vCPU)
. -
Expand the "Network settings (advanced)" section and make sure you are using the default VPC. It will have "(default)" next to the name. If you do not have a default VPC listed, it is recommended that you create a "Single Public Subnet" VPC by clicking the "Create new VPC" button and following the wizard it presents.
-
If everything is correct, click the "Next Step" button.
-
Review the configuration to ensure everything is correct and then click the "Create environment" button.
This will close the wizard and you will be taken to a screen informing you that your new AWS Cloud9 environment is being created. Once this is completed, the IDE will open to the following screen:
Your environment is now ready to be setup for working with Kubernetes and the rest of this workshop.
Your AWS Cloud9 environment comes with many useful tools preinstalled, but there are still a few tweaks to these and additional tools you will need to support working with Kubernetes.
Your AWS Cloud9 environment comes with the AWS CLI preinstalled and configured to automatically use the credentials of the currently logged in user. Make sure you are logged in as a user with these permissions.
It is not recommended that you change the default AWS CLI config in your AWS Cloud9 environment. Instead, it is recommended that you provide the logged in user’s account the permissions needed to make any requests needed by your project. More information on this can be found by visiting: Calling AWS Services from an Environment in AWS Cloud9
Note
|
All the commands below should be run in the Terminal section of your Cloud9 GUI. |
Docker is preinstalled. You can verify the version by running the following:
$ docker --version Docker version 17.06.2-ce, build 3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
You should have a similar or newer version.
Install the Kubectl CLI:
$ curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.2/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Add kubectl autocompletion to your current shell:
$ source <(kubectl completion bash)
You can verify that kubectl is installed by executing the following command:
$ kubectl version --client Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.2", GitCommit:"6e937839ac04a38cac63e6a7a306c5d035fe7b0a", GitTreeState:"clean", BuildDate:"2017-09-28T22:57:57Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Install kops using the following:
$ 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 $ chmod +x kops-linux-amd64 $ sudo mv kops-linux-amd64 /usr/local/bin/kops
kops needs to know the availability zones to use when configuring a cluster. We set an environment variable $AWS_AVAILABILITY_ZONES
based on the region.
$ export AWS_AVAILABILITY_ZONES="$(aws ec2 describe-availability-zones --query 'AvailabilityZones[].ZoneName' --output text | awk -v OFS="," '$1=$1')"
kops needs a “state store” to store configuration information of the cluster. We will use a s3 bucket with versioning enabled. A state store can work with multiple kops clusters.
Note
|
The bucket name must be unique otherwise you will encounter an error on deployment. We will use an example bucket name of kops-state-store- and add a randomly generated string to the end.
|
$ export S3_BUCKET=kops-state-store-$(cat /dev/urandom | LC_ALL=C tr -dc "[:alpha:]" | tr '[:upper:]' '[:lower:]' | head -c 32) $ export KOPS_STATE_STORE=s3://${S3_BUCKET} $ aws s3 mb $KOPS_STATE_STORE $ aws s3api put-bucket-versioning --bucket $S3_BUCKET --versioning-configuration Status=Enabled
The workshop repository has configuration files that are used to create Kubernetes resources. You need to clone the repo to have access to those files:
$ git clone https://github.com/aws-samples/aws-workshop-for-kubernetes
At this point, you should have everything you need to complete any of the sections of the this workshop using your Cloud9 Environment.