What is Kubernetes? Flashcards
What is Kubernetes?
- It’s a container orchestration tool. But it’s much more than that.
- You can run it on your own cloud, on your system or a public cloud
- Zero downtime updates
- self healing of clusters
- you can migrate it from one cloud provider to another provider.
- K8 can replicate services, scale them and put them on dedicated servers
- You can use volumes - external storage
- Load balancing for requests
- Access logs
- Secret information like password using secrets
- There’s service discovery
Why is K8 called OS of the cloud?
Coz you just run your application for Kubernetes but don’t care where it’s running. Idc if it’s running on Aws, Gcp or civo
The two ways to use kubectl
Declarative way and imperative way.
Declarative: we create yaml manifest files. You write code in the yaml files. You give this file to the control plane via kubectl. This is the recommended way
Imperative: write commands in terminal for every change. Very tedious process and can get lost in those commands
Is K8 a cluster or orchestrator?
Both. Cluster is Control plane + worker nodes. Orchestrator means managing all the micro services.
Where are the micro services/ apps running? - On the worker nodes.
Node means server
What is a pod?
Pod is the smallest scheduling unit in Kubernetes. Pod is the definition of how to run a container. Inside the pod, you run the containers.
You cannot schedule a container without scheduling a pod, coz pod is the smallest scheduling unit.
You can schedule pods inside a deployment. This will scale your pods, update your pods and all these other things.
Best practice- 1 type of service -1 pod
If someone goes to the pod.yaml file, he can understand everything about the container.
How to run application in k8’s?
- Create micro service
- Put every micro service in its own container.
- Put every container in its own pod.
- Deploy these pods to controllers (such as deployments)
What is controller?
Controllers watch the state of your kubernetes cluster.
Each controller tries to make the cluster state closer to the desired state.
What are two types of controllers? A Deployment controller and Job controller. These are built in controllers in kubernetes
I’m telling k8- hey I want you to run 5 pods. You give this information to whom? A controller
What is desired state?
It’s the configuration that a user wants their system to achieve. This is achieved through the use of API, where the state of objects such as ReplicatSet, Deployment, etc., is described. Kubernetes, through its controller managers, ensures that the actual state of the system matches the desired state
What is Control plane?
A collection of various components that help us in managing the overall health of the cluster.
You want to create new pod, scale pods, destroy something, expose something.
Architecture of Control plane
API server - All communication happens via this. Kubectl talks to this. It basically exposes a restful api. (Https://443)
Etcd - database. It stores information about the cluster. If the API wants any info about the server, it communicates to etcd.
Controller manager - Manages the controllers. Has 4 functions - manages Desired state, manages Current state, Differences, Make changes to server if someone is requesting changes
Scheduler - Responsible for scheduling the objects. Scheduler is the one who’s going to schedule it on worker nodes
Architecture of Worker Node
Kube-Proxy- Responsible for networking. If your worker node or your cluster wants to communicate with outside network, kubeproxy will help with that. It makes sure that every worker node gets its own unique IP address. So every node has its own IP address
Kubelet- It’s on every worker node. Whenever a new worker node is created and attached to the control plane, a kubelet is attached to it. It listens to the API server from the control plane and allocate those on the worker node
Container runtime- A container runtime, also known as container engine, is a software component that can run containers on a host OS.
K8 used container d. Pulling the image, pushing the image, creating a container, stopping a container, destroying a container.
In K8, there was support for docker, but coz of CRI, (and docker doesn’t support CRI) it’s replaced with container-d.
Does K8 have self healing of clusters?
Kubernetes heals itself when there is a discrepancy and ensures the cluster always matches the desired state.
if a pod goes down, a new one will be deployed to match the desired state.
Kubernetes implements self-healing at the Application Layer. This means that if your app is well containerized and a pod where containers are placed crashes, Kubernetes will work to reschedule it as soon as possible.
Containers are made available for clients only if they are ready to serve.
What is service discovery?
Mechanism that allows services to discover each other dynamically without the need for hard-coding IP addresses or endpoints.
In Kubernetes, a Service is an object that exposes a network application running as one or more Pods, and it provides a consistent way to access the set of Pods.
Kubernetes provides service discovery through its endpoints API, which allows client applications to discover the IP addresses and ports of pods in an application. The service discovery mechanism in Kubernetes is essential for enabling communication between microservices without manual configuration, thus supporting the dynamic nature of cloud-native applications
This is particularly useful in a dynamic environment where the IP addresses and ports of Pods are continually changing.
Benefits:
1. Dynamic communication
2. Abstraction and Load Balancing
3. Simplified configuration
4. Support for micro service architecture.
Monokle
OSS to write Yaml Manifest files. Sometimes these files can get very complex. It makes your life extremely easy when using Kubernetes
How does communication inside cluster happen b/w two nodes?
K8 has its own internal DNS. It has IP addresses for every pod, so they can communicate with each other.