Kubernetes Quick Glance.

Khemnath chauhan
3 min readJan 9, 2021

--

Working with kubernetes -

  • kubectl is kubernetes command line tool.
  • Kubernetes resources can be created using Kubectl command directly

OR, using YAML/JSON file.

  • The advantage of YAML files is it can be track in version control

KUBECTL :-

The configuration related to kubectl are defined in the ~/.kube/config file by default. The kubectl configuration file is in the YAML format, like many other things in Kubernetes. It has two top-level keys that are of immediate relevance: contexts and clusters. The clusters list contains endpoint and certificate information for the different clusters to which the user has access. A context combines one such cluster with the user and namespace values for accessing it. One of these contexts is the currently active one; you can find out which by either looking at the config file, or running kubectl config current-context. We can use the kubectl config view command to show the complete configuration.

NODE:-

Nodes are the individual units of a Kubernetes cluster, it can be VM or an bare metal or cloud instance. In each kubernetes node have a kubelet process that runs on it. This process is responsible for communicating with the Kubernetes master, and running the containers . We can use this command to get lists from nodes by running on master controller node kubectl get nodes.

Clusters are the building blocks of Kubernetes architecture. The clusters are made up of nodes, each of which represents a single compute host (virtual or physical machine).

KUBEPROXY:-

Kubeproxy runs on every node in a cluster. it’s main job is to look for a new services and every time a new service is created, it creates an appropriate rule on each node to forward traffic to those service to backend pods.

It does this using IP table rule. it creates an IP table rule on each node on cluster to forward traffic to IP of service to IP of actual pod.

NAMESPACE:-

A namespace can be considered as a logically isolated virtual cluster inside the Kubernetes cluster which is from each other.
Each workload object added to a Kubernetes cluster must be placed within exactly one namespace. A resource created without a namespace specified is created in the default namespace.
Namespaces make certain things much easier, by helping you avoid name clashes, limit resource allocation, or manage permissions.

By default, a Kubernetes cluster has following namespaces:

default: it has unbounded CPU and memory requests/limits and used by default for creating resources.
kube-public: its a namespace for resources that are publicly readable by all users and is reserved for cluster usage.
kube-system: used by Kubernetes systems/control plane.
Creating namespace in Kubernetes
You can use either the ad-hoc command or the config file to create a namespace.

#Creating namespace with single command
$ kubectl create namespace Test-ns
namespace/dev-ns created

OR, we can use the yaml to create a namespace

apiVersion: v1
kind: Namespace
metadata:
name: Test-ns
labels:
env: prod

To create in different namespace, we must include the --namespace= option in the command. Let’s create a deployment with the same name in the test-namespace namespace

$kubectl create deployment --image nginx demo-nginx --namespace=test-namespace

KUBELET:-

Kubelet is the process that receives and executes orders from the master node. Kubelet is part of every worker nodes.

SERVICE :-

Service is an endpoint that's expose the ports to outside and maps to container Port.

## Create Deployment Script

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
— name: nginx
image: nginx:1.7.9
ports:
— containerPort: 80

COMMANDS TO CREATE K8s OBJECTS :-

#To run the yaml file, we can use any method from below command to create resource.
~ kubectl create -f <File_Name>
OR
~ kubectl apply -f <FIle_Name>

# To view deployment details
~ kubectl get deployment -o wide
OR
~ kubectl get deploy -o wide

# Create service to access the app.

kind: Service // resource type you will create
apiVersion: v1
metadata:
name: my-service // Name of service
spec:
selector:
app: nginx // This is to filter
type: LoadBalancer // There are different types of services based on how loads will be distributed
ports:
— name: my-nginx-port //This is name of port
port: 8080 //Whenever we access with 8080 — it will be map to below port 80.
targetPort: 80

## Create service with below command:
~ kubectl create -f <File_Name>
OR
~ kubectl apply -f <FIle_Name>

## Get deployment details
~ kubectl get service -o wide
OR
~ kubectl get svc -o wide

--

--

Khemnath chauhan
Khemnath chauhan

No responses yet