Deploying a Kubernetes Cluster by using kops

kops is an open source tool that allows you to orchestrate the creation of a Kubernetes Cluster on AWS. Let’s deploy a new Cluster by using it. We will be using the EC2 Instance that was created for the Docker portion of this Workshop.

  • Access your IAM Console and create a new Role called KOPS-Administrator

  • Attach the following policies to it:

AmazonEC2FullAccess
AmazonRoute53FullAccess
AmazonS3FullAccess
IAMFullAccess
AmazonVPCFullAccess
  • Using your EC2 Console, associate the IAM Role with your EC2 Instance

  • Access the Instance via SSH

  • Let’s deploy the necessary tools

  • Start by installing KOPS itself

curl -Lo kops 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
sudo install kops /usr/local/bin
  • Now install the kubectl tooling
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
sudo install kubectl /usr/local/bin
  • If you are not using Amazon Linux, install the AWS CLI if it is not already present. You might have to install pip using your local package manager beforehand.
pip install awscli
  • Create the Cluster State storage S3 Bucket. Please change the Bucket name as required to avoid duplicates and the associated Region to the Region your EC2 Instance is running on
aws s3api create-bucket \
    --bucket my-kops-cluster-state-for-today \
    --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1
  • Let’s export some variables to start creating our Cluster. Change your S3 Bucket name to the used above and also change the Cluster name if so desired. Please keep the “.k8s.local” suffix associated with the Cluster name in order to create a gossip-based cluster. This avoids the need of setting up a Cluster supporting DNS infrastructure
export NAME=kops.k8s.local
export KOPS_STATE_STORE=s3://my-kops-cluster-state-for-today
  • List the available Availability Zones in the Region your are running the EC2 Instance in
aws ec2 describe-availability-zones --region eu-west-1
  • Generate a RSA Key Pair to use with your Cluster
ssh-keygen
  • Press enter three times to accept insecure defaults

  • Generate your Cluster configuration and leverage at least two Availability Zones for it

kops create cluster \
    --zones eu-west-1a,eu-west-1b,eu-west-1c \
    ${NAME}
  • Take a look at the Cluster configuration file that was created
kops edit cluster ${NAME}
  • Acccept the Defaults by exiting your editor without making any changes and let’s move forward with the actual Cluster creation
kops update cluster ${NAME} --yes
  • The process will take about 10 minutes to conclude. When it is finished, you can validate the state of the Cluster by using
kops validate cluster
  • And the standard kubectl commands should also execute properly. Try to list the nodes in your Cluster with
kubectl get nodes
  • And take a look at all the System Components by using
kubectl -n kube-system get po