Kubernetes tutorial – Create simple cluster & Deploy app

In the last post, we have looked at the Introduction & key concepts of the Kubernetes platform. Now in this post, we are going to create a 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 clusters.

Step #1. Minikube installation

Download the latest release with the command. This is for Linux, if you’re using another 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/ 
Image – Minikube installation

Check the download by running the minikube version command:

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.

Usage:
 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 of kubectl with the following 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
Image – kubectl Installation

Make the kubectl binary executable.

chmod +x ./kubectl

Move the binary into 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
zsh)

Other Commands:
  api-versions   Print the supported API versions on the server, in the form of
"group/version"
  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
commands).

Step #3.Create local cluster

Start the cluster, by running the minikube start command:

Image – Starting local cluster

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:

Image – kubectl version command

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:

Image – kubectl cluster-info

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

Image – kubectl get nodes command

Step #4 : Deploy Nginx 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 the Nginx image. If we want to run the app on a specific port so we could add the --port parameter as well.

Image – Kubernets deployment created

Congrats! We have just deployed the 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 Nginx application to run on that node.
  3. Configured the cluster to reschedule the instance on a new Node when needed.
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, the Node is 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 Nginx app as well as a different container that feeds the data to be published by the Nginx 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:

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 Nginx app outside of the cluster

To expose the app to the outside world, use 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 Nginx landing page, you can check the same at 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 the above command.

A Service in Kubernetes is an abstraction that 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 allows 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) are handled by Kubernetes Services.

Step #6: Delete app

To delete the app, run the 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 :

Summary
Article Name
Kubernetes tutorial - Create simple cluster & Deploy app
Description
In this post, we are going to create a new Kubernetes cluster using Minikube.
Author
Publisher Name
Upnxtblog
Publisher Logo
Karthik

Allo! My name is Karthik,experienced IT professional.Upnxtblog covers key technology trends that impacts technology industry.This includes Cloud computing,Blockchain,Machine learning & AI,Best mobile apps, Best tools/open source libs etc.,I hope you would love it and you can be sure that each post is fantastic and will be worth your time.

Share
Published by
Karthik

Recent Posts

Finding the Right Time to Build Your Software Instead of Buy

There are few things as valuable to a business as well-designed software. Organizations today rely…

6 days ago

Innovators in Crypto: Prominent AI-Powered Coins

The cryptocurrency industry is being reshaped by the fusion of blockchain technology and artificial intelligence…

3 weeks ago

Top AI Design Tools Every Graphic Designer Should Use in 2024

Introduction Artificial Intelligence (AI) has also found its relevance in graphic design and is quickly…

2 months ago

Transforming Industries: The Integration of AI and Blockchain

Imagine a world where the brilliance of Artificial Intelligence (AI) meets the unbreakable security of…

2 months ago

How Can I Use Automation to Streamline My Digital Marketing Efforts?

In today’s fast-paced digital landscape, automation is not just a luxury but a necessity for…

2 months ago

Top 5 AI Technologies Transforming the Casino Gaming Landscape in 2025

The world of casino gaming has leveraged the emerging technology advancements to create immersive and…

3 months ago

This website uses cookies.