Getting Started with Kubernetes

Neenad Sahasrabuddhe
GDSC GHRCE
Published in
5 min readNov 1, 2020

In my previous article Fundamentals of Kubernetes, I have tried to cover all the basic terminologies which are used in the Kubernetes. This article will take you on the amazing journey of the hands-on tutorial with Kubernetes. Here, we are going to learn how to run Kubernetes locally and on Google Cloud. But before that let’s have a look at prerequisites to run Kubernetes locally.

Prerequisites

Before we go any further, I strongly suggest a machine with at least 8 GB of RAM. Some of the requirements are as per VMs, Operating System, etc. Having 8 GB of RAM allows you to get enough resources for VMs to perform at a better rate. Container or virtual machine manager, such as Docker, Hyper-V, VirtualBox is also needed.

Now, we have to install kubectl and minikube onto our local machine. With the kubectl we can interact with the Kubernetes cluster. Minikube is the entry point for all the beginners who want to run Kubernetes on their local machine.

Minikube

Minikube lets you quickly set up a local Kubernetes cluster. Minikube is great for getting to grips with Kubernetes and learning the concepts of container orchestration at scale.

For Linux, there are 3 ways to install minikube locally. They are

  1. Binary Download
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

2. Debian Package

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb

3. RPM Package

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
sudo rpm -ivh minikube-latest.x86_64.rpm

Now, from the command line with administrator access, run

start minikube

Interacting with the Kubernetes cluster is done via kubectl CLI or Kubernetes dashboard. Install kubectl on your machine with the help of an official installation guide or alternatively minikube can download the appropriate version for you.

minikube kubectl -- get po -A

Minikube has integrated support for Kubernetes Dashboard UI. From the command line run

minikube dashboard

The Dashboard is a web-based Kubernetes user interface. You can use it to:

  • Deploy containerized applications
  • Troubleshoot your containerized application
  • Manage the cluster resources
  • Overview of applications running on your cluster
  • Creating or modifying individual Kubernetes resources (such as Deployments, add-ons, Jobs, etc). For example, you can scale a Deployment, initiate a rolling update, restart a pod, or deploy new applications using a deploy wizard.

The dashboard will look something like this:

Minikube Dashboard

Now, let’s deploy a sample containerized application on minikube. Create minikube deployment with

kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4

It creates by default a single pod on which the containerized application will be deployed. The above command creates a deployment named hello-minikube. It runs based on the provided docker image. Once done, you will receive successfully created output.

By default, the pod is only accessible to its internal IP address. So, to make it accessible to network outside the cluster we need to expose our pod. Expose the pod to public internet using kubectl expose command:

kubectl expose deployment hello-minikube --type=NodePort --port=8080

Here, our deployment is exposed to type NodePort. NodePort sends requests to the IP address of a node which is specified by the cluster. It is exposed on Port 8080 as Port 8080 is typically used for a personally hosted web server when the ISP restricts this type of usage for non-commercial customers. The Port 8080 is used by the proxy address to connect you to the internet services (WWW).

You can view your deployments, pods, and services with:

kubectl get deployments
kubectl get pods
kubectl get services

Tada!!! You have just now deployed your first containerized application using minikube.

Some other commands used in minikube:

minikube pause
minikube stop
minikube delete
minikube addons list
minikube config

GKE [Google Kubernetes Engine]

Google Kubernetes Engine is a management and orchestration that runs with google public cloud services. It is frequently used by software developers to create and testing new enterprise applications. Users can interact with Google Kubernetes Engine using the gcloud command-line interface or the Google Cloud Platform Console.

To get started, you can use a cloud shell or local shell. Cloud Shell is a shell environment for managing resources hosted on Google Cloud. Cloud Shell comes pre-installed with the gcloud command-line tool and kubectl.

If you prefer a local shell, you must have to install gcloud (by installing cloud SDK) and kubectl onto your local machine. Perform the following steps to install cloud SDK and kubectl:

  1. Install the Cloud SDK, which includes the gcloud command-line tool.
  2. After installing the Cloud SDK, install the kubectl command-line tool by running the following command:
gcloud components install kubectl

Else, you can login to the google cloud platform and activate the cloud shell from the top right corner.

First of all, you need to enable the Kubernetes API from API & Services. Create a new project.

Setting up of default Project ID and Compute zone:

gcloud config set project {Project ID}
gcloud config set compute/zone {Compute Zone}

Now we will create a GKE cluster. The cluster consists of 1 Master node and at least 1 Worker node. Nodes are none other than Compute Engine VMs that runs the Kubernetes process. The following command will create a one-node cluster:

gcloud container clusters create {cluster-name} --num-nodes=1

After creating the cluster, we need credentials to interact with the cluster through Kubernetes API.

gcloud container clusters get-credentials cluster-name

Now that you have created our cluster, you can deploy your first containerized applications. For this, you can deploy an example web application hello-app. To create deployment run the following command:

kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0

After deploying the application we need to expose it to the public internet so that users can access our application from their devices.

Use the following command to expose your application:

kubectl expose deployment hello-server --type LoadBalancer \
--port 80 --target-port 8080

You can inspect your application by running the following command:

kubectl get pods
kubectl get service hello-server

View the application from your web browser by using the external IP address with the exposed port:

http://external-ip/

Congratulations, you have just deployed your first application on GKE. You can auto-scale your application as per your need. You can also add worker nodes onto your cluster. But keep in mind that whatever you use is billed as per the rate. So, make sure to terminate/pause services after your work.

--

--

Neenad Sahasrabuddhe
GDSC GHRCE

Developer Student Club (Core Team Member)| Data Science| Machine Learning | Cloud | He/Him