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 need to create VPC resources and change environment variables. This configuration has not been tested. |
Region |
Launch template with a new VPC |
Launch template with an existing VPC |
N. Virginia (us-east-1) |
||
Oregon (us-west-2) |
Accept the default stack name and Click Next. You can give Tags such as Key=Name, Value=k8s-workshop, and click Next. Make sure to check I acknowledge that AWS CloudFormation might create IAM resources with custom names and click Create.
CloudFormation creates nested stacks and builds several resources that are required for this workshop. Wait until all the resources are created. Once the status for k8s-workshop changes to CREATE_COMPLETE, you can open Cloud9 IDE. 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://aws-kubernetes-artifacts/v0.5/lab-ide-build.sh . && \ chmod +x lab-ide-build.sh && \ . ./lab-ide-build.sh
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 ver
and press Tab
to autocomplete and press Enter
. This will ensure that 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. For a better understanding of the roles and policies that make up these credentials, check out the permissions section.
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.