Kubernetes tutorial – Create simple cluster & Deploy app

In the last post, we have looked at the Introduction & key concepts of Kubernetes platform.Now in this post,we are going to create new Kubernetes cluster using Minikube. Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node. Minikube is available for Linux, macOS, and Windows systems.

The Minikube CLI provides basic bootstrapping operations for working with your cluster, including start, stop, status, and delete.Also we are going to use kubectl utility to deploy and manage applications on Kubernetes. Also,you can inspect cluster resources; create, delete, and update components; and look at new cluster.

Here are the detailed steps :

Step #1. Minikube installation

Download the latest release with the command.This is for linux,if you’re using other OS,please refer above link.

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ 
Minikube installation
Image – Minikube installation

Check the download by running the minikube version command:

Check Minikube version
Image – Check Minikube version





To check what are the available commands,try minikube from the terminal

$ minikube
Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized
 for development workflows.

 minikube [command]

Available Commands:
start Starts a local kubernetes cluster.
stop Stops a running local kubernetes cluster.
version Print the version of minikube.

Step #2.kubectl installation.

Download the latest release with the command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
kubectl Installation
Image – kubectl Installation









Make the kubectl binary executable.

chmod +x ./kubectl

Move the binary in to your PATH.

sudo mv ./kubectl /usr/local/bin/kubectl

To check what are the available kubectl commands,run kubectl from the terminal

$ kubectl
kubectl controls the Kubernetes cluster manager.

Find more information at https://github.com/kubernetes/kubernetes.

Basic Commands (Beginner):
  create         Create a resource from a file or from stdin.
  expose         Take a replication controller, service, deployment or pod and
expose it as a new Kubernetes Service
  run            Run a particular image on the cluster
  set            Set specific features on objects
  run-container  Run a particular image on the cluster. This command is
deprecated, use "run" instead

Basic Commands (Intermediate):
  get            Display one or many resources
  explain        Documentation of resources
  edit           Edit a resource on the server
  delete         Delete resources by filenames, stdin, resources and names, or
by resources and label selector

Deploy Commands:
  rollout        Manage the rollout of a resource
  rolling-update Perform a rolling update of the given ReplicationController
  scale          Set a new size for a Deployment, ReplicaSet, Replication
Controller, or Job
  autoscale      Auto-scale a Deployment, ReplicaSet, or ReplicationController

Cluster Management Commands:
  certificate    Modify certificate resources.
  cluster-info   Display cluster info
  top            Display Resource (CPU/Memory/Storage) usage.
  cordon         Mark node as unschedulable
  uncordon       Mark node as schedulable
  drain          Drain node in preparation for maintenance
  taint          Update the taints on one or more nodes

Troubleshooting and Debugging Commands:
  describe       Show details of a specific resource or group of resources
  logs           Print the logs for a container in a pod
  attach         Attach to a running container
  exec           Execute a command in a container
  port-forward   Forward one or more local ports to a pod
  proxy          Run a proxy to the Kubernetes API server
  cp             Copy files and directories to and from containers.
  auth           Inspect authorization

Advanced Commands:
  apply          Apply a configuration to a resource by filename or stdin
  patch          Update field(s) of a resource using strategic merge patch
  replace        Replace a resource by filename or stdin
  convert        Convert config files between different API versions

Settings Commands:
  label          Update the labels on a resource
  annotate       Update the annotations on a resource
  completion     Output shell completion code for the specified shell (bash or

Other Commands:
  api-versions   Print the supported API versions on the server, in the form of
  config         Modify kubeconfig files
  help           Help about any command
  plugin         Runs a command-line plugin
  version        Print the client and server version information

Use "kubectl  --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all

Step #3.Create local cluster

Start the cluster, by running the minikube start command:

Starting local cluster
Image – Starting local cluster


Coursera CS



Once the cluster is started,we have a running Kubernetes local cluster now.Minikube has started a virtual machine for you, and a Kubernetes cluster is now running in that VM.

To interact with Kubernetes we’ll use the command line interface, kubectl. To check if kubectl is installed you can run the kubectl version command:

kubectl version command
Image – kubectl version command







Magoosh.com GRE 468x60

As you can see kubectl is configured and we can see that both the version of the client and as well as the server. The client version is the kubectl version; the server version is the Kubernetes version installed on the master. You can also see details about the build.

To view the cluster details, run kubectl cluster-info:

kubectl cluster-info command
Image – kubectl cluster-info










To view the nodes in the cluster, run the kubectl get nodes command:

kubectl get nodes command
Image – kubectl get nodes command





Step #4 : Deploy ngnix app to one of the nodes of the cluster

Let’s run our first app on Kubernetes with the kubectl run command. The run command creates a new deployment. We need to provide the deployment name and app image location (include the full repository url for images hosted outside Docker hub) ,currently I have provided ngnix image. If we want to run the app on a specific port so we could add the –port parameter as well.

Kubernets deployment created
Image – Kubernets deployment created




Congrats! We have just deployed first application by creating a deployment. Following is what the command has done for us:

  1. Searched for a suitable node where an instance of the application could be run (we have only 1 available node)
  2. Scheduled the ngnix application to run on that Node
  3. Configured the cluster to reschedule the instance on a new Node when needed
kubectl get pods command
Image – kubectl get pods




Once the application instances are created, a Kubernetes Deployment Controller continuously monitors those instances. If the Node hosting an instance goes down or is deleted, the Deployment controller replaces it.

A Pod is a Kubernetes abstraction that represents a group of one or more application containers (such as Docker or rkt), and some shared resources for those containers. Those resources include:

  • Shared storage, as Volumes
  • Networking, as a unique cluster IP address
  • Information about how to run each container, such as the container image version or specific ports to use

A Pod always runs on a Node. As discussed earlier,Node is a nothing but a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the Master. A Node can have multiple pods, and the Kubernetes master automatically handles scheduling the pods across the Nodes in the cluster. The Master’s automatic scheduling takes into account the available resources on each Node.

Every Kubernetes Node runs at least:

  • Kubelet – responsible for communication between the Kubernetes Master and the Nodes
  • Container runtime (like Docker, rkt)

For example, a Pod might include both the container with your ngnix app as well as a different container that feeds the data to be published by the ngnix webserver. The containers in a Pod share an IP Address and port space, are always co-located and co-scheduled, and run in a shared context on the same Node.

To list your deployments, use the get deployments command:

kubectl get deployments command
Image – kubectl get deployments command




Here we can see that there is 1 deployment running a single instance of the app.

Some of the useful kubectl commands are below.

  • kubectl getlist resources
  • kubectl describeshow detailed information about a resource
  • kubectl logsprint the logs from a container in a pod
  • kubectl execexecute a command on a container in a pod

Step #5 : Expose ngnix app outside of the cluster

To expose the app on to the outside world, use expose deployment command:

kubectl expose deployment command
Image – kubectl expose deployment command




Pods that are running inside Kubernetes are running on a private, isolated network. By default they are visible from other pods and services within the same kubernetes cluster, but not outside that network. On some platforms (for example Google Compute Engine) the kubectl command can integrate with your cloud provider to add a public IP address for the pods, to do this run:

To see the ngnix landing page,you can check at the http://localhost:80

Also note in order to access your nginx landing page, you also have to make sure that traffic from external IPs is allowed. Do this by opening a firewall to allow traffic on port 80.

kubectl get services

This should print the service that has been created, and map an external IP address to the service. Where to find this external IP address will depend on the environment you run in. For instance, for Google Compute Engine the external IP address is listed as part of the newly created service and can be retrieved by running above command.

A Service in Kubernetes is an abstraction which defines a logical set of Pods and a policy by which to access them. Services enable a loose coupling between dependent Pods.A Service routes traffic across a set of Pods. Services are the abstraction that allow pods to die and replicate in Kubernetes without impacting your application. Discovery and routing among dependent Pods (such as the frontend and backend components in an application) is handled by Kubernetes Services.

Step #6 : Delete app

To delete the app,run delete deployment command

kubectl delete deployment my-nginx

In the next tutorial,we will learn how to scale & perform updates to the app on the cluster.

Like this post? Don’t forget to share it!

Additional Resources :

Leave a Reply

Your email address will not be published. Required fields are marked *