What are the topmost NodeJS practices for developers?.
Node.js, a platform based on Chrome's JavaScript motor assists with growing quick, adaptable system applications. It utilizes an occasion driven,...
With more applications moving to the cloud, it has become very important for engineers to have a safe, reliable infrastructure on the cloud. That is why the concept of DevOps came into being. Moving away from the hassle of DevOps solutions, some of today’s most popular emerging technologies in cloud solutions is pairing containers with cluster management software. Some of the most used solutions are Apache Mesos, Docker Swarm and the most popular Kubernetes.
Kubernetes is one of the most popular open source container management system for technologies like Docker and rkt. It offers unique features which lets you create portable and scalable app deployment which can be managed, scheduled and maintained easily.
Lets get familiar with the various components used by Kubernetes
At the end of this post, you should be able to create a cluster and deploy a simple application across the cluster consisting of multiple nodes.
The Kubernetes Getting Started guide helps you through the process of setting up a cluster on multiple platforms like Google Cloud Engine or the Amazon and Azure alternatives. This is a great way to get started instantly. We will set up Kubernetes locally using Minikube VM.
kubectl can be installed in different way depending on your OS and the installation method that you use. These can be found here
To download the latest stable version of kubectl, use the below curl request
curl -Lo https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl > kubectl
Once the installation completes, you need to ensure you change the necessary permissions to allow kubectl to execute and then move the binary into your PATH.
chmod +x kubectl
sudo mv kubectl /usr/local/bin
With these values set, you can execute a kubectl command. Now, in order for kubectl to communicate with a cluster, it needs a kubeconfig file which is automatically created when you set up a cluster. By default, config files are located at ~/.kube/config
The config file defines the Kubernetes cluster’s configuration. When the cluster installation script is executed, it creates the .kube directory in the user’s home folder which has a file called config. This file is what holds all the information about the cluster.
The config file holds two main pieces of information
To install minikube, run the following curls
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.8.0/minikube-linux-amd64
chmod +x minikube
sudo mv minikube /usr/local/bin/
This will download and install minikube, change its permissions to be executable and move the installation to the correct location.
Now that you have minikube installed, you can start the cluster using the following command
minikube start
This will start a single-node cluster. You can now use kubectl along with minikube commands to control and administer the cluster.
If you run the command kubectl get nodes, it will list the nodes (just one in this case), their status and time they have been active.
You can launch the Kubernetes dashboard using minikube dashboard - this will open the dashboard on a browser.
So, you now have minikube and kubectl up and running and have started your first cluster. The next step is to deploy an application on Kubernetes.
To run your app on Kubernetes, we will use the kubectl run command. The command requires you to provide the deployment name and app image location. For images hosted outside Docker hub, you need to use full repo URLs.
If you wish to run the app on a specific port, add the --port parameter. So the command would come to be
kubectl run my-sample --image=sample_icon --port=2345
This process did a few steps for you under the hood
To confirm that the deployment was successful, you can use kubectl get deployments command
Pods running inside Kubernetes run on a private, isolated network which are visible to other pods and services in the same cluster, but only within the same network. This is because the port defined for the app is not exposed outside the cluster. This is where we introduce services.
To make our application available outside the cluster, the deployment needs to be exposed as a service. The kubectl command allows you to “expose” the deployment
kubectl expose deployment my-sample --type="NodePort"
The NodePort service type sets all nodes to listen to a specific port.
You can now use kubectl describe service command to see the port at which the service is exposed. Once you know the NodePort, you can use curl to connect to the node.
curl -vk http://<your url here>:<NodePort exposed>
In this post, we learned how to deploy a Kubernetes cluster on a VM, how to deploy an application and make it available to external systems. But this is just the tip of Kubernetes. If you would like to know more about specific topics, do let us know in the comments or get in touch.
Node.js, a platform based on Chrome's JavaScript motor assists with growing quick, adaptable system applications. It utilizes an occasion driven,...
What could be the ultimate goal for each business person? Increase the number of sales!!! In any case, driving traffic and offering amazing...