0% found this document useful (0 votes)
5 views

intro_kubernetes (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

intro_kubernetes (1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

What is Kubernetes?

Kubernetes is a portable, extensible, open-source platform for managing


containerized workloads and services, that facilitates both declarative
configuration and automation. It has a large, rapidly growing ecosystem.
Kubernetes services, support, and tools are widely available.

The name Kubernetes originates from Greek, meaning helmsman or pilot.


K8s as an abbreviation results from counting the eight letters between the
"K" and the "s". Google open-sourced the Kubernetes project in 2014.
Kubernetes combines over 15 years of Google's experience running
production workloads at scale with best-of-breed ideas and practices from
the community
Why Kubernetes is so useful
Why you need Kubernetes and what
it can do
• Containers are a good way to bundle and run your applications. In a
production environment, you need to manage the containers that run
the applications and ensure that there is no downtime. For example,
if a container goes down, another container needs to start. Wouldn't
it be easier if this behavior was handled by a system?
• That's how Kubernetes comes to the rescue! Kubernetes provides you
with a framework to run distributed systems resiliently. It takes care
of scaling and failover for your application, provides deployment
patterns, and more. For example, Kubernetes can easily manage a
canary deployment for your system.
Kubernetes provides you with:
• Service discovery and load balancing Kubernetes can expose a container using the DNS name or using their
own IP address. If traffic to a container is high, Kubernetes is able to load balance and distribute the network
traffic so that the deployment is stable.
• Storage orchestration Kubernetes allows you to automatically mount a storage system of your choice, such
as local storages, public cloud providers, and more.
• Automated rollouts and rollbacks You can describe the desired state for your deployed containers using
Kubernetes, and it can change the actual state to the desired state at a controlled rate. For example, you can
automate Kubernetes to create new containers for your deployment, remove existing containers and adopt
all their resources to the new container.
• Automatic bin packing You provide Kubernetes with a cluster of nodes that it can use to run containerized
tasks. You tell Kubernetes how much CPU and memory (RAM) each container needs. Kubernetes can fit
containers onto your nodes to make the best use of your resources.
• Self-healing Kubernetes restarts containers that fail, replaces containers, kills containers that don't respond
to your user-defined health check, and doesn't advertise them to clients until they are ready to serve.
• Secret and configuration management Kubernetes lets you store and manage sensitive information, such as
passwords, OAuth tokens, and SSH keys. You can deploy and update secrets and application configuration
without rebuilding your container images, and without exposing secrets in your stack configuration.
Master Node Components

1. API Server 2. Controller Manager 3. ETCD 4. Scheduler


kube-apiserver
• The API server is a component of the Kubernetes control plane that
exposes the Kubernetes API. The API server is the front end for the
Kubernetes control plane.
• The main implementation of a Kubernetes API server is
kube-apiserver. kube-apiserver is designed to scale horizontally—that
is, it scales by deploying more instances. You can run several instances
of kube-apiserver and balance traffic between those instance
etcd
• Consistent and highly-available key value store used as Kubernetes'
backing store for all cluster data.
kube-scheduler
• Control plane component that watches for newly created Pods with no assigned node, and selects a
node for them to run on.
• Factors taken into account for scheduling decisions include: individual and collective resource
requirements, hardware/software/policy constraints, affinity and anti-affinity specifications, data locality,
inter-workload interference, and deadlines.
kube-controller-manager
• Control plane component that runs controller processes.
• Logically, each controller is a separate process, but to reduce complexity, they are all compiled into a
single binary and run in a single process.
Some types of these controllers are:
• Node controller: Responsible for noticing and responding when nodes go down.
• Job controller: Watches for Job objects that represent one-off tasks, then creates Pods to run those tasks
to completion.
• Endpoints controller: Populates the Endpoints object (that is, joins Services & Pods).
• Service Account & Token controllers: Create default accounts and API access tokens for new namespaces.
Master Node
API Server
Scheduler
Controller Manager
etcd
Node Components
Node components run on every node, maintaining running pods and providing the Kubernetes runtime
environment.
kubelet
• An agent that runs on each node in the cluster. It makes sure that containers are running in a Pod.
• The kubelet takes a set of PodSpecs that are provided through various mechanisms and ensures that the
containers described in those PodSpecs are running and healthy. The kubelet doesn't manage containers which
were not created by Kubernetes.
kube-proxy
• kube-proxy is a network proxy that runs on each node in your cluster, implementing part of the Kubernetes
Service concept.
• kube-proxy maintains network rules on nodes. These network rules allow network communication to your Pods
from network sessions inside or outside of your cluster.
• kube-proxy uses the operating system packet filtering layer if there is one and it's available. Otherwise, kube-
proxy forwards the traffic itself.
Container runtime
• The container runtime is the software that is responsible for running containers.
• Kubernetes supports several container runtimes: Docker, containerd, CRI-O, and any implementation of the
Kubernetes CRI (Container Runtime Interface).
Worker Node
Kubelet
Virtual Network
Kubectl
Deployment
How to write YAML files for
Kubernetes
• What is YAML? YAML stands for YAML ain’t markup language is used to create
Kubernetes manifests.
• YAML’s official definition is a “human-friendly, data serialization standard for all
programming languages.” YAML’s main advantage over other similar formats like
JSON or XML is its human readability. YAML was specifically designed to be easily
readable and editable by humans. This makes it ideal for dual human-machine use
cases such as log files, configuration files, inter-process messages, and in this case,
also for Kubernetes config and definition files.
• In YAML, you only need to know 2 types of structures: lists and maps.
• A YAML map is how you define key-value pairs, which is an intuitive and
convenient method of creating configurations, such as in Kubernetes (A sample
Kubernetes config showing a map is below).
Create a Kubernetes Pod using
YAML
In Kubernetes we use YAML file which acts as
configuration file. These files are used to do
deployment, create new pods etc. Let us see what we
include in the YAML file. Make sure your YAML files in
Kubernetes should always have these four parameters
that are mentioned below.

apiVersion: When we create an object, the


apiVersion will define which version of kubernetes
API we will be using. If we search in google we can
see many apiVersion are available such as v1, beta,
apps/v1, stable etc.
kind: This will tell you what kind of object we are
trying to create, whether it is a Pod, deployment,
service or replicaset.
Metadata: As the name suggest it’s the data about
the object, that helps in uniquely identify the
object. Within metadata we can define name,
labels etc.
Note: While providing the spaces in YAML file always use space key and
not tab key.
Yaml contd….
• Spec: Additional Our final YAML file (pod-create.yaml) for
information will be creating a pod as shown below.
provided under spec
parameter. Within spec
we can define containers,
container name, container
image etc.

Once the YAML file is completed, save the file


and give it a name(eg: pod-create.yaml) we
can run below mentioned command to
create the pod. We can use either create or
apply both will do the same task.
Kubectl YAML Dry Run Examples
• Create a pod YAML named myapp which uses image nginx:latest
kubectl run mypod --image=nginx:latest --labels type=web --dry-run=client -o
yaml > mypod.yaml
• Create a Pod service YAML: Generate YAML for a Pod Service that exposes a NodePort. This will only work if you have
a running pod.
kubectl expose pod mypod --port=80 --name mypod-service --type=NodePort --dry-
run=client -o yaml > mypod-service.yaml
• Create NodePort Service YAML
kubectl create service nodeport mypod --tcp=80:80 --node-port=30001 --dry-
run=client -o yaml > mypod-service.yaml
• Create Deployment YAML
kubectl create deployment mydeployment --image=nginx:latest --dry-run=client -o
yaml > mydeployment.yaml
• Create Deployment Service YAML
• kubectl expose deployment mydeployment --type=NodePort --port=8080 --
name=mydeployment-service --dry-run=client -o yaml > mydeployment-service.yaml
YAML Autogeneration using Kubernetes
Extention

• One of the easiest ways to create Kubernetes YAML is using the visual
studio kubernetes extension.
• Install the Kubernetes VS code extension, and it will help develop k8s
manifests for most kubernetes objects. It also supports deploying apps
to local and remote k8s clusters.
• All you have to do is, start typing the Object name and it will
automatically populate the options for you. Then, based on your
selection, it will autogenerate the basic YAML structure.
• This extension supports YAML generation of Pods, Deployment,
Statefulset, Replicationset, Persistent Volumes (PV), Persistent Volume
Claims (PVC), etc.
Other characteristics you should
know about YAML:
• It is case sensitive
• Elements in the same level share the same left indentation, the
amount of indentation does not matter
• Tab characters are not allowed to be used as indentation
• Blank lines do not matter
• Use # to comment a line
• Use a single quote ' to escape the special meaning of any character

You might also like