Setup a SandBox/Development K8s Environment with KOps and Ubuntu 18.04 AMD64 Bionic
I needed to set up an environment for my development team, allowing them to utilize one of the same tools used for the CKA exam and an environment to obtain real hands-on experience for onboarding to K8s. So let's explain how this is done.
- Must have the AWS CLI installed
- Must have the KOps CLI installed
- Must have a valid AWS Admin account associated with the Profile for the AWS CLI.
Step 1. Identify the AMI
This section will identify the particular AMI that will be utilized by KOps based on the particular region in AWS.
aws ec2 describe-images --region us-east-1 --output table --owners 099720109477 --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-*"
I usually scroll down to the bottom of the table and pull the latest image for 18.
AMI I will be using in this article is:
Step 2. Create a Route53 Domain for the Cluster
This is pretty explanatory. Create a domain with Route53 as the hosted zone will be used for installation.
Step 3. Single-State Management with S3
An S3 bucket will need to be created to contain the state of the Kubernetes environment. This S3 bucket is used by KOps to handle the desired and as-is state of the environments.
In this example, I will be using an S3 bucket called:
Step 4. Build your cluster configuration as desired.
This will run the Kops CLI to install the cluster on AWS. KOps utilize Terraform to provision the servers on AWS. So this command will utilize the AWS CLI along with the attributes given to the KOps installer to provision the cluster.
Understanding the Keys
The keys utilized by default by KOps is the .ssh default key within your user account. If you do not already have a key created then you can utilize the ssh-keygen utility to create one. This key will also be used to access the Master or Master within the cluster. Hopefully, you set up your cluster for fault tolerance.
Understanding the Configuration
Let’s understand what the below command actually means.
kops create cluster --node-count 3 --zones us-west-2a,us-west-2b,us-west-2c --master-zones us-west-2a,us-west-2b,us-west-2c --node-size t2.medium --master-size t2.medium --topology public --networking weave --name dev.training.k8s.local --image ami-007e276c37b5ff2d7 --dns public --dns-zone Z09023161C3R5R5FCLII --state s3://k8s-training-kops-state
Below will explain each attribute in the command.
Create - KOps CLI command used to create the Kubernetes Cluster
--node-count - Identifies the number of nodes to start with when the cluster is created.
--zones - Identifies the number of availability zones to associate the nodes to.
--master-zones - Identifies the number of availability zones to assocate the master nodes to.
--node-size - Identifies the Instance Type for the nodes.
--master-size - Identifies the Instance Type for the masters.
--topology - Identifies weather or not to use a private or public topology.
--networking - Identifies the CNI used for the cluster.
--name - Name given to the cluster. If k8s.local is used then a local DNS is utilize.
--image The AMI used for both the master and the nodes when the servers are provisioned.
--dns-zone - Identfies the hosted zone of the domain to be utilize for the API endpoint of the cluster.
--dns - Identifies the type of endpoints which should be utilize private or public are the options
--state - Identifies the S3 Bucket that the state should go to and be used for.
Step 5. Complete and Apply the Cluster
Next, run the following to complete the creation of the cluster
kops update cluster --name dev.training.k8s.local --yes --state s3://<name of S3 bucket>
Step 6. Wait until servers are provisioned
It will take about 5–10 mins to provision the servers and for the Kubectl to communicate to the API. Run the command below to wait for a validated connection:
kops validate cluster --wait 10m --state s3://<name of s3 bucket>
If all goes well then you will have the Kubernetes Cluster Installed and Ready to Go!