Skip to main content

Setting Up a Kubernetes Cluster on Ubuntu 19.04



Kubernetes is an open-source container-orchestration tool for automating the application deployment, scaling, and management. It provides a platform that automates Linux container operations. It eliminates many of the manual processes involved in deploying and scaling containerized applications.

You can cluster together groups of hosts running Linux containers, and Kubernetes helps you easily and efficiently manage those clusters. These clusters can span hosts across public, private, or hybrid clouds.

For this very reason, Kubernetes is an ideal platform for hosting cloud-native applications that require rapid scaling. It was originally designed by Google, and is now maintained by the Cloud Native Computing Foundation.

Stpes to Set up a Kubernetes Cluster on Ubuntu 19.04 :

Installing Docker
$ sudo apt install docker.io

Checking Docker Version
$ docker –version

Enable docker
$ sudo systemctl enable docker

The first step is to download and add the key for the Kubernetes install. Add the Kubernetes signing key on both the nodes :

$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add

If curl is not installed on your system, run below command:
$ sudo apt-get install curl

Add Xenial Kubernetes Repository on both the nodes
$ sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

Installing virtualbox on Ubuntu
$ sudo apt-get install -y virtualbox virtualbox-ext-pack

Install kubectl, which you use to interact with the Kubernetes cluster.

$ sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni

If above binaries are not installed together, install them one by one.

Download and install minikube, which runs a single node Kubernetes cluster on your machine.

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

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.28.2/minikube-linux-amd64

or

https://github.com/kubernetes/minikube/releases/tag/v1.3.1

or

$ snap install minikube

Snap path(if installed through snap):

$ sudo chmod +x /snap/bin/minikube

Now start up Minikube and use kubectl to find what version of Kubernetes you’re running on Ubuntu.

$ minikube start

Starting local Kubernetes cluster...

$ kubectl api-versions

Initialize your master

With everything installed, go to the machine that will serve as the Kubernetes master and issue the command:

sudo kubeadm init

Before you join a node, you need to issue the following commands (as a regular user):

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Deploying a pod network

You must deploy a pod network before anything will actually function properly. This is demonstrated using the Flannel pod network. This can be done with two commands (run on the master):

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml

Use the following command in order to view the status of the network:
$ kubectl get pods –all-namespaces

Now when you see the status of the nodes, you will see that the master-node is ready:
$ sudo kubectl get nodes

Joining a node

With everything in place, you are ready to join the node to the master. To do this, go to the node's terminal and issue the command:

sudo kubeadm join --token TOKEN MASTER_IP:6443

Where TOKEN is the token you were presented after initializing the master and MASTER_IP is the IP address of the master.

Once the node has joined, go back to the master and issue the command sudo kubectl get nodes to see the node has successfully joined

Deploying a service

At this point, you are ready to deploy a service on your Kubernetes cluster. To deploy an NGINX service (and expose the service on port 80), run the following commands (from the master):

sudo kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
sudo kubectl expose deployment nginx-app --port=80 --name=nginx-http

If you go to your node and issue the command sudo docker ps -a, you should see the service listed.

Now Kubernetes cluster is ready
You now have a basic Kubernetes cluster, consisting of a master and a single node. Of course you can scale your cluster by installing and adding more nodes. With these instructions, Kubernetes cluster should be up and running !!

Pankaj

Comments

Popular posts from this blog

Spring Cloud vs AWS/GCP/Azure Cloud - In the realm of Distributed Systems Development

The Scalability and High-Availability have become defacto standards for Distributed Systems development. The traditional applications are moving fast from the On-Prem model to the Cloud. With such requirements, it has become imperative to build an application with robust APIs or Cloud Services having fault-tolerant and graceful fallback functionality. Spring framework has emerged as a full-fledged, robust, feature-rich and mature ecosystem over time. It has been equipped with lots of features for rapid development. Spring Boot dominates the Cloud Native Software development. With the introduction of Spring Boot, the Microservices development has catapulted to a whole new level as it brings all sorts of dependencies in one place. Spring Cloud is an umbrella project under the Spring ecosystem. It consists of many sub-projects to build a robust distributed system. It was primarily developed by Netflix and open-sourced as part of Netflix OSS to create resilient, fault-tolerant and s...

Program "make" not found in PATH in Eclipse

In order to fix the error "Program "make" not found in PATH in Eclipse", follow below steps: Right Click on the Project -> Properties -> C/C++ Build ->Environment Check PATH, if it has C:\cygwin64\bin in the path or not. Sometimes path set in Environment variables is not reflected in the Eclipse, so you have to edit it here. Build/Restart the eclipse again, you should be able to get rid of the error. If it still persists, do right click on the Project -> Properties -> C/C++ Build ->Tool Chain Editor Current toolchain: ->Cygwin GCC Current builder: -> GNU Make Builder It should work now !! Pankaj

Create the Vsix package from a class library

A project that was created as a class library that contains numerous controls that can be used in windows forms applications. In order to create an installation package (*.vsix) that will embed these controls into the visual studio toolbox window. The controls are visible in the toolbox window when being in the solution that has this project within itself. I have created a vsix project and referenced the component project's dll as a Microsoft.VisualStudio.Assembly asset. The VS2017 build process creates the vsix file that I need. When I run it on a system with a fresh VS installation, it goes through the install process with no problems, but the components don't show up in the toolbox. When I try to register the asset as a Microsoft.VisualStudio.ToolboxControl, I get the error 'The target "PkgdefProjectOutputGroup" does not exist in the project.  To reslolve the below error which comes while adding reference of DLL application to VSIX project for Visual ...