5 Ways to launch Kubernetes in 5 Minutes

Posted on 23 Jul 2019, By Diego Woitasen under DevOps, Infrastructure as Code, Kubernetes

Get Started

This article describes 5 different ways to launch Kubernetes in 5 minutes. These steps are not intended for production usage; they are my own, personal notes on how to create clusters for use in testing and development. I use them when I want to launch K8s for quick, personal testing. I created this article in the hope that these notes will be useful also to others. Again, this is not for the production, staging or development environments, it’s for personal testing and development only.

 

This article assumes that you already have billing properly configured in the cloud providers and a basic knowledge of Kubernetes. It’s neither a tutorial nor an introduction.

 

The steps were tested in Ubuntu 19.04.

 

Kubectl installation

Kubectl is a requirement for all the Kubernetes deployments described here. You have to install it in your local workstation.  


# bash
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin

 

Microk8s

MicroK8s is a lightweight method for launching Kubernetes in a single node for development purposes. It’s very helpful to install it in your local workstation for testing. It’s been demonstrated also to be useful in some CI/CD environments, where it allows you to trigger a pipeline that creates a “single node cluster” in order to test deployment of the platform and application from scratch.MicroK8s is a lightweight method for launching Kubernetes in a single node for development purposes. It’s very helpful to install it in your local workstation for testing. It’s been demonstrated also to be useful in some CI/CD environments, where it allows you to trigger a pipeline that creates a “single node cluster” in order to test deployment of the platform and application from scratch.  


# bash
sudo snap install microk8s --classic

Microk8s is shipped with the microk8s.kubectl command, which should be used to connect to the cluster. Unlike kubectl, microk8s.kubectl  doesn’t require any special configuration.

 

Other useful commands: microk8s.start, microk8s.stop, microk8s.status.  

 

EKS

Elastic Kubernetes Services (EKS) is the managed cluster provided by Amazon. The easiest way to launch a cluster is using the eksctl tool. The following steps describe how to install and use it.  


# bash
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_DEFAULT_REGION="us-east-1"
export AWS_SSH_KEY="diegows"
 
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
curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
sudo mv aws-iam-authenticator /usr/local/bin
 
eksctl create cluster --ssh-public-key ${AWS_SSH_KEY} -n cluster_name

 

Having executed the above, you will have a cluster up and running. The command also writes the kubectl configuration.   Do not forget to delete the cluster when you finish:  


# bash
eksctl delete cluster -n cluster_name

 

GKE

Google Kubernetes Engine (GKE) is the managed service provided by Google. Google provides an official tool to operate with Google Cloud Platform services, gcloud. It ‘s simple to use, but it requires some steps:  


# bash
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt-get update && sudo apt-get install google-cloud-sdk
gcloud init

 

Having executed the above, you will have the tool installed and configured. The following steps are optional. You need to create a project and connect the project with the billing account that should have been configured using the web console.  


# bash
gcloud projects create mylab01
gcloud beta billing accounts list
gcloud beta billing projects link my-project --billing-account 0X0X0X-0X0X0X-0X0X0X # use the ID showed in the previous command.

 

Finally you need to define some defaults and create the cluster.  


#bash
gcloud config set project mylab01
gcloud config set compute/region us-east4
gcloud config set compute/zone us-east4-a
gcloud services enable container.googleapis.com
gcloud container clusters create mycluster

 

The above configures Kubectl. You can run any kubectl command to verify. Do not forget to delete the cluster when you are through:  


# bash
gcloud container clusters delete mycluster

 

Azure Kubernetes Service

Like the name says, AKS is the Kubernetes-managed service from Azure. Microsoft provides the az tool to manage the services in a very convenient way.  


# bash
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
az login
az group create --name myResourceGroup --location eastus
az aks create \
        --resource-group myResourceGroup \
        --name myAKSCluster \
        --node-count 3 \
        --enable-addons monitoring \
        --ssh-key-value
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

 

Having executed the above, you will have the cluster up and running and Kubectl configured for its use.   As usual, do not forget to delete the cluster when you are through:  


# bash
az aks delete \
        --resource-group myResourceGroup \
        --name myAKSCluster

 

Bare Metal or VMs (Kubeadm)

The final method allows you to create a multi-node cluster in virtual machines or bare metal. If you want to do some testing in a non-managed environment, Kubeadm allows creation of a cluster in a few steps.   You must run these steps in all the nodes:  


#bash
apt-get update
apt-get install docker.io
 
RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
 
 
cd /usr/local/bin
ln -sf /usr/local/bin /opt/bin
curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
chmod +x {kubeadm,kubelet,kubectl}
 
CNI_VERSION="v0.7.5"
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
 
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service
mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl enable --now kubelet

 

Now you have to run the next step in the node you selected as master:  


# bash
kubeadm init

 

In the output of the init command, you will see a command that starts with kubeadm join. You must run that command in all the other nodes in order to add them to the cluster.   The last step is to install the networking plugin, because there is no default shipped or installed with Kubeadm:  


# bash
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

 

Conclusion and Disclaimer

The commands described in this article allow easy launch of a cluster when you need to test something for personal purposes. As I said at the beginning, these techniques should not be used in any persistent environment and most certainly not for production. In general, clusters must be launched in private networks respecting a number of considerations not addressed in this article. Nor do I recommend use of these tools for deployments, as Terraform or CloudFormation are better options.

Prepare Your Infrastructure for the Challenges Ahead

Your clients, investors and business partners will notice the difference, from now on, you can progress with confidence.

Get Started