Getting Started with Kubernetes
Tags: tutorial, microservices, devops, kubernetes
Published: 2021-10-05 16:34:25

### Orchestration

Container orchestration is all about managing the life cycles of containers, especially in large, dynamic environments.

Container Orchestration can be used to perform a lot of tasks, some of them includes:

* Provisioning and deployment of containers
* Scaling up or removing containers to spread application load evenly
* Movement of containers from one host to another if there is a shortage of resources
* Load balancing of service discovery between containers
* Health monitoring of containers and hosts


There are many container orchestration solutions which are available, some of the popular ones include:

* Docker Swarm
* Kubernetes
* Apache Mesos
* Elastic Container  Service (AWS ECS)

There are also various container orchestration platforms available like EKS.

###Introduction to Kubernetes

Kubernetes (K8s) is and open-Source container Orchestration engine developed by Google.

It is originally designed by Google, and is now maintained by the Cloud Native Computing Foundation.

![K8s Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huz8ql9dz9cldalqxjf4.png)
 
### Installation Options for K8s

####Installation Aspects

Things to configure while working with Kubernetes.

| Sr No | Things to Install | Description |
|:-----|:--------:|--------:|
| 1 | kubectl | CLI for running user commands against cluster |
| 2 | Kubernetes Master | Kubernetes Cluster by itself |
|3 | Worker Node Agents | Kubernetes Node Agent |

#### Understanding Installation Methods

There are multiple ways to get started with fully functional k8s environment.

* Use the Managed K8s Service
* Use Minikube
* Install & Configure K8s Manually (Hard Way)

#### Install & Configure K8s Manually(Hard Way)

In this approach you have to install all the components ok K8s Individually

![Hard-way](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7jr4fb9obi8ege2xwiz.png)
 
#### Components to be Configured - Managed Service

You have to just download kubectl and that's it. As rest all the things are taken care by Managed Service. Download CLI and just need to connect with K8s master.

[Environment Setup](https://dev.to/dporwal/digitalocean-managed-kubernetes-service-54kp)


#### Components to be Configured - Minikube

Take care of K8s master also the worker node, then we need to configure the kubectl.
It has disadvantage that it provision single node cluster.

---

### Kubernetes API Primitives

Depending on the Operations there are various APIs availble.

eg: /apis , /metrics , 
/api/v1/pods or /api/v1/nodes or /api/v1/services

to explore APIs, run below command and goto: ***localhost:8080***

```shell
kubectl proxy --port 8080
```
---
### Kubernetes POD
A pod is a collection of containers and its storage inside a node of a Kubernetes cluster. It is possible to create a pod with multiple containers inside it. For example, keeping a database container and data container in the same pod.

There are two types of Pods −

* Single container pod
* Multi container pod

#### Single container pod

```shell
$ kubectl run <name of pod> --image=<name of the image from registry>
```

eg:

```shell
kubectl run tomcat --image = tomcat:8.0
```

#### Multi container pod

Multi container pods are created using ***yaml mail*** with the definition of the containers.

```yml
apiVersion: v1
kind: Pod
metadata:
   name: Tomcat
spec:
   containers:
   - name: Tomcat
    image: tomcat: 8.0
    ports:
containerPort: 7500
   imagePullPolicy: Always
   -name: Database
   Image: mongoDB
   Ports:
containerPort: 7501
   imagePullPolicy: Always
```
For more deep on Pods goto: [Kubernetes Pods](https://dev.to/dporwal/kubernetes-pods-3mk5)

---
### Kubernetes Objects

Kubernetes Objects are basically a record of intent that you pass on to the Kubernetes Cluster.
Once you create the object, the kubernetes system will constantly work to ensure that object exists.

### Commands and Arguments in K8s

In Docker main difference between ***ENTRYPOINT*** and ***CMD*** is that Override the main command in Dockerfile with the command passing as arguments.

Whereas, in Kubernetes we can override both the ***ENTRYPOINT*** and ***CMD*** with command and arguments field.

#### Dockerfile VS K8s Menifest Perspective

| Docker Field Name | K8s field Name | Description |
|:---|:------:|-----:|
|ENTRYPOINT|command|Command that will run by the container|
|CMD| args | Argument passed to the container|

Let me show you how ***command*** and ***args*** work on kubernetes.


![commands with description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8iu3h278luwsqn5lefu.gif)
 
Reference: [Define a Command and Arguments for a Container](https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/)




References:
[Official Documentation](https://kubernetes.io/docs/home/)
[Udemy Course](https://www.udemy.com/course/certified-kubernetes-administrator/)

Credit:
[Zeal Vora](https://in.linkedin.com/in/zealvora)

***Specific Kubernetes setups, coming soon!!!!!!!!!!!!!!!!***