Kubernetes Full INSAT's Course
Kubernetes Full INSAT's Course
Chapter 1: Kubernetes
RT4 - 2023
Containers are made possible by process isolation and virtualization capabilities built into the Linux kernel.
These capabilities—such as control groups (Cgroups) for allocating resources among processes, and namespaces for restricting a processes
access or visibility into other resources or areas of the system—enable multiple application components to share the resources of a single
instance of the host operating system in much the same way that a hypervisor enables multiple virtual machines (VMs) to share the CPU,
memory and other resources of a single hardware server.
As a result, container technology offers all the functionality and benefits of VMs—including application isolation, cost-effective scalability,
and disposability—plus important additional advantages:
It is the public repository of It is an application for Mac or It is a service that creates and
Docker images that calls itself the Windows that includes Docker manages Docker images, using
“world’s largest library and Engine, Docker CLI client, the commands from the client.
community for container images.” Docker Compose, Kubernetes, Essentially Docker daemon
It holds over 100,000 container and others. It also includes access serves as the control center of
images sourced form commercial to Docker Hub. your Docker implementation.
software vendors, open-source
projects, and individual
developers.
Notion of container orchestration: Docker
Every Docker container starts Docker images contain executable Docker containers are the live, running
with a simple text file containing application source code as well as all instances of Docker images. While
instructions for how to build the the tools, libraries, and dependencies Docker images are read-only files,
Docker container image. that the application code needs to run containers are life, ephemeral,
DockerFile automates the process as a container. When you run the executable content. Users can interact
of Docker image creation. Docker image, it becomes one with them, and administrators can
instance (or multiple instances) of adjust their settings and conditions
the container. using Docker commands.
Notion of container orchestration: Docker
Storage Orchestration
Self-healing
Control Plane
controller-
kube-apiserver etcd kube-scheduler
manager
Kubernetes Architecture: Control Plane Components
The API server is a component of the Kubernetes control plane that exposes
kube-apiserver the Kubernetes API. The API server is the front end for the Kubernetes control
plane.
Control
Plane
Control plane component that watches for newly created Pods with no
kube-scheduler assigned node and selects a node for them to run on.
Cluster
Node Node
(Worker) (Worker)
Kubernetes Architecture: Node Components
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
kubelet and ensures that the containers described in those PodSpecs are running and
healthy.
Node
Container The container runtime is the software that is responsible for running
containers.
runtime
Pods are the smallest deployable element in K8s, it is an abstraction layer for
Pods the containers
Kubernetes Architecture: Global Architecture
WORKLOAD OF KUBERNETES
Workload of Kubernetes
Kubernetes pods have a defined lifecycle. For example, once a pod is running in your cluster
then a critical fault on the node where that pod is running means that all the pods on that node
fail. Kubernetes treats that level of failure as final: you would need to create a new Pod to
recover, even if the node later becomes healthy.
However, to make life considerably easier, you don't need to manage each Pod directly. Instead,
you can use workload resources that manage a set of pods on your behalf. These resources
configure controllers that make sure the right number of the right kind of pod are running, to
match the state you specified.
Workload of Kubernetes: Pods
A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and
network resources, and a specification for how to run the containers. A Pod's contents are always co-located
and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it
contains one or more application containers which are relatively tightly coupled.
•Pods that run a single container: The "one-container-per-Pod" model is the most common Kubernetes use
case; in this case, you can think of a Pod as a wrapper around a single container; Kubernetes manages Pods
rather than managing the containers directly.
•Pods that run multiple containers that need to work together: A Pod can encapsulate an application
composed of multiple co-located containers that are tightly coupled and need to share resources. These co-
located containers form a single cohesive unit of service—for example, one container serving data stored in a
shared volume to the public, while a separate sidecar container refreshes or updates those files. The Pod
wraps these containers, storage resources, and an ephemeral network identity together as a single unit.
Workload of Kubernetes: Pods Lifecycle
Like individual application containers, Pods are relatively ephemeral (rather than durable) entities. Pods are created,
assigned a unique ID (UID), and scheduled to nodes where they remain until termination (according to restart policy) or
deletion. If a Node dies, the Pods scheduled to that node are scheduled for deletion after a timeout period.
The phase of a Pod is a simple, high-level summary of where the Pod is in its
lifecycle.
Pending The Pod has been accepted by the Kubernetes cluster, but one or more of the containers has not been set up and made ready to run. This
includes time a Pod spends waiting to be scheduled as well as the time spent downloading container images over the network.
Running The Pod has been bound to a node, and all of the containers have been created. At least one container is still running, or is in the process
of starting or restarting.
Succeeded All containers in the Pod have terminated in success, and will not be restarted.
Failed All containers in the Pod have terminated, and at least one container has terminated in failure. That is, the container either exited with
non-zero status or was terminated by the system.
Unknown For some reason the state of the Pod could not be obtained. This phase typically occurs due to an error in communicating with the node
where the Pod should be running.
Workload of Kubernetes: workload resources
StatefulSet StatefulSet lets you run one or more related Pods that do track state.
Workload
Resources
DaemonSet defines Pods that provide node-local facilities. These might be
DaemonSet fundamental to the operation of your cluster, such as a networking helper tool,
or be part of an add-on.
Job and CronJob define tasks that run to completion and then stop. Jobs
Job and CronJob represent on-off tasks, whereas CronJobs recur according to a schedule.
Workload of Kubernetes: Roll-Out
a Kubernetes rollout is a process of updating or replacing replicas with new replicas matching a new
deployment template. Changes may be configurations such as environment variables or labels, or also
code changes which result in the updating of an image key of the deployment template.
1. Create a YAML file describing the desired state 4. The kube-controller-manager continuously monitors the system for
configuration of the cluster. new requests and works towards reconciling the system state to the
desired state – creating ReplicaSets,
2. Apply the YAML file to the cluster through kubectl, the deployments and pods in the process.
Kubernetes command-line interface.
5. Once all controllers have run, the kube-scheduler will see that there
3.Kubectl submits the request to the kube-apiserver, which are pods in the “pending” state because they haven’t been scheduled
authenticates and authorises the request before recording the to run on a node yet. The scheduler finds suitable nodes for the pods,
change in a database, etcd. then communicates with the kubelet in each node to take control and
start the deployment.
Workload of Kubernetes: YAML Reminder
Every Pod in a cluster gets its own unique cluster-wide IP address. This means you do not need to explicitly create links
between Pods, and you almost never need to deal with mapping container ports to host ports.
This creates a clean, backwards-compatible model where Pods can be treated much like VMs or physical hosts from the
perspectives of port allocation, naming, service discovery, load balancing, application configuration, and migration.
Kubernetes imposes the following fundamental requirements on any networking implementation (barring any intentional
network segmentation policies):
•pods can communicate with all other pods on any other node without NAT
•agents on a node (e.g. system daemons, kubelet) can communicate with all pods on that node
K8s Networking: Cluster Networking
Networking is a central part of Kubernetes, but it can be challenging to understand exactly how it is expected to work.
There are 4 distinct networking problems to address:
• Kubernetes is all about sharing machines between applications. Typically, sharing machines requires ensuring that two
applications do not try to use the same ports. Coordinating ports across multiple developers is very difficult to do at
scale and exposes users to cluster-level issues outside of their control.
• Dynamic port allocation brings a lot of complications to the system - every application has to take ports as flags, the API
servers must know how to insert dynamic port numbers into configuration blocks, services must know how to find each
other, etc. Rather than deal with this, Kubernetes takes a different approach.
KUBERNETES AND STORAGE
Kubernetes and Storage: Challenge
In Kubernetes, containerized applications can be either stateful or stateless. Stateless applications do not have any
persistent state, and they lose their data once the containerized application shut down or accidentally crashed. However, for
stateful applications, Kubernetes needs to attach persistent external volumes for the storage of states.
Storage for stateful applications has always been a challenge as they must be always provisioned with the volume which
stays connected with pods through remote storage. Kubernetes community is trying to fill the gap for managing stateful
apps for years by providing many abstractions and features. But containers by default are stateless, causing significant
challenges for stateful workloads.
Kubernetes and Storage: Storage Classes
A Storage Class provides a way for administrators to describe the "classes" of storage they offer. Different classes might
map to quality-of-service levels, or to backup policies, or to arbitrary policies determined by the cluster administrators.
Kubernetes itself is unopinionated about what classes represent. This concept is sometimes called "profiles" in other
storage systems
Reclaim
Can be either Delete or Retain
Policy
Kubernetes and Storage: Main Volume types
Persistent
Some application need additional storage but don't care whether that data is stored persistently across
restarts. For example, caching services are often limited by memory size and can move infrequently
used data into storage that is slower than memory with little impact on overall performance.
Other applications expect some read-only input data to be present in files, like configuration data or
secret keys.
Ephemeral volumes are designed for these use cases. Because volumes follow the Pod's lifetime and get
Ephemeral
• emptyDir: empty at Pod startup, with storage coming locally from the kubelet base directory
(usually the root disk) or RAM
• configMap, downwardAPI, secret: inject different kinds of Kubernetes data into a Pod
• CSI ephemeral volumes: similar to the previous volume kinds, but provided by special CSI drivers
which specifically support this feature
• generic ephemeral volumes, which can be provided by all storage drivers that also support persistent
volumes
BASIC SECURITY CONCEPTS
Basic Security Concepts: The 4C's of Cloud Native security
You can think about security in layers. The 4C's of Cloud Native security are Cloud, Clusters, Containers, and Code. Each
layer of the Cloud Native security model builds upon the next outermost layer. The Code layer benefits from strong base
(Cloud, Cluster, Container) security layers. You cannot safeguard against poor security standards in the base layers by
addressing security at the Code level.
Basic Security Concepts: Code
Application code is one of the primary attack surfaces over which you have the most control.
While securing application code is outside of the Kubernetes security topic, here are recommendations to protect
application code.
In many ways, the Cloud (or co-located servers, or the corporate datacenter) is the trusted computing base of a Kubernetes
cluster. If the Cloud layer is vulnerable (or configured in a vulnerable way) then there is no guarantee that the components
built on top of this base are secure. Each cloud provider makes security recommendations for running workloads securely
in their environment
Area of Concern for Kubernetes Infrastructure Recommendation
Access to etcd
Access to etcd (the datastore of Kubernetes) should be limited to the control plane only. Depending on your
configuration, you should attempt to use etcd over TLS. More information can be found in the etcd documentation.
etcd Encryption
Wherever possible it's a good practice to encrypt all storage at rest, and since etcd holds the state of the entire
cluster (including Secrets) its disk should especially be encrypted at rest.
Basic Security Concepts: Security Checklist
Authentication & Authorization:
Cloud adaptations with Kubernetes help simplify and automate container management, making it easier to deploy
and manage applications in the cloud.
Cloud adaptation to Kubernetes: Key Terms
Container Kubernetes enables automated container management, providing features such as scheduling,
Orchestration scaling, updating and deploying containers.
Configuration Kubernetes provides tools for managing the configuration of containers, including secret
Management management, storage volume management and configuration settings management.
Update Kubernetes enables applications to be updated seamlessly, managing the update process without
Cloud management service interruption.
adaptatio
ns Kubernetes enables automatic replication of containers to improve application resiliency and
Replication availability.
General
Key
Terms Resource Kubernetes provides tools for resource management, including memory management, CPU usage
management management and quota management.
Kubernetes provides security features such as identity management, certificate management and
Security security policy management.
Choose a Kubernetes Service : Azure offers several Kubernetes services, including Azure Kubernetes Service (AKS), Azure Red Hat
OpenShift, and Azure Arc enabled Kubernetes. Choose the service that best suits your needs based on your requirements and the level of control
you need.
Deploy Kubernetes : Once you've selected a Kubernetes service, you can deploy Kubernetes on Azure by following the service-specific
deployment steps. For example, to deploy AKS, you can use the Azure Portal or Azure CLI.
Configure Networking : Kubernetes on Azure requires networking configuration to enable communication between pods and services. Azure
offers several options for configuring networking, including Azure CNI. Choose the networking solution that best suits your needs.
Secure Your Cluster : Security is an important consideration when running Kubernetes on any cloud platform. Azure provides several built-in
security features, such as Azure Security Center, Azure Active Directory integration, and Role-Based Access Control (RBAC). Make sure to
enable these features to secure your cluster.
Monitor Your Cluster : Monitoring your Kubernetes cluster is important to ensure its performance and availability. Azure offers several tools
for monitoring Kubernetes, such as Azure Monitor and Azure Log Analytics. Use these tools to track the health of your cluster and diagnose
issue.
Automate Deployment : Automating deployment can save time and reduce the risk of errors. Azure offers several tools for automating
Kubernetes deployment, such as Azure DevOps, Azure Kubernetes Service (AKS) Deployment Center, and Azure Arc enabled Kubernetes.
Choose the tool that best suits your needs.
Cloud adaptation to Kubernetes: AWS
Running Kubernetes in the cloud is easy with AWS. A scalable and highly available infrastructure of virtual machines, integrations of
services from the community and the managed Kubernetes service Amazon Elastic Kubernetes Service (EKS), which is certified as
Kubernetes-compliant, are used for this purpose.
Kubernetes in Multi Cloud: Best Practices
K8s clusters across multiple clouds
Kubernetes is a platform with similar
aspects to those in a data center.
• networking
• servers
• storage
• security and policies
• permissions and RBAC
• container images