by Greg Cox
Everyone in any sort of technology related role has heard about Kubernetes, and you may have heard it’s not easy to set up and get working. In this post, I’d like to share a rather interesting project I've come across and show how to quickly and incredibly easily create and use a Kubernetes cluster. With this project and AWS’s Elastic Kubernetes Service you will literally be able to create Kubernetes clusters with 1 command and be able to work with the Kubernetes cluster you created with that one command in a reliable scalable environment as if you are working with a Hyper Scale Cluster because you kind of are.
This project is known as eksctl for Amazon's Elastic Container Service, from weaveworks. From the eksctl project page, developers describe eksctl as “a simple CLI tool for creating clusters on EKS - Amazon’s new managed Kubernetes service for EC2. It is written in Go, and uses CloudFormation.” From my experience using the tool, it is incredibly simple while being extremely powerful. The eksctl.io project page shows how to install on different platforms, but I will walk through how to install on Mac and create clusters and worker nodes with a single command.
Run (if not on a mac here is a link):
curl --silent –location "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv /tmp/eksctl /usr/local/bin
With your awscli already setup with credentials in your ~/.aws/credentials file, you can run this command below, obviously replacing the “<>” with the appropriate values for you:
eksctl create cluster --name=<cluster name> --ssh-public-key=<your public key>.pub --region=us-east-1 --zones=us-east-1a,us-east-1b,us-east-1c,us-east-1e --nodes-min=1 --nodes-max=5 --auto-kubeconfig
After running that command go to your AWS Console – CloudFormation. From here you can view the progress of the Cloudformation that eksctl creates and runs. There are 2 CloudFormation stacks run, one for the EKS Cluster, and the other for the Worker nodes. It will take roughly 10-15 minutes for both of the Stacks to complete, but once complete you will have a fully functioning cluster with worker nodes.
You need a few standard things set up on your machine to interact with AWS (awscli) and Kubernetes (kubectl, see below), but once you have those, you can now create clusters and worker node groups with that single “eksctl create cluster” command above. In the past, this could be described as cumbersome and error-prone, there have been a good number of other projects that tried to make this easier, but many times as Kubernetes versions changed, or the tool changed, the tool would no longer work, and something needed to be updated or fixed to get it working again.
Now even though you have a working cluster and worker nodes, you still need to interact with the cluster to make it do stuff. To do that you need the standard Kubernetes command line interface, kubectl, which you can get following these three steps (if not on a Mac, here is a link):
From here you will just need to update your kubeconfig to allow your kubectl to connect to your Cluster. Eksctl creates the kubeconfig files; you just need to tell kubectl which cluster to start communicating to by running this command with the same <cluster name> defined above:
aws eks update-kubeconfig --name <cluster name>
Now you will be able to run any standard kubectl commands for your new cluster.
This environment or environments like it are great for tinkering and building an ad-hoc cluster to validate as well as learn. For a more production or full lifecycle, I would have all the infrastructure build as part of a Continuous Delivery Pipeline. But for lowering the barrier to entry for people related to using Kubernetes regularly, these are great advancements.
I hope after going thru this post you will feel comfortable creating and starting to use a Kubernetes cluster. So, if you have been hesitant to try out using a Kubernetes cluster, you know you can create and start using a cluster with almost no effort, and it can really be “plug and play” kind of thing.