Kubernetes (k8s) is an open-source system for automating deployment, scaling and management of containerized application. It groups containers that make up an application into logical units for easy management and discovery.
It was originated in Google, in 2015 google release Kubernetes as an open source project, shortly after it was donated to CNCF for promoting container technology
Various advantages of k8s:
- Automates various manual process.
- Interacts with several groups of containers
- Self-healing and Self-monitoring
- Horizontal Scaling
- Storge Orchestration
- Automates rollouts and rollbacks
- Container load balancing
- Run everywhere / supports On-prem / Cloud / Hybrid environment
- Fast paced deployment techniques
- Declarative configuration
- Decoupling / Supports micro-services ecosystem / seperation of concerns
- Provides efficiency - both cost efficiency and operational efficiency
- Portability / Modularity
- Provides additional capabilities
Disadvantage of k8s:
- Some degree of complexity of setup
- Network latency and limitations
A cluster consists of at least one master cluster and multiple worker machines called nodes. When the programs or applications are deployed onto a cluster, it intelligently handles distributing work to the individual nodes via master. A cluster is a "master-nodes" architecture.
Master components are also know as Decision Makers, it's consists of :
- kube-apiserver: it process / validated the json or yaml file that contains the information such as name, label and specification about the entity
- kube-scheduler : this is the head of all the scheduling task, if any pods are unavailable then this component will ensure it avaialable at another pod
- kube-controller-manager : a controller watches the state of the cluster through kube-apiserver and makes changes to get the desired state. It's a continuously watching deamon process which manages all the system example - Node Controller, Replication Controller, Endpoints Controller etc.
- etcd : Storage for the k8s cluster ( Key Value pair format), only kube-apiserver will be able to communicate with etcd
Node components it's consists of :
- kubelet : an agent that runs on each node, it communicate with the master via API, it main job is that the containers are running on pods
- Container Runtime : responsible for downloading and running the containers
- kube-proxy : maintains the network rules on the host
Single instance of an application in k8s, which consists of either a single container or a small number of containers that are tightly coupled and share resources. It runs on a single node and represents a unit of deployment in k8s.
- Pods are atomic, building blocks of k8s.
- A Pod can only run on a single node at a given time
- Pod is the unit of scaling in k8s
- Each Pod is assigned a unique IP address. Containers inside a Pod can communicate with one another using localhost
- All containers in the Pod can access the shared volumes, allowing those container to share data
A way of grouping the pods for variety of purposes, can be used for providing the quotas and limits around resource usage have an impact on DNS name that k8s create internal to the cluster and in the future may impact access control policies. Namespaces could also be used to divide the cluster resources between various users.
Command to view all namespaces:
kubectl get pods --all-namespaces
k8s starts with three intial namespaces:
- default
- kube-system - for the object created by the kubernetes system
- kube-public - created automatically and is visible and readable by all the users throughout the whole cluster
Tag that can be attached to kubernetes object to mark them as a part of a group. An object can have multiple labels, but the keys must be unique.
Allows you to attach key-value information as metadata to an object.
It ensures that a specified number of pods replicas are running at any one time. It starts or terminates the pods depending on the desired state. Pods maintained by replication controller are automatically replaces if they are fail, are deleted, or terminated.
- RC starts/stops pod depending on the desired state
- Error correction and detection
- Ease of supervision and management
- Supervises multiple pods across multiple nodes
Created using deployment, this is a declarative way of ensuring that a specified number of pod replica are running at any given time. It starts or terminates the pods depending on the desired state. It allows access to pods within each other inside a cluster as well as outside of it.
An abstraction which defines a logical set of Pods and a policy by which to access those pods. It facilitates access to the pods within the cluster or outside of it.
- With this type (default) the service can be reached only from within the cluster
- Assign the service it's own IP address
- This option is used if the service is to be accessed from outside the cluster. It exposes the service on each Node's IP at a static port (the NodePort). So the service accessed using the :
- If the type field is NodePort, the kubernetes master will allocate a port of the range specified by the --service-node-port-range flag (default: 30000-32767), and each Node will proxy that port ( the same number on every Node) into the service
- Specific port number can be used in the NodePort field, and the system will allocate that port.
- Exposes the service externally using a cloud provider's load balancer(Ex- Elastic Cloud Load Balancer of AWS).
- Provides ExternalIP to access the service
- Simply provide a DNS reference called as ExternalName
- Does not include a selector, and doesn't include any port references either. Instead, it simply defines and external DNS entry that can be used as a service definition.
It's a process for finding out how to connect to a service. It can discovered by
- Environment Variables
- Using Domain Name System
A Deployment controller provides declaritive update for Pods and ReplicaSets. Once the desired state is described in the Deployment object, and the Deployment controller changes the actual state to the desired state at a controlled rate.
A storage that is accessible to the containers in a Pod. A pod can specify a set of shared storage volumes.
A Probe is a diagnostic performed periodically by the kubelet on a container. This helps k8s identify what is going on the pods and their containers. There are two types of container probes:
- livelinessProbe : Indicates whether the container running
- readinessProbe : Indicate whether the container is ready to serve the request