image1 image2 image3

NISHI'S TECH BLOG|HELLO I'M NISHADI KIRIELLE|WELCOME TO MY TECH BLOG

Getting Started with Kubernetes





This blog post is intended to walk you through a guide on how to get started with Kuberenetes by creating a single cluster with one or more nodes on a single physical machine.
Running Kubernetes with Vagrant is a better way to be familiar with Kubernetes. Kubernetes getting started guide provides a way to install Kubernetes with Fedora.

As an alternative, this post will guide you through a Kubernetes vagrant setup with core-os. Initially, you have to install vagrant and virtual box to proceed with.

As the first step, clone this Kubernetes core-os vagrant setup. 


$git clone https://github.com/pires/kubernetes-vagrant-coreos-cluster.git

This vagrant setup sets some default values to the properties like number of nodes, memory of master, memory of nodes, enabling of Kubernetes UI and etc. If you need to set custom values for these properties, you can set them by setting the environment variables as below;


$export NODES=1
$export USE_KUBE_UI=true

Now, that all are ready to run the Kuberenetes cluster. The following command will create and configure the guest machines according to the vagrant file specification. In order to run this command you need to go inside the cloned folder.


$vagrant up


 After successfully completing the above command, now the Kubernetes cluster is ready. You can verify the cluster information by the running the following command which displays addresses of master and services.


$kubectl cluster-info

In trying to run kubectl cluster info command, there's a possibility in getting the following error due to the incorrect master IP.




Thus to avoid that error we need to set the master IP as an environment variable. As per the above vagrant setup, the IP of the Kubernetes cluster is as follows;



$export KUBERNETES_MASTER=172.17.8.101:8080

With the proper installation of Kuberenetes, it would provide cluster information to the kubectl cluster info command as follows;





What is kubectl?

Kubectl is the command line interface that helps the user to run command against the Kubernetes cluster.

Creating a pod


$kubectl create -f FILE

A pod can be created with create command and the properties of the pod definition can be defined via a YAML or JSON formatted configuration file. The direct use of this command to create a pod does not create a replication controller which watches over the failures.

Viewing a pod

$kubectl get pod NAME
                 displays the basic information on the specified pod



$kubectl describe pod NAME
                displays the more information on the specified pod



$kubectl get pods
                lists all the pods that are running on the cluster

Deleting a pod

$kubectl delete pod NAME
                 deletes the pod and returns the name of the pod that is deleted


Creating a replication controller

$kubectl create -f FILE
                 a replication controller is can be created in create command with the configuration in YAML or JSON formatted file. The 'kind' field in the configuration should state that this a replication controller in order to identify the configuration as a replication controller.

Viewing a replication controller

$kubectl get rc
            lists all the replication controllers that are running on the cluster
  
$kubectl describe rc NAME
            displays more information on the specified replication controller

Deleting a replication controller

$kubectl delete rc NAME
                deletes the specified replicated controller including all the pods that are associated with it




Deploying a Sample Tomcat Application on Kubernetes

 

In order to deploy a sample tomcat application on Kubernetes, we can use the provided sample examples in Kubernetes code base.
What you have to do is clone the Kubernetes code base, as follows;
$git clone https://github.com/kubernetes/kubernetes.git
         The YAML configuration file for the tomcat sample application is provided and you can create the pod with the following command
$kubectl create -f <kubernetes home>/examples/javaweb-tomcat-sidecar/javaweb-2.yaml

We can view the status of the pod by running 

  
$kubectl get pods

Once the pod is in the running status, we can access the sample deployed application through   
http://172.17.8.102:8001/sample/index.html
as this port is defined in the configuration YAML file. 


References : https://cloud.google.com/container-engine/docs/


 

Share this: