Feb 22, 2019 · ⏱ 2 minutes

Provisioning Kubernetes clusters πŸ€

Welcome to the first post of a series covering the basics of deploying and using Kubernetes! For the first post, we'll look into provisioning a new cluster to use for the following guides. A running cluster is an essential part of your infrastructure, every application will be eventually deployed on one of those. Let's start by creating K8s clusters using either Google Cloud or DigitalOcean. For local development, you can either use the packaged Kubernetes in Docker for Windows/Mac or tools like minikube and kind.

Google Cloud

Start off by accessing your Google Cloud Console and heading over to Kubernetes Engine > Clusters as shown in the image below.

screen

screen

You can now configure the basic details, choose from preconfigured cluster templates, and play around with the possible options to configure your cluster. After hitting Create, your cluster will be provisioned automatically, you can lean back and relax while Google Cloud is creating everything for you!

screen

screen

After your cluster was created, you can open the cluster page and click Connect, which will open a dialog and display a command you can paste into your terminal to fetch your cluster configuration and automatically point kubectl at it.

πŸ”§
This requires the gcloud CLI to be set up correctly to pull in your Kubeconfig file.

screen

After running the aforementioned command, the output should roughly look like the following. To validate that everything is running smoothly, you can execute kubectl get all, which should return a single object row containing service/kubernetes.

$ gcloud beta container clusters get-credentials \
demo \
--region [CLUSTER REGION] \
--project [YOUR PROJECT]
Fetching cluster endpoint and auth data.
kubeconfig entry generated for demo.
$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.27.240.1 <none> 443/TCP 1m

If everything mentioned above was printed in the terminal, you've successfully created your first cluster! Rejoice!

DigitalOcean

In your DigitalOcean dashboard, simply navigate to Clusters to start creating your first cluster.

screen

You can now configure your cluster and start the provisioning process by clicking on Create Cluster.

screen

After hitting the button, you will be redirected to an overview screen displaying the creation status of your new cluster. Deploying will take some time, but we can already continue.

screen

To interact with your cluster using kubectl, we have to download the kubeconfig file first, which we can do by hitting Download Config, an action shown in the Actions button dropdown.

screen

If you open your downloaded file, you will see your cluster configuration which should look similar to this:

apiVersion: v1
clusters:
- cluster:
certificate-authority-data: [AUTHORITY DATA]
server: https://[UUID].k8s.ondigitalocean.com
name: do-fra1-demo
contexts:
- context:
cluster: do-fra1-demo
user: do-fra1-demo-admin
name: do-fra1-demo
current-context: do-fra1-demo
kind: Config
preferences: {}
users:
- name: do-fra1-demo-admin
user:
client-certificate-data: [CERTIFICATE DATA]
client-key-data: [KEY DATA]

If you haven't added a cluster to your kubectl config before, you can simply copy the file you've downloaded and move it over to $HOME/.kube/config. Otherwise, simply append the new cluster information like clusters -> cluster, contexts -> context, users -> do-fra1-demo-admin to your existing configuration. If you change your current-context to match the added context name, you should be able to execute the following to get information about your newly created cluster:

$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.245.0.1 <none> 443/TCP 1m34s

And that's about it for DigitalOcean's managed Kubernetes, you're all set to deploy your applications!