CKA Study Guide
CKA Study Guide
• General Terms
○ Virtual Ethernet Device (veth)
▪ Consists of two virtual interfaces that can be spread across multiple namespaces
allowing traffic to flow between the two namespaces
○ netfilter / iptables
▪ Netfilter is a firewall framework for Linux which consists of many modules including
iptables which is the primary module
• Kubernetes Terminology
○ Init container
▪ One or more initialization containers that must run to completion before any app
containers
▪ In the pod spec use the initContainers heading
○ headless service
▪ Used when you do not need load balancing and a single IP and want to achieve the
discovery process outside of Kubernetes
○ node affinity
▪ Property of pods that attracts them to a specific set of nodes either as a preference or
a hard requirement
○ Binding
▪ Process by which the scheduler notifies the API server about the decision as to where
to schedule a pod
○ Eviction
▪ Process by which pods on a node are deleted
▪ If a node becomes unavailable for more than 5 minutes pods are evicted from the
node
▪ Also happens when node runs out of resources
○ Runtime class
▪ Property of a pod that can allows you to run different pods with the same container
runtime but with different settings
▪ Use case is may a highly secure workload running on a machine that supports
hardware isolation
○ Static Pod
▪ Managed directly by kubelet daemon on a specific node without the API server
observing them
▪ Mirror object created in api-server so it can be displayed with kubectl
▪ Used primarily for boostrapping Kubernetes itself such as with kubeadm
○ Ephemeral Containers
▪ Lack guarantees for resources and executions and never automatically restarted, no
ports (so no probes), no setting resources
▪ Useful for interactive troubleshooting when kubectl exec is insufficient
○ Proporational Scaling
▪ Supported by RollingUpdate Deployments to run multiple versions of an application at
the same time
▪ If scaling request comes in during rollout, the replicas are spread among the two
replica sets
○ Garbage Collection
▪ Control whose responsibility is to remove cleanup objects that once had an owner but
do not anymore
○ Service Discovery
▪ Can be provided by Kubernetes API Server which will provide a dynamic listing of
endpoints available for a particular service which is kept up to date as Pods are
brought up and down
○ sidecar
▪ Another container within a pod that is used to run another specific task such as
collecting and aggregating logs
○ Persistent Volume
▪ Allows abstraction of details of how storage is provided from the users of a cluster
▪ Lifecycle is independent of a Pod unlike a Volume
▪ Clusterwide storage and created by the administrator
○ Storage Classes
▪ Defines a dynamic provisioner which provisions storage based upon apps request
them
▪ Persistent volume claims can directly reference a storage class negating the need for a
persistent volume
• General Facts
○ Default pull policy for images in Kubernetes is IfNotPresent but be modified in the container
spec by setting imagePullPolicy to Always
○ CoreDNS has a TTL for cached responses of 30 seconds
○ Control Plane
▪ Key Facts
○ Make global decisions about the cluster such as scheduling and responding to cluster events
such as starting new pods
▪ Worker Components
○ kubelet
▪ Runs as a service
▪ Agent that runs on each node in the cluster and makes sure containers are running in
a pod
▪ Always manually installed on worker nodes
○ kube-proxy
▪ Maintains network rules on nodes which allow network communication to your pods
from network sessions outside your cluster
▪ Uses OS packet filtering layer if available other forwards traffic itself
○ Container runtime
▪ Software responsible for running the containers
▪ Examples: Docker, containerd, CRI-O
▪ Manager Components
○ kube-apiserver
▪ Exposes Kubernetes API which is the front-end of the control plane
▪ Scales horizontally
▪ Responsibilities
□ Authenticate User
□ Validate Request
□ Retrieve Data
□ Update ETCD
□ Communicate with Scheduler
□ Communicate with Kubelet
○ etcd
▪ Runs as service
▪ Consistent and highly available key value store used as Kubernetes backing store for
all cluster data
○ kube-scheduler
▪ Watches for newly created pods with no assigned node and selects a node for them to
run on
○ kube-controller-manager
▪ Runs controller processes
▪ Consists of separate controllers wrapped into a single binary named kube-controller-
manager
▪ Node controller
□ Responsible for noticing and responding when nodes go down
Monitors health via kube-apiserver every 5 seconds
Grace period of 40s before marked as unreachable
Given 5 minutes before Pods are evicated
○ Cloud-controller-manager
▪ Embeds cloud-specific logic and links cluster to cloud provider's API
▪ Separates out components that interact with the cloud platform from components
that interact with your cluster
▪ Only runs controllers specific to cloud provider
▪ Not present if running on-premises
▪ Wrapped into a single binary and scales horizontally same as kube-controller-manager
○ etcd
• Key Facts
○ etcd is a distributed key value store that provides a reliable way to store data across a
cluster of machines
○ Used by Kubernetes to store all of its internal data about cluster state and synchronize
across all controller nodes
○ Installed on each controller node to create a etcd cluster
○ Runs as a service on each controller node
• Configuration
○ Etcd requires root CA public-key cert used to issue certificates to Kubernetes cluster and
both public and private key certificates for API in etc/etcd directory
• Pod Storage
○ By default storage used by containers within a Pod is ephemeral
○ Volumes can be used to provide persistent storage of data to containers within a Pod
• Persistent Volumes
○ Key Facts
▪ Access mode for a Persistent Volume can be
□ ReadOnlyMany
□ ReadWriteOnce
□ ReadWriteMany
▪ An overall capacity is defined for the Persistent Volume
▪ It also has a type which could be hostPath (local host) or another storage class such as public
cloud provider
• Key Terminology
○ Virtual Ethernet Device (veth)
▪ Consists of two virtual interfaces that can be spread across multiple namespaces
allowing traffic to flow between the two namespaces
○ Services
▪ Expose an application running on a set of Pods as a network service
○ Ingress
▪ Object that manages external access to services in a cluster and may provide load
balancing, SSL termination, and name-based virtual routing
○ Cluster CIDR
▪ IP range used to assign IPs to Pods in the cluster
○ Pod CIDR
▪ IP range for Pods on a specifc worker node
▪ Should fall within the cluster CIDR but not overlap with the Pod CIDR of other worker
nodes
○ Headless Services
▪ Use to interface with other service discovery mechanisms without being tied to
Kubernetes implementation
• Key Facts
○ One virtual network for all hosts within a cluster
○ Each Pod has a unique IP within the cluster
○ Each Service has a unique IP that is in a different range than Pod IPs
○ All Pod can communicate with other Pods within a clsuter and can reach each other's ports
on localhost
○ All Pods can see each other without NAT
• Standard Concepts
○ DNS
▪ Key Facts
□ Service Structure: <SERVICE_NAME>.<NAMESPACE>.[Link]-
[Link]
□ Pod Stucture: <POD_IP_ADDRESS>.<NAMESPACE>.[Link]-
○ IPVS vs iptables
▪ iptables runs into performance issues with >5,000 services because iptables rules are
evaluated sequentially
▪ IPVS scales more effectively for >5,000 services because it uses a hash table managed
by the kernal to determine the destination of a packet
○ kubenet
▪ Very basic network plugin available on linux only and no support for advanced
features like Network policy
▪ Run with --network-plugin=kubenet
▪ Pods assigned network through --pod-cidr kubelet command line option or --allocate-
node-cidrs=true through controller-manager
○ SSH tunnels
▪ SSH tunnels to protect control plane to node communication is supported but is
deprecated
○ Connectivity service
▪ New replacement for SSH tunnels for control plane to node communication
▪ TCP level proxy for the control plane to cluster communication
○ kube-proxy Modes
▪ User space proxy mode
□ kube-proxy watches K8 master for addition and removal of Service and Endpoint
objects
□ For each service it opens port randomly on the local node and connection to
proxy port are proxied to one of Services's backend pods (as reported by
Endpoints)
□ Honors SessionAffinity
□ Installs iptables rules which capture traffic to Service's clusterIP and Port which
redirect traffic to proxy port which proxies to backend Pod
□ Backend chosen by round-robin by default and if backend connection to first
Pod fails automatically try with a different backend Pod
• Kubernetes Resources
○ Services
▪ Key Facts
□ Have a DNS label of <SERVICE_NAME>.<NAMESPACE>.[Link]
□ Assigned an IP address from the --service-cluster-ip-range argument set for the
• Resources
○ Great comparison of iptables vs IPVS - [Link]
[Link]/en/blog/2018/03/19/kubernetes-ipvs/#:~:text=The%20IPVS%20implementation%
20differs%20from,massive%20packet%20processing%2C%20performances%20collapse.
• Concepts
○ Roles and Role Bindings
▪ Key Facts
□ Scoped to a namespace
□ In the definition for a role the apiGroups property can be left blank if
referencing a resource in the core/v1 API
□ Roles are associated with a user using a RoleBinding
○ Network Policies
▪ Key Facts
□ Applied to Pods to control ingress and egress traffic
□ Not supported by all CNIs
○ Kubeconfig
▪ Key Facts
□ kubectl by default references config file in $HOME/kube/config
□ Designate a specific kubeconfig file using the --kubeconfig <CONFIG_FILE>
option of kubectl
□ Configuration file that stores information about clusters, users, namespaces,
and authentication mechanisms
□ Contains data needed to connect to and interact with one or more Kubernetes
clusters
▪ Structure
□ Clusters - location of the cluster (hostname or IP address)
□ Contexts - marry the clusters and users together to determine which user will be
used to access a cluster
□ Users - user accounts of which you have access to
• PKI Dependences
▪ Key Facts
□ Clusters setup with kubeadm make the first master node the CA for the cluster
□ Kubernetes supports a certificate API where CSRs can be sent to and processed
and is managed by controller-manager
□ Certificate requests can be expressed in YAML using the
CertificateSigningRequest spec and value of request must be base64 encoded
▪ Server components
▪ Client components
□ kube-scheduler certificate
Looks for Pods that need scheduling and communicates with kube-
apiserver
□ kube-controller-manager certificate
Communicates with kube-apiserver
□ kube-proxy certifocate
• Authentication
○ Human
▪ Kubernetes does not support human-being identities and authentication out of the
box, this must be provided by a third-party integration
▪ kube-apiserver handles authentication of human users
□ Static password file
Pass as an option to kube-apiserver service using --basic-auth-
file=[Link]
This file has three columns, username, password, (optionally group)
□ Static token file
Pass as an option to kube-apiserver service using --token-auth-
file=[Link]
This file has three columns, token, username, (optionally group)
Pass the token as an authorization header
□ Certificates
□ Identity services
○ Non-Human
▪ Kubernetes does support non-human identities and authentication via service
accounts
▪ Kubernetes control nodes and worker nodes authenticate with each other using
certificate
• Authorization
○ RBAC
▪ Key Facts
□ In the definition for an RBAC role the apiGroups property can be left blank if
referencing a resource in the core/v1 API
□ Roles are associated with a user using a RoleBinding
• Key Facts
• If NodeName in Pod spec is not set, then scheduler will determine which node to schedule the Pod
to
○ Resource Requests
▪ Key Facts
○ Request and Limits defaults are configured on per namespace
○ CPU, Memory Disk
○ By default Kubernetes limits each container in the Pod to 1vCPU and 512Mi
○ If Pod tries to use more than it's limit of memory consistently it will be terminated but a Pod
is throttled at the CPU limit and cannot use more than that limit
○ Request are the minimum required by the container and the limit is the maximum amount
of resources the container in a Pod can consume
○ Set the request and the limits in the Pod spec for each container in the Pod
○ Express CPU by full vCPU (1) or tenths of a CPU (100m)
○ Express Memory in G, Gi (Gibityes - 1024MB), M, Mi (Mebibyte)
▪ Example
○ Resources:
requests:
memory: "1Gi"
cpu: 1
limits:
memory: "2Gi"
cpu: 2
○ Annotations
▪ Key Facts
Used to record other informational metadata for some other purpose potentially by a third
▪ Node Selector
○ Allows you to constrain a pod to a specific node(s)
○ Does not support conditional language like AND or OR
○ Field of the PodSec
nodeSelector:
<KEY>:<VALUE>
▪ Node Affinity
○ Facts
▪ Limit Pod placement using advanced conditionals
▪ Detailed in Pod spec
▪ Use in combination with taints and tolerations to dedicate nodes to specific Pods
○ Types
▪ requiredDuringSchedulingIgnoredDuringExecution
□ Pod will not be scheduled if affinity rules don't match any Nodes
□ Pods running on a Node where affinity rules no longer match will continue to
run
▪ preferredDuringScheudlingIgnoreDuringExecution
□ Pod will scheduled on Node with matching affinity if possible
□ Pods running on a Node where affinity rules no longer match will continue to
run
▪ requiredDuringSchedulingRequiredDuringExecution
□ Pod will not be scheduled if affinity rules don't match any Nodes
□ Pods running on a Node where affinity rules no longer match will be evicted
○ Examples
▪ affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: <KEY>
operator: In/NotIn/Exists/NotExists
values:
- <VALUE1>
<VALUE2> (Processed as OR)
○ Field Selectors
▪ Facts
○ Let you seelct Kubernetes resources based on value of one or more resource fields
Example: [Link]=<SOME_VALUE>
○ Multiple Schedulers
▪ Facts
○ Kubernetes supports custom schedules and multiple schedulers running in the same cluster
○ Add new field of schedulerName in Pod spec to designate a custom scheduler
▪ kube-scheduler Facts
○ kube-scheduler assumes name of default-scheduler so to add a different scheduler it must
be named something unique
○ If multiple copies of kube-scheduler running on multiple master nodes in HA configuration --
leader-elect option must be set to true to ensure that one instance of the scheduler is
handling all scheduling
• Probes
○ Facts
▪ Diagnostic performed periodically by the kubelet on a Container
○ Handlers
▪ ExecAction
□ Specified command run in container and successful if status code 0
▪ TCPSocketAction
□ Performs a TCP check against the Pod's IP address on a specified port
▪ HTTPGetAction
□ Performs HTTP GET request on Pod's IP address on a specified port and path
which is successful if > or = to 200 and <400
○ Types
▪ livenessProbe
□ Indicatese whether container is running and if probe fails kubelet kills the
container and subject to restart policy
□ USE CASE - Use if your application may fail without crashing the container
▪ readinessProbe
□ Indicates whether container ready to respond to requests
□ If fails endpoint controller removes Pod's IP address from endpoints of all
services that match the pod
□ USE CASE - If you'd like to send traffic only after the probe succeeds
▪ startupProbe
□ Indicates whether the application within the container has started
□ All other probes are disabled if startup probe is provided and succeeds
□ USE CASE - Useful for containers that take a long time to start
• Cluster Upgrades
○ Key Facts
▪ Management components can be different versions but none should be higher than
kube-apiserver
▪ Controller-manager and kube-scheduler can be one version lower than kube-apiserver
while kubelet and kube-proxy can be two versions lower than kube-apiserver
▪ kubectl can be one version higher or one version lower than kube-apiserver
▪ Recommended approach for upgrades is upgrading one minor version at a time
○ Upgrade Options
▪ Cloud providers typically have seamless upgrades
▪ Kubeadm simplifies upgrade process
□ Only updates master nodes and worker nodes must be updated separately
▪ Deployment from scratch requires manual upgrade of each component
○ Upgrade Process
▪ Master nodes are updated first so controller-manager functions are unavailable at
that time unless multiple master nodes
▪ Nodes should be upgraded on a per node basis to avoid downtime of workloads if
upgrading existing nodes
▪ Adding new nodes is another option then decomming old nodes
○ Nodes
▪ Key Facts
○ Run on every node maintaining pods and providing Kubernetes runtime environment
○ Sends heartbeats to node controller to inform controller it is running
○ Controller
▪ Key Facts
○ Control loops that watch state of cluster and make or change requests where needed to
achieve desired state
○ Tracks at least one resource type
○ Sometimes carry out actions themselves but more commonly send message to API server to
initiate an action
○ Cluster Add-Ons
▪ Key Facts
○ Implement cluster features
○ Cluster DNS add-on should be installed on server
○ Other examples include Web UI, Container Resource Monitoring, and Cluster-level logging
○ Object
▪ Facts
○ Persistent entity in the Kubernetes system which are used to represent the state of the
cluster
○ Record of intent which Kubernetes will constantly work to ensure exists (desired state)
○ Defining YAML files require the apiVersion, kind, metadata, and spec
○ Names are unique for a given resource within a namespace
○ Every object created over the entire lifetime of a cluster is assigned a unique UID (a UUID)
▪ Key Terms
○ spec
▪ Set at the creation of the object and provides a description of characteristics (desired
state)
○ Status
▪ Describes current state of the object and Kubernetes
▪ Management
○ Imperative commands operate on live objects
▪ Example: kubectl create deployment <DEPLOYMENT_NAME> --image
<CONTAINER_IMAGE>
○ Imperative object configuration operates on individual files
▪ Example: kubectl create -f <FILENAME>.yaml
○ Declarative object configuration operates on directory of files
▪ Processes all all objects across a directory or set of directories and the operations to
be performed are detected automatically by kubectl
▪ Example
□ kubectl diff -f configs/
□ kubectl apply -f configs/
○ Container Hooks
▪ Facts
○ Enable container to be aware of events in management lifecycle and run code implemented
by handler when lifecycle hook is executed
▪ Hooks
○ PostStart
▪ Executes immediately after a container is created
○ PreStop
▪ Executes immediately before is container is terminated due toa n API request or
management event such as liveness probe failure, preemption, resource contention,
etc
▪ Hook Handler Types
○ Exec
▪ Executes a specific command inside cgroups and namespaces of the container
○ HTTP
▪ Executes an HTTP request against a specific endpoint on the container
○ Pods
▪ Facts
○ Group of one or more containers that share the same storage/network resources and can
refer to each other as localhost
○ Co-located and run in shared context
○ Mean to be ephemeral and disposable
○ Pods are never updated directly and instead if a template is changed are deleted and
recreated using the new template
○ readinessGates allow you to introduce extra feedback or signals to PodStatus which until the
condition is met the pod is not deemed ready
○ Pods that are already running can only have the following items edited:
▪ [Link][*].image
▪ [Link][*].image
▪ [Link]
▪ [Link]
▪ Lifecycle
○ Pending
○ Running
○ Succeeded - All containers in pod have terminated in success
○ Failed - All containers in Pod have terminated but at least one container terminated in
failure
○ Unknown
▪ Container States
○ Waiting
○ Running
○ Terminated
▪ Pod Status
○ PodScheduled
▪ Pod has been scheduled to a node
○ ContainersReady
▪ All containers in pod are ready
○ Initiatlized
▪ All init containers have started successfully
○ Ready
▪ Pod is able to serve requests and should be added to the load balancing pools of all
matching Service
▪ Disruptions
○ Involuntary
▪ Hardware failure of physical VM backing a node
▪ Cluster admin deletes VM
▪ Cloud provider or hypervisor makes VM disappear
▪ Kernal panic
▪ Node disappears from cluster to due networking issue
▪ Evocation of pod due to out of resources
○ Voluntary
▪ Deleting the deployment or other controller that manages the pod
▪ Updating a deployment's pod templates causing a restart
▪ Directly deleting a pod
▪ Draining a node for repair or upgrade
▪ Draining a node from a cluster to scale the cluster down
○ Static Pod
▪ Key Facts
○ Pods created and managed by the kubelet process on each node without interaction with
API Server or Scheduler
○ Definition files are placed in directory and Kubelet regularly checks this directory and will
create and update Pods as per the manifest file
○ The directory is designated in the kubelet etcd config file using the --pod-manifest-path
option
○ Clusters configured with kubeadm sets the directory by using the --config option of the
[Link] file which points to a config file where the directory is configured
○ Static Pods are reported to the kube-apiserver because the kubelet creates a stub object to
represent the Pod and are appended with "-NODENAME"
▪ Use Case
○ kubeadmn tool uses Static Pods to create the Pods on the Master nodes for the controller-
manager, apiserver, and etcd services.
○ ReplicaSet
▪ Key Facts
○ ReplicaSet Controller is replacing Replication Controller and is the preferred method moving
forward
○ Controller that has a main purpose of maintaining a stable set of replica Pods at any given
time
○ Defined with fields that include a selector to identify which pods to acquire, number of
replicas, and a Pod template
○ Ownership of a Pod by a ReplicaSet is indicated in the [Link] field of
the Pod
○ Deployments manage a ReplicaSet and should be used instead of directly using a ReplicaSet
○ Deployments
▪ Key Facts
○ Controller that changes the actual state of a deployment to meet the desired state
○ By default Deployment ensure at least 75% of the desired number of Pods are up
○ Rollouts can be paused and resumed
○ Deployments can fail due to insufficient quota, readiness probe failures, image pull errors,
insufficient permissions, limit ranges, and application runtime misconfig
○ Control rollout with Max Unavailable and Max Surge (how many pods over max can be
created)
▪ Features
○ Rolling updates
○ Rollback updates
▪ Deployment Strategies
○ Recreate
▪ All older Pods deleted before new version of deployment added
○ Rolling Update
▪ Default
▪ Gracefully removes Pods to ensure application does not become unavailable
▪ Use Cases
Create a deployment to rollout a replica set
○ Stateful Sets
▪ Key Facts
○ Updates have two strategies
▪ OnDelete
□ pods are not replaced when you apply manifest and instead you have to
manually delete existing pods before new one will be created
▪ RollingUpdate
□ same as deployment
○ Each pod has a unique network identifier <STATEFULSETNAME>-
<ORDINAL>.<SERVICE_NAME>.<NAMESPACE>.[Link]
▪ Use Cases
○ Care about order of pod deployment
○ Persistent storage
○ Unique and stable network identifier
○ Daemon Set
▪ Key Facts
○ Ensures that all or some nodes run a copy of a Pod
○ Pods for DaemonSets are scheduled by the DaemonController not the K8 Scheduler and will
be installed on all nodes in the cluster
○ DefaultScheduler can be used to limit the nodes a pod is deployed to if you use the
nodeAffinity field of the DaemonSet spec
▪ Use Cases
○ Running a cluster storage daemon on every node
○ Running a logs collection daemon on every node
○ Running a node monitoring daemon on every node
○ Job / Cronjob
▪ Key Facts
○ Jobs creates one or more Pods and ensures that the specified number of them terminate
successfully and tracks successful completions
○ Cronjobs can be used to create jobs on a repeating schedule
• Non Kubernetes
○ Get a listing of network interfaces
▪ ip link
○ Get a listing of network interfaces and the IP configuration
▪ ip addr
○ Get a listing of routes configured on a machine
▪ ip route
○ Get status of a service
▪ service <SERVICE_NAME> status
○ Get the logs of a kubelet process
▪ sudo journalctl -u kubelet
○ Location of kubelet process file for systemd
▪ /etc/systemd/system/[Link].d
• Kubernetes
○ Check the logs of a previously running Pod in case of failure
▪ kubectl logs web -f --previous
• Networking
• Services
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ClusterIP
selector:
app: myApp
ports:
- name: http
protocol: TCP
port: 80
targetPort: 9376
• Circuit Breaker
○ Pattern to account for failures with a micro-services architecture
○ Main goal is to fail fast and avoid lengthy timeouts and large queues
○ Products
▪ Istio - Blackbox approach with sidecar dropped
▪ Hystrix / Resilience4J - Whitebox approach where library is integrated into code
• Resources
○ [Link]
• Istio
○ Functions as a Service Mesh
○ Runs as a sidecar and functions as a proxy receiving traffic before passed to other container
○ Capabilities
▪ Automatic load balancing of HTTP, gRPC, WebSocket, and TCP Traffic
▪ Fine-grained control of traffic behavior with routing rules, retries, failovers, and fault
injection
▪ Pluggable policy layer and configuration API supporting access controls, rate limits,
quotas
▪ Automatic metrics, logs, traces for all traffic within a cluster which includes cluster
ingress and egress
▪ Secure service-to-service communication in a cluster with identity-based
authentication and authorization
• Hystrix / Reslience4J
○ Latency and fauilt tolerance library provided by Netflix (Resilience4J is successor)
○ Can be used to implement circuit breaker patterns