Professional Documents
Culture Documents
Kubernetes v1.18
Agenda
● Introduction ● Concepts
○ Who am I? ○ Core
○ What is Kubernetes? ○ Workloads
○ What does Kubernetes do? ○ Network
● Architecture ○ Storage
○ Master Components ○ Configuration
○ Node Components ○ Auth and Identity
○ Additional Services
○ Networking
@moficodes
Mofizur Rahman
Developer Advocate, IBM @moficodes
Do Container Stuff,
Collect Stickers,
Write go code
What is Kubernetes?
@moficodes
What is Kubernetes?
API to Compute Resources
Modeled after Borg from google
Open source project under CNCF
@moficodes
What Does Kubernetes
do?
@moficodes
What Does Kubernetes do?
Kubernetes is the linux kernel of distributed systems.
It abstracts away the underlying hardware of the nodes and provides a uniform
interface for applications to be both deployed and consume the shared pool of
resources.
@moficodes
Kubernetes Architecture
@moficodes
Overview
@moficodes
Masters
@moficodes
Architecture Overview
Masters - Acts as the primary control plane for Kubernetes. Masters are
responsible at a minimum for running the API Server, scheduler, and cluster
controller. They commonly also manage storing cluster state, cloud-provider
specific components and other cluster essential services.
@moficodes
Nodes
@moficodes
Architecture Overview
Nodes - Are the ‘workers’ of a Kubernetes cluster. They run a minimal agent that
manages the node itself, and are tasked with executing workloads as designated
by the master.
@moficodes
UI Node 1
Node 2
Node 3
CLI Node n
@moficodes
Kubernetes Master
No
Cloud No
Scheduler Controller
Controller
API
API Server
No
@moficodes
Kubernetes Master
No
Cloud
Scheduler Controller
Controller
No
API Server
API
@moficodes
UI Node 1
Node 2
Node 3
CLI Node n
@moficodes
Node 1,2,3,n
Pod Pod
Pod
Pod
Master Pod
Pod Pod
Pod
@moficodes
Master
Components
@moficodes
Kubernetes Master
Cloud
Scheduler Controller
Controller
API Server
@moficodes
Master Components
● Kube-apiserver
● Etcd
● Kube-controller-manager
● Cloud-controller-manager
● Kube-scheduler
@moficodes
kube-apiserver
Forward facing REST interface into the kubernetes control plane and datastore.
All clients interact with kubernetes strictly through the API Server.
Handles authentication and authorization, request validation, mutation, and
admission control
@moficodes
etcd
Cluster datastore
Provides a strong, consistent and highly available key-value store used for
persisting cluster state.
@moficodes
kube-controller-manager
Manages all core component control loops.
Monitors the cluster state via the apiserver and steers the cluster towards the
desired state.
@moficodes
cloud-controller-manager
Provides cloud-provider specific knowledge and integration capability into the
core control loop of Kubernetes.
Includes Node, Route, Service, and add an additional controller to handle
PersistentVolumeLabels .
@moficodes
kube-scheduler
Verbose policy-rich engine that evaluates workload requirements and attempts
to place it on a matching resource.
These requirements can include such things as general hardware reqs, affinity,
anti-affinity, and other custom resource requirements.
@moficodes
Node Components
@moficodes
Node 1,2,3,n
Pod Pod
Pod
Pod
Pod
Pod Pod
Pod
@moficodes
Node Components
● Kubelet
● Kube-proxy
● Container runtime engine
@moficodes
kubelet
Acts as the node agent responsible for managing pod lifecycle on its host.
Kubelet understands YAML container manifests that it can read from several
sources:
● File path
● HTTP Endpoint
● Etcd watch acting on any changes
● HTTP Server mode accepting container manifests over a simple API.
@moficodes
kube-proxy
Manages the network rules on each node and performs connection forwarding or
load balancing for Kubernetes cluster services.
● Userspace
● iptables
● ipvs (alpha in 1.8)
@moficodes
Container Runtime
With respect to Kubernetes, A container runtime is a CRI (Container Runtime
Interface) compatible application that executes and manages containers.
● Containerd (docker)
● Cri-o
● Rkt
● Kata (formerly clear and hyper)
● Virtlet (VM CRI compatible runtime)
@moficodes
Additional Services
Kube-dns - Provides cluster wide DNS Services. Services are resolvable to
<service>.<namespace>.svc.cluster.local.
Heapster - Metrics Collector for kubernetes cluster, used by some resources
such as the Horizontal Pod Autoscaler. (required for kubedashboard metrics)
Kube-dashboard - A general purpose web based UI for kubernetes.
@moficodes
Networking
@moficodes
Networking - Fundamental Rules
● All Pods can communicate with all other Pods without NAT
● All nodes can communicate with all Pods (and vice-versa) without NAT.
● The IP that a Pod sees itself as is the same IP that others see it as.
@moficodes
Networking - Fundamentals Applied
Containers in a pod exist within the same network namespace and share an IP;
allowing for intrapod communication over localhost.
Pods are given a cluster unique IP for the duration of its lifecycle, but the pods
themselves are fundamentally ephemeral.
@moficodes
Networking - Fundamentals Applied
Services are given a persistent cluster unique IP that spans the Pods lifecycle.
@moficodes
Networking
CNI
@moficodes
Networking - CNI
Networking within Kubernetes is plumbed via the Container Network Interface (CNI), an interface
between a container runtime and a network implementation plugin.
@moficodes
Compatible CNI Network Plugins:
● Calico ● kube-router
● Cillium ● Multus
● Contiv ● OpenVSwitch
● Contrail ● OVN
● Flannel ● Romana
● GCE ● Weave
@moficodes
Kubernetes Concepts
@moficodes
Kubernetes Concepts - Core
Cluster - A collection of hosts that aggregate their available resources including cpu,
ram, disk, and their devices into a usable pool.
Master - The master(s) represent a collection of components that make up the control
plane of Kubernetes. These components are responsible for all cluster decisions
including both scheduling and responding to cluster events.
@moficodes
Kubernetes Concepts - Core
Node - A single host, physical or virtual capable of running pods. A node is managed
by the master(s), and at a minimum runs both kubelet and kube-proxy to be
considered part of the cluster.
@moficodes
Concepts - Core (cont.)
Label - Key-value pairs that are used to identify, describe and group together related sets
of objects. Labels have a strict syntax and available character set. *
Selector - Selectors use labels to filter or select objects. Both equality-based (=, ==, !=) or
simple key-value matching selectors are supported.
@moficodes
* https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
Labels, and Annotations, and Selectors
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
Annotations
annotations:
description: "nginx application"
description: “nginx frontend”
labels:
app: nginx
tier: frontend Labels:
spec:
replicas: 1 app: nginx
selector:
matchLabels: tier: frontned
app: nginx
tier: frontend
template:
metadata:
selector:
labels:
app: nginx
matchLabels:
tier: frontend app: nginx
spec:
containers: tier: frontend
- name: nginx
image: nginx:latest
@moficodes
Set-based selectors
Valid Operators:
● In
● NotIn
● Exists
● DoesNotExist
@moficodes
Concepts - Workloads
Pod - A pod is the smallest unit of work or management resource within Kubernetes. It is
comprised of one or more containers that share their storage, network, and context
(namespace, cgroups etc).
@moficodes
Concepts - Workloads (cont)
ReplicaSet - Next Generation ReplicationController. Supports set-based selectors.
@moficodes
Replicaset
apiVersion: apps/v1
Generated ReplicaSet from Deployment spec. kind: Replicaset
metadata:
name: nginx
annotations:
description: "nginx application"
labels:
app: nginx
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
app: nginx
tier: frontend
template:
metadata:
labels:
app: nginx
tier: frontend
spec:
containers:
- name: nginx
image: nginx:latest
@moficodes
Deployment
apiVersion: apps/v1
Contains configuration of how updates or kind: Deployment
metadata:
‘deployments’ should be managed in addition to the name: nginx
@moficodes
Concepts - Workloads (cont.)
StatefulSet - A controller tailored to managing Pods that must persist or maintain state. Pod
identity including hostname, network, and storage will be persisted.
DaemonSet - Ensures that all nodes matching certain criteria will run an instance of a
supplied Pod. Ideal for cluster wide services such as log forwarding, or health monitoring.
@moficodes
StatefulSet
Attaches to ‘headeless service’ (not shown) nginx.
Pods given unique ordinal names using the pattern <statefulset name>-<ordinal index>.
@moficodes
DaemonSet
apiVersion: apps/v1
Bypasses default scheduler kind: DaemonSet
metadata:
Schedules a single instance on every host while name: fluentd
spec:
adhering to tolerances and taints. selector:
matchLabels:
name: fluentd
template:
metadata:
labels:
name: fluentd
spec:
nodeSelector:
type: prod
containers:
- name: fluentd
image: gcr.io/google-containers/fluentd-elasticsearch:1.20
@moficodes
Concepts - Workloads (cont.)
Job - The job controller ensures one or more pods are executed and successfully
terminates. It will do this until it satisfies the completion and/or parallelism condition.
@moficodes
Jobs
● Number of pod executions can be controlled apiVersion: batch/v1
via spec.completions kind: Job
metadata:
● Jobs can be parallelized using
name: name
spec.parallelism spec:
● Jobs and Pods are NOT automatically cleaned template:
up after a job has completed. metadata:
name: name
spec:
containers:
- name: hello
image: alpine:latest
command: ["echo", "hello world"]
@moficodes
CronJob
● Adds cron schedule to job template apiVersion: batch/v1
kind: CronJob
● Uses the cron syntax metadata:
name: hello
spec:
schedule: "30 8 * * *"
jobTemplate:
* * * * * spec:
template:
metadata:
minute hour day month day
name: name
(month) (week) spec:
containers:
- name: hello
image: alpine:latest
command: ["echo", "hello world"]
@moficodes
Concepts - Network
Service - Services provide a method of exposing and consuming L4 Pod network
accessible resources. They use label selectors to map groups of pods and ports to a cluster-
unique virtual IP.
Ingress - An ingress controller is the primary method of exposing a cluster service (usually
http) to the outside world. These are load balancers or routers that usually offer SSL
termination, name-based virtual hosting etc.
@moficodes
Service
Acts as the unified method of accessing apiVersion: v1
replicated pods. kind: Service
metadata:
name: nginx
Four major Service Types:
spec:
● CluterIP selector:
● NodePort app: nginx
● LoadBalancer ports:
● ExternalName - port: 80
targetPort: 80
@moficodes
Ingress Controller
● Deployed as a pod to one or more hosts apiVersion: networking.k8s.io/v1beta1
kind: Ingress
● Ingress controllers are an external controller metadata:
with multiple options. name: test-ingress
○ annotations:
Nginx
nginx.ingress.kubernetes.io/rewrite-target: /
○ HAproxy spec:
○ Contour rules:
○ Traefik - http:
● Specific features and controller specific paths:
- path: /server
configuration is passed through annotations. pathType: Prefix
backend:
serviceName: nginx
servicePort: 80
@moficodes
Concepts - Storage
Volume - Storage that is tied to the Pod Lifecycle, consumable by one or more containers within
the pod.
@moficodes
Concepts - Configuration
ConfigMap - Externalized data stored within kubernetes that can be referenced as a
commandline argument, environment variable, or injected as a file into a volume mount.
Ideal for separating containerized application from configuration.
@moficodes
ConfigMaps and Secrets
● Can be used in Pod Config: apiVersion: v1
kind: Secret
○ Injected as a file
metadata:
○ Passed as an environment variable name: secretName
○ Used as a container command (requires data:
passing as env var) secretKey: BASE64_ENCODED_VALUE
type: Opaque
---
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfigmap
labels:
app: myapplication
data:
my-key: my-value
@moficodes
Concepts - Auth and Identity (RBAC)
[Cluster]Role - Roles contain rules that act as a set of permissions that apply verbs like
“get”, “list”, “watch” etc over resources that are scoped to apiGroups. Roles are scoped to
namespaces, and ClusterRoles are applied cluster-wide.
@moficodes
Concepts - Auth and Identity (RBAC)
ServiceAccount- ServiceAccounts provide a consumable identity for pods or external
services that interact with the cluster directly and are scoped to namespaces.
@moficodes
[Cluster]Role
● Permissions translate to url path. With “” apiVersion: rbac.authorization.k8s.io/v1
defaulting to core group. kind: Role
metadata:
● Resources act as items the role should be
namespace: default
granted access to.
name: pod-reader
● Verbs are the actions the role can perform on rules:
the referenced resources. - apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]
@moficodes
[Cluster]RoleBinding
● Can reference multiple subjects apiVersion: rbac.authorization.k8s.io/v1
● Subjects can be of kind: kind: RoleBinding
○ User metadata:
○ Group name: read-pods
○ ServiceAccount namespace: default
subjects:
● roleRef targets a single role only.
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
@moficodes
Can ?
Subject Verb Object
@moficodes
Can User
? List Pods
@moficodes
Can User List
? Pods In Namespace
@moficodes
Demo
@moficodes
Questions?
@moficodes