This document provides a comprehensive introduction to Kubernetes, an open-source container orchestration platform developed from Google's experience with its internal systems. It covers key concepts, such as pods, services, and various components like the control plane and node components, while detailing the architecture and networking involved in Kubernetes. Additionally, it explains how to manage workloads and utilize core objects, including namespaces, labels, and selectors in Kubernetes environments.
An introductory overview of Kubernetes, a cloud-native container orchestration platform. It references its origin, the meaning of the name, and details its version.
Details the Kubernetes project, its purpose as a container orchestration platform, and key features such as uniform API across clouds and management by CNCF.
Presents vital statistics on Kubernetes, such as GitHub stars (38,000+), contributors, user discussions, Slack participants, emphasizing its popularity.
Introduces core concepts of Pods (smallest deployable units) and Services (stable IPs/DNS names for pods), explaining their characteristics.
Describes the architecture of Kubernetes, detailing control plane components like kube-apiserver, etcd, and node components including kubelet and kube-proxy.
Explains networking aspects in Kubernetes, including Pod-to-Pod communication, service networking, and its dependency on Container Network Interface (CNI).
Covers the Kubernetes API and object model, including API versioning, object structure, and how objects represent cluster state.
Introduces essential objects such as Namespaces, Pods, Labels, and Selectors, underpinning the architecture and management of Kubernetes.
Explains workloads in Kubernetes which manage Pods, highlighting ReplicaSets, Deployments, Jobs, CronJobs, and StatefulSets with examples.
Describes how Kubernetes handles configuration using ConfigMaps and Secrets for decoupling configuration from application code.
Introduces the Kubernetes community structure, resources for further learning, meetups, and links to official documentation and courses.
What is Kubernetes? ●Project that was spun out of Google as an open source container orchestration platform. ● Built from the lessons learned in the experiences of developing and running Google’s Borg and Omega. ● Designed from the ground-up as a loosely coupled collection of components centered around deploying, maintaining and scaling workloads.
9.
What Does Kubernetesdo? ● Known as the linux kernel of distributed systems. ● Abstracts away the underlying hardware of the nodes and provides a uniform interface for workloads to be both deployed and consume the shared pool of resources. ● Works as an engine for resolving state by converging actual and the desired state of the system.
10.
What can KubernetesREALLY do? ● Autoscale Workloads ● Blue/Green Deployments ● Fire off jobs and scheduled cronjobs ● Manage Stateless and Stateful Applications ● Provide native methods of service discovery ● Easily integrate and support 3rd party apps
Who “Manages” Kubernetes? TheCNCF is a child entity of the Linux Foundation and operates as a vendor neutral governance group.
13.
Project Stats ● Over38,000 stars on Github ● 1700+ Contributors to K8s Core ● Most discussed Repository by a large margin ● 41,000+ users in Slack Team 07/2018
Pods ● Atomic unitor smallest “unit of work”of Kubernetes. ● Pods are one or MORE containers that share volumes, a network namespace, and are a part of a single context.
Services ● Unified methodof accessing the exposed workloads of Pods. ● Durable resource ○ static cluster IP ○ static namespaced DNS name
19.
Services ● Unified methodof accessing the exposed workloads of Pods. ● Durable resource ○ static cluster IP ○ static namespaced DNS name NOT Ephemeral!
kube-apiserver ● Provides aforward facing REST interface into the kubernetes control plane and datastore. ● All clients and other applications interact with kubernetes strictly through the API Server. ● Acts as the gatekeeper to the cluster by handling authentication and authorization, request validation, mutation, and admission control in addition to being the front-end to the backing datastore.
25.
etcd ● etcd actsas the cluster datastore. ● Purpose in relation to Kubernetes is to provide a strong, consistent and highly available key-value store for persisting cluster state. ● Stores objects and config information.
26.
etcd Uses “Raft Consensus” amonga quorum of systems to create a fault-tolerant consistent “view” of the cluster. https://raft.github.io/ Image Source
27.
kube-controller-manager ● Serves asthe primary daemon that manages all core component control loops. ● Monitors the cluster state via the apiserver and steers the cluster towards the desired state. List of core controllers: https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-controller-manager/app/controllermanager.go#L332
28.
kube-scheduler ● Verbose policy-richengine that evaluates workload requirements and attempts to place it on a matching resource. ● Default scheduler uses bin packing. ● Workload Requirements can include: general hardware requirements, affinity/anti-affinity, labels, and other various custom resource requirements.
kubelet ● Acts asthe node agent responsible for managing the lifecycle of every pod 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.
32.
kube-proxy ● Manages thenetwork rules on each node. ● Performs connection forwarding or load balancing for Kubernetes cluster services. ● Available Proxy Modes: ○ Userspace ○ iptables ○ ipvs (beta in 1.9)
33.
Container Runtime Engine ●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)
cloud-controller-manager ● Daemon thatprovides cloud-provider specific knowledge and integration capability into the core control loop of Kubernetes. ● The controllers include Node, Route, Service, and add an additional controller to handle things such as PersistentVolume Labels.
37.
Cluster DNS ● ProvidesCluster Wide DNS for Kubernetes Services. ○ kube-dns (default 1.10) ○ CoreDNS (future default)
Kubernetes Networking ● PodNetwork ○ Cluster-wide network used for pod-to-pod communication managed by a CNI (Container Network Interface) plugin. ● Service Network ○ Cluster-wide range of Virtual IPs managed by kube-proxy for service discovery.
42.
Container Network Interface(CNI) ● Pod networking within Kubernetes is plumbed via the Container Network Interface (CNI). ● Functions as an interface between the container runtime and a network implementation plugin. ● CNCF Project ● Uses a simple JSON Schema.
Fundamental Networking Rules ●All containers within a pod can communicate with each other unimpeded. ● 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.
47.
Fundamentals Applied ● Container-to-Container ○Containers within a pod exist within the same network namespace and share an IP. ○ Enables intrapod communication over localhost. ● Pod-to-Pod ○ Allocated cluster unique IP for the duration of its life cycle. ○ Pods themselves are fundamentally ephemeral.
48.
Fundamentals Applied ● Pod-to-Service ○managed by kube-proxy and given a persistent cluster unique IP ○ exists beyond a Pod’s lifecycle. ● External-to-Service ○ Handled by kube-proxy. ○ Works in cooperation with a cloud provider or other external entity (load balancer).
API Overview ● TheREST API is the true keystone of Kubernetes. ● Everything within the Kubernetes is as an API Object. Image Source
52.
API Groups ● Designedto make it extremely simple to both understand and extend. ● An API Group is a REST compatible path that acts as the type descriptor for a Kubernetes object. ● Referenced within an object as the apiVersion and kind. Format: /apis/<group>/<version>/<resource> Examples: /apis/apps/v1/deployments /apis/batch/v1beta1/cronjobs
53.
API Versioning ● Threetiers of API maturity levels. ● Also referenced within the object apiVersion. ● Alpha: Possibly buggy, And may change. Disabled by default. ● Beta: Tested and considered stable. However API Schema may change. Enabled by default. ● Stable: Released, stable and API schema will not change. Enabled by default. Format: /apis/<group>/<version>/<resource> Examples: /apis/apps/v1/deployments /apis/batch/v1beta1/cronjobs
54.
Object Model ● Objectsare a “record of intent” or a persistent entity that represent the desired state of the object within the cluster. ● All objects MUST have apiVersion, kind, and poses the nested fields metadata.name, metadata.namespace, and metadata.uid.
55.
Object Model Requirements ●apiVersion: Kubernetes API version of the Object ● kind: Type of Kubernetes Object ● metadata.name: Unique name of the Object ● metadata.namespace: Scoped environment name that the object belongs to (will default to current). ● metadata.uid: The (generated) uid for an object. apiVersion: v1 kind: Pod metadata: name: pod-example namespace: default uid: f8798d82-1185-11e8-94ce-080027b3c7a6
56.
Object Expression -YAML ● Files or other representations of Kubernetes Objects are generally represented in YAML. ● A “Human Friendly” data serialization standard. ● Uses white space (specifically spaces) alignment to denote ownership. ● Three basic data types: ○ mappings - hash or dictionary, ○ sequences - array or list ○ scalars - string, number, boolean etc
Object Model -Workloads ● Workload related objects within Kubernetes have an additional two nested fields spec and status. ○ spec - Describes the desired state or configuration of the object to be created. ○ status - Is managed by Kubernetes and describes the actual state of the object and its history.
Core Concepts Kubernetes hasseveral core building blocks that make up the foundation of their higher level components. Namespaces Pods Selectors Services Labels
65.
Namespaces Namespaces are alogical cluster or environment, and are the primary method of partitioning a cluster or scoping access. apiVersion: v1 kind: Namespace metadata: name: prod labels: app: MyBigWebApp $ kubectl get ns --show-labels NAME STATUS AGE LABELS default Active 11h <none> kube-public Active 11h <none> kube-system Active 11h <none> prod Active 6s app=MyBigWebApp
66.
Default Namespaces $ kubectlget ns --show-labels NAME STATUS AGE LABELS default Active 11h <none> kube-public Active 11h <none> kube-system Active 11h <none> ● default: The default namespace for any object without a namespace. ● kube-system: Acts as the home for objects and resources created by Kubernetes itself. ● kube-public: A special namespace; readable by all users that is reserved for cluster bootstrapping and configuration.
67.
Pod ● Atomic unitor smallest “unit of work”of Kubernetes. ● Foundational building block of Kubernetes Workloads. ● Pods are one or more containers that share volumes, a network namespace, and are a part of a single context.
68.
Pod Examples apiVersion: v1 kind:Pod metadata: name: multi-container-example spec: containers: - name: nginx image: nginx:stable-alpine volumeMounts: - name: html mountPath: /usr/share/nginx/html - name: content image: alpine:latest command: ["/bin/sh", "-c"] args: - while true; do date >> /html/index.html; sleep 5; done volumeMounts: - name: html mountPath: /html volumes: - name: html emptyDir: {} apiVersion: v1 kind: Pod metadata: name: pod-example spec: containers: - name: nginx image: nginx:stable-alpine ports: - containerPort: 80
69.
Key Pod ContainerAttributes ● name - The name of the container ● image - The container image ● ports - array of ports to expose. Can be granted a friendly name and protocol may be specified ● env - array of environment variables ● command - Entrypoint array (equiv to Docker ENTRYPOINT) ● args - Arguments to pass to the command (equiv to Docker CMD) Container name: nginx image: nginx:stable-alpine ports: - containerPort: 80 name: http protocol: TCP env: - name: MYVAR value: isAwesome command: [“/bin/sh”, “-c”] args: [“echo ${MYVAR}”]
70.
Labels ● key-value pairsthat are used to identify, describe and group together related sets of objects or resources. ● NOT characteristic of uniqueness. ● Have a strict syntax with a slightly limited character set*. * https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
Equality based selectorsallow for simple filtering (=,==, or !=). Selector Types Set-based selectors are supported on a limited subset of objects. However, they provide a method of filtering on a set of values, and supports multiple operators including: in, notin, and exist. selector: matchExpressions: - key: gpu operator: in values: [“nvidia”] selector: matchLabels: gpu: nvidia
75.
Services ● Unified methodof accessing the exposed workloads of Pods. ● Durable resource (unlike Pods) ○ static cluster-unique IP ○ static namespaced DNS name <service name>.<namespace>.svc.cluster.local
76.
Services ● Target Podsusing equality based selectors. ● Uses kube-proxy to provide simple load-balancing. ● kube-proxy acts as a daemon that creates local entries in the host’s iptables for every service.
77.
Service Types There are4 major service types: ● ClusterIP (default) ● NodePort ● LoadBalancer ● ExternalName
78.
ClusterIP Service ClusterIP servicesexposes a service on a strictly cluster internal virtual IP. apiVersion: v1 kind: Service metadata: name: example-prod spec: selector: app: nginx env: prod ports: - protocol: TCP port: 80 targetPort: 80
NodePort Service ● NodePortservices extend the ClusterIP service. ● Exposes a port on every node’s IP. ● Port can either be statically defined, or dynamically taken from a range between 30000-32767. apiVersion: v1 kind: Service metadata: name: example-prod spec: type: NodePort selector: app: nginx env: prod ports: - nodePort: 32410 protocol: TCP port: 80 targetPort: 80
LoadBalancer Service apiVersion: v1 kind:Service metadata: name: example-prod spec: type: LoadBalancer selector: app: nginx env: prod ports: protocol: TCP port: 80 targetPort: 80 ● LoadBalancer services extend NodePort. ● Works in conjunction with an external system to map a cluster external IP to the exposed service.
ExternalName Service apiVersion: v1 kind:Service metadata: name: example-prod spec: type: ExternalName spec: externalName: example.com ● ExternalName is used to reference endpoints OUTSIDE the cluster. ● Creates an internal CNAME DNS entry that aliases another.
Workloads Workloads within Kubernetesare higher level objects that manage Pods or other higher level objects. In ALL CASES a Pod Template is included, and acts the base tier of management.
89.
Pod Template ● WorkloadControllers manage instances of Pods based off a provided template. ● Pod Templates are Pod specs with limited metadata. ● Controllers use Pod Templates to make actual pods. apiVersion: v1 kind: Pod metadata: name: pod-example labels: app: nginx spec: containers: - name: nginx image: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx
90.
ReplicaSet ● Primary methodof managing pod replicas and their lifecycle. ● Includes their scheduling, scaling, and deletion. ● Their job is simple: Always ensure the desired number of pods are running.
91.
ReplicaSet ● replicas: Thedesired number of instances of the Pod. ● selector:The label selector for the ReplicaSet will manage ALL Pod instances that it targets; whether it’s desired or not. apiVersion: apps/v1 kind: ReplicaSet metadata: name: rs-example spec: replicas: 3 selector: matchLabels: app: nginx env: prod template: <pod template>
92.
ReplicaSet $ kubectl describers rs-example Name: rs-example Namespace: default Selector: app=nginx,env=prod Labels: app=nginx env=prod Annotations: <none> Replicas: 3 current / 3 desired Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: app=nginx env=prod Containers: nginx: Image: nginx:stable-alpine Port: 80/TCP Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 16s replicaset-controller Created pod: rs-example-mkll2 Normal SuccessfulCreate 16s replicaset-controller Created pod: rs-example-b7bcg Normal SuccessfulCreate 16s replicaset-controller Created pod: rs-example-9l4dt apiVersion: apps/v1 kind: ReplicaSet metadata: name: rs-example spec: replicas: 3 selector: matchLabels: app: nginx env: prod template: metadata: labels: app: nginx env: prod spec: containers: - name: nginx image: nginx:stable-alpine ports: - containerPort: 80 $ kubectl get pods NAME READY STATUS RESTARTS AGE rs-example-9l4dt 1/1 Running 0 1h rs-example-b7bcg 1/1 Running 0 1h rs-example-mkll2 1/1 Running 0 1h
93.
Deployment ● Declarative methodof managing Pods via ReplicaSets. ● Provide rollback functionality and update control. ● Updates are managed through the pod-template-hash label. ● Each iteration creates a unique label that is assigned to both the ReplicaSet and subsequent Pods.
94.
Deployment ● revisionHistoryLimit: Thenumber of previous iterations of the Deployment to retain. ● strategy: Describes the method of updating the Pods based on the type. Valid options are RollingUpdate or Recreate. ○ RollingUpdate: Cycles through updating the Pods according to the parameters: maxSurge and maxUnavailable. ○ Recreate: All existing Pods are killed before the new ones are created. apiVersion: apps/v1 kind: Deployment metadata: name: deploy-example spec: replicas: 3 revisionHistoryLimit: 3 selector: matchLabels: app: nginx env: prod strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 template: <pod template>
95.
RollingUpdate Deployment $ kubectlget pods NAME READY STATUS RESTARTS AGE mydep-6766777fff-9r2zn 1/1 Running 0 5h mydep-6766777fff-hsfz9 1/1 Running 0 5h mydep-6766777fff-sjxhf 1/1 Running 0 5h $ kubectl get replicaset NAME DESIRED CURRENT READY AGE mydep-6766777fff 3 3 3 5h Updating pod template generates a new ReplicaSet revision. R1 pod-template-hash: 676677fff R2 pod-template-hash: 54f7ff7d6d
96.
RollingUpdate Deployment $ kubectlget replicaset NAME DESIRED CURRENT READY AGE mydep-54f7ff7d6d 1 1 1 5s mydep-6766777fff 2 3 3 5h $ kubectl get pods NAME READY STATUS RESTARTS AGE mydep-54f7ff7d6d-9gvll 1/1 Running 0 2s mydep-6766777fff-9r2zn 1/1 Running 0 5h mydep-6766777fff-hsfz9 1/1 Running 0 5h mydep-6766777fff-sjxhf 1/1 Running 0 5h New ReplicaSet is initially scaled up based on maxSurge. R1 pod-template-hash: 676677fff R2 pod-template-hash: 54f7ff7d6d
97.
RollingUpdate Deployment $ kubectlget pods NAME READY STATUS RESTARTS AGE mydep-54f7ff7d6d-9gvll 1/1 Running 0 5s mydep-54f7ff7d6d-cqvlq 1/1 Running 0 2s mydep-6766777fff-9r2zn 1/1 Running 0 5h mydep-6766777fff-hsfz9 1/1 Running 0 5h $ kubectl get replicaset NAME DESIRED CURRENT READY AGE mydep-54f7ff7d6d 2 2 2 8s mydep-6766777fff 2 2 2 5h Phase out of old Pods managed by maxSurge and maxUnavailable. R1 pod-template-hash: 676677fff R2 pod-template-hash: 54f7ff7d6d
98.
RollingUpdate Deployment $ kubectlget replicaset NAME DESIRED CURRENT READY AGE mydep-54f7ff7d6d 3 3 3 10s mydep-6766777fff 0 1 1 5h $ kubectl get pods NAME READY STATUS RESTARTS AGE mydep-54f7ff7d6d-9gvll 1/1 Running 0 7s mydep-54f7ff7d6d-cqvlq 1/1 Running 0 5s mydep-54f7ff7d6d-gccr6 1/1 Running 0 2s mydep-6766777fff-9r2zn 1/1 Running 0 5h Phase out of old Pods managed by maxSurge and maxUnavailable. R1 pod-template-hash: 676677fff R2 pod-template-hash: 54f7ff7d6d
99.
RollingUpdate Deployment $ kubectlget replicaset NAME DESIRED CURRENT READY AGE mydep-54f7ff7d6d 3 3 3 13s mydep-6766777fff 0 0 0 5h $ kubectl get pods NAME READY STATUS RESTARTS AGE mydep-54f7ff7d6d-9gvll 1/1 Running 0 10s mydep-54f7ff7d6d-cqvlq 1/1 Running 0 8s mydep-54f7ff7d6d-gccr6 1/1 Running 0 5s Phase out of old Pods managed by maxSurge and maxUnavailable. R1 pod-template-hash: 676677fff R2 pod-template-hash: 54f7ff7d6d
100.
RollingUpdate Deployment $ kubectlget replicaset NAME DESIRED CURRENT READY AGE mydep-54f7ff7d6d 3 3 3 15s mydep-6766777fff 0 0 0 5h $ kubectl get pods NAME READY STATUS RESTARTS AGE mydep-54f7ff7d6d-9gvll 1/1 Running 0 12s mydep-54f7ff7d6d-cqvlq 1/1 Running 0 10s mydep-54f7ff7d6d-gccr6 1/1 Running 0 7s Updated to new deployment revision completed. R1 pod-template-hash: 676677fff R2 pod-template-hash: 54f7ff7d6d
101.
DaemonSet ● Ensure thatall nodes matching certain criteria will run an instance of the supplied Pod. ● They bypass default scheduling mechanisms. ● Are ideal for cluster wide services such as log forwarding, or health monitoring. ● Revisions are managed via a controller-revision-hash label.
102.
DaemonSet ● revisionHistoryLimit: Thenumber of previous iterations of the DaemonSet to retain. ● updateStrategy: Describes the method of updating the Pods based on the type. Valid options are RollingUpdate or OnDelete. ○ RollingUpdate: Cycles through updating the Pods according to the value of maxUnavailable. ○ OnDelete: The new instance of the Pod is deployed ONLY after the current instance is deleted. apiVersion: apps/v1 kind: DaemonSet metadata: name: ds-example spec: revisionHistoryLimit: 3 selector: matchLabels: app: nginx updateStrategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 template: spec: nodeSelector: nodeType: edge <pod template>
DaemonSet $ kubectl describeds ds-example Name: ds-example Selector: app=nginx,env=prod Node-Selector: nodeType=edge Labels: app=nginx env=prod Annotations: <none> Desired Number of Nodes Scheduled: 1 Current Number of Nodes Scheduled: 1 Number of Nodes Scheduled with Up-to-date Pods: 1 Number of Nodes Scheduled with Available Pods: 1 Number of Nodes Misscheduled: 0 Pods Status: 1 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: app=nginx env=prod Containers: nginx: Image: nginx:stable-alpine Port: 80/TCP Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 48s daemonset-controller Created pod: ds-example-x8kkz apiVersion: apps/v1 kind: DaemonSet metadata: name: ds-example spec: revisionHistoryLimit: 3 selector: matchLabels: app: nginx updateStrategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 template: metadata: labels: app: nginx spec: nodeSelector: nodeType: edge containers: - name: nginx image: nginx:stable-alpine ports: - containerPort: 80 $ kubectl get pods NAME READY STATUS RESTARTS AGE ds-example-x8kkz 1/1 Running 0 1m
105.
StatefulSet ● Tailored tomanaging Pods that must persist or maintain state. ● Pod identity including hostname, network, and storage WILL be persisted. ● Pod lifecycle will be ordered and follow consistent patterns.
106.
StatefulSet ● Assigned aunique ordinal name following the convention of ‘<statefulset name>-<ordinal index>’. ● Ordinal pattern is also passed to the Pod’s network Identity and volumes. ● Revisions are managed via a controller-revision-hash label
StatefulSet apiVersion: apps/v1 kind: StatefulSet metadata: name:sts-example spec: replicas: 2 revisionHistoryLimit: 3 selector: matchLabels: app: stateful serviceName: app updateStrategy: type: RollingUpdate rollingUpdate: partition: 0 template: <pod template> ● revisionHistoryLimit: The number of previous iterations of the StatefulSet to retain. ● serviceName: The name of the associated headless service; or a service without a ClusterIP.
109.
StatefulSet ● updateStrategy: Describesthe method of updating the Pods based on the type. Valid options are OnDelete or RollingUpdate. ○ OnDelete: The new instance of the Pod is deployed ONLY after the current instance is deleted. ○ RollingUpdate: Pods with an ordinal greater than the partition value will be updated in one-by-one in reverse order. apiVersion: apps/v1 kind: StatefulSet metadata: name: sts-example spec: replicas: 2 revisionHistoryLimit: 3 selector: matchLabels: app: stateful serviceName: app updateStrategy: type: RollingUpdate rollingUpdate: partition: 0 template: <pod template>
110.
StatefulSet spec: containers: - name: nginx image:nginx:stable-alpine ports: - containerPort: 80 volumeMounts: - name: www mountPath: /usr/share/nginx/html volumeClaimTemplates: - metadata: name: www spec: accessModes: [ "ReadWriteOnce" ] storageClassName: standard resources: requests: storage: 1Gi ● volumeClaimTemplates: Template of the persistent volume(s) request to use for each instance of the StatefulSet.
111.
Headless Service / #dig sts-example-0.app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> sts-example-0.app.default.svc.cluster.local +noall +answer ;; global options: +cmd sts-example-0.app.default.svc.cluster.local. 20 IN A 10.255.0.2 apiVersion: v1 kind: Service metadata: name: app spec: clusterIP: None selector: app: stateful ports: - protocol: TCP port: 80 targetPort: 80 $ kubectl get pods NAME READY STATUS RESTARTS AGE sts-example-0 1/1 Running 0 11m sts-example-1 1/1 Running 0 11m <StatefulSet Name>-<ordinal>.<service name>.<namespace>.svc.cluster.local / # dig app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> app.default.svc.cluster.local +noall +answer ;; global options: +cmd app.default.svc.cluster.local. 2 IN A 10.255.0.5 app.default.svc.cluster.local. 2 IN A 10.255.0.2 / # dig sts-example-1.app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> sts-example-1.app.default.svc.cluster.local +noall +answer ;; global options: +cmd sts-example-1.app.default.svc.cluster.local. 30 IN A 10.255.0.5
112.
Headless Service / #dig sts-example-0.app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> sts-example-0.app.default.svc.cluster.local +noall +answer ;; global options: +cmd sts-example-0.app.default.svc.cluster.local. 20 IN A 10.255.0.2 apiVersion: v1 kind: Service metadata: name: app spec: clusterIP: None selector: app: stateful ports: - protocol: TCP port: 80 targetPort: 80 $ kubectl get pods NAME READY STATUS RESTARTS AGE sts-example-0 1/1 Running 0 11m sts-example-1 1/1 Running 0 11m <StatefulSet Name>-<ordinal>.<service name>.<namespace>.svc.cluster.local / # dig app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> app.default.svc.cluster.local +noall +answer ;; global options: +cmd app.default.svc.cluster.local. 2 IN A 10.255.0.5 app.default.svc.cluster.local. 2 IN A 10.255.0.2 / # dig sts-example-1.app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> sts-example-1.app.default.svc.cluster.local +noall +answer ;; global options: +cmd sts-example-1.app.default.svc.cluster.local. 30 IN A 10.255.0.5
113.
Headless Service / #dig sts-example-0.app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> sts-example-0.app.default.svc.cluster.local +noall +answer ;; global options: +cmd sts-example-0.app.default.svc.cluster.local. 20 IN A 10.255.0.2 apiVersion: v1 kind: Service metadata: name: app spec: clusterIP: None selector: app: stateful ports: - protocol: TCP port: 80 targetPort: 80 $ kubectl get pods NAME READY STATUS RESTARTS AGE sts-example-0 1/1 Running 0 11m sts-example-1 1/1 Running 0 11m <StatefulSet Name>-<ordinal>.<service name>.<namespace>.svc.cluster.local / # dig app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> app.default.svc.cluster.local +noall +answer ;; global options: +cmd app.default.svc.cluster.local. 2 IN A 10.255.0.5 app.default.svc.cluster.local. 2 IN A 10.255.0.2 / # dig sts-example-1.app.default.svc.cluster.local +noall +answer ; <<>> DiG 9.11.2-P1 <<>> sts-example-1.app.default.svc.cluster.local +noall +answer ;; global options: +cmd sts-example-1.app.default.svc.cluster.local. 30 IN A 10.255.0.5
114.
VolumeClaimTemplate volumeClaimTemplates: - metadata: name: www spec: accessModes:[ "ReadWriteOnce" ] storageClassName: standard resources: requests: storage: 1Gi $ kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE www-sts-example-0 Bound pvc-d2f11e3b-18d0-11e8-ba4f-080027a3682b 1Gi RWO standard 4h www-sts-example-1 Bound pvc-d3c923c0-18d0-11e8-ba4f-080027a3682b 1Gi RWO standard 4h <Volume Name>-<StatefulSet Name>-<ordinal> Persistent Volumes associated with a StatefulSet will NOT be automatically garbage collected when it’s associated StatefulSet is deleted. They must manually be removed.
115.
Job ● Job controllerensures one or more pods are executed and successfully terminate. ● Will continue to try and execute the job until it satisfies the completion and/or parallelism condition. ● Pods are NOT cleaned up until the job itself is deleted.
116.
Job ● backoffLimit: Thenumber of failures before the job itself is considered failed. ● completions: The total number of successful completions desired. ● parallelism: How many instances of the pod can be run concurrently. ● spec.template.spec.restartPolicy: Jobs only support a restartPolicy of type Never or OnFailure. apiVersion: batch/v1 kind: Job metadata: name: job-example spec: backoffLimit: 4 completions: 4 parallelism: 2 template: spec: restartPolicy: Never <pod-template>
117.
Job apiVersion: batch/v1 kind: Job metadata: name:job-example spec: backoffLimit: 4 completions: 4 parallelism: 2 template: spec: containers: - name: hello image: alpine:latest command: ["/bin/sh", "-c"] args: ["echo hello from $HOSTNAME!"] restartPolicy: Never $ kubectl describe job job-example Name: job-example Namespace: default Selector: controller-uid=19d122f4-1576-11e8-a4e2-080027a3682b Labels: controller-uid=19d122f4-1576-11e8-a4e2-080027a3682b job-name=job-example Annotations: <none> Parallelism: 2 Completions: 4 Start Time: Mon, 19 Feb 2018 08:09:21 -0500 Pods Statuses: 0 Running / 4 Succeeded / 0 Failed Pod Template: Labels: controller-uid=19d122f4-1576-11e8-a4e2-080027a3682b job-name=job-example Containers: hello: Image: alpine:latest Port: <none> Command: /bin/sh -c Args: echo hello from $HOSTNAME! Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 52m job-controller Created pod: job-example-v5fvq Normal SuccessfulCreate 52m job-controller Created pod: job-example-hknns Normal SuccessfulCreate 51m job-controller Created pod: job-example-tphkm Normal SuccessfulCreate 51m job-controller Created pod: job-example-dvxd2 $ kubectl get pods --show-all NAME READY STATUS RESTARTS AGE job-example-dvxd2 0/1 Completed 0 51m job-example-hknns 0/1 Completed 0 52m job-example-tphkm 0/1 Completed 0 51m job-example-v5fvq 0/1 Completed 0 52m
118.
CronJob An extension ofthe Job Controller, it provides a method of executing jobs on a cron-like schedule. CronJobs within Kubernetes use UTC ONLY.
119.
CronJob ● schedule: Thecron schedule for the job. ● successfulJobHistoryLimit: The number of successful jobs to retain. ● failedJobHistoryLimit: The number of failed jobs to retain. apiVersion: batch/v1beta1 kind: CronJob metadata: name: cronjob-example spec: schedule: "*/1 * * * *" successfulJobsHistoryLimit: 3 failedJobsHistoryLimit: 1 jobTemplate: spec: completions: 4 parallelism: 2 template: <pod template>
120.
CronJob $ kubectl describecronjob cronjob-example Name: cronjob-example Namespace: default Labels: <none> Annotations: <none> Schedule: */1 * * * * Concurrency Policy: Allow Suspend: False Starting Deadline Seconds: <unset> Selector: <unset> Parallelism: 2 Completions: 4 Pod Template: Labels: <none> Containers: hello: Image: alpine:latest Port: <none> Command: /bin/sh -c Args: echo hello from $HOSTNAME! Environment: <none> Mounts: <none> Volumes: <none> Last Schedule Time: Mon, 19 Feb 2018 09:54:00 -0500 Active Jobs: cronjob-example-1519052040 Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 3m cronjob-controller Created job cronjob-example-1519051860 Normal SawCompletedJob 2m cronjob-controller Saw completed job: cronjob-example-1519051860 Normal SuccessfulCreate 2m cronjob-controller Created job cronjob-example-1519051920 Normal SawCompletedJob 1m cronjob-controller Saw completed job: cronjob-example-1519051920 Normal SuccessfulCreate 1m cronjob-controller Created job cronjob-example-1519051980 apiVersion: batch/v1beta1 kind: CronJob metadata: name: cronjob-example spec: schedule: "*/1 * * * *" successfulJobsHistoryLimit: 3 failedJobsHistoryLimit: 1 jobTemplate: spec: completions: 4 parallelism: 2 template: spec: containers: - name: hello image: alpine:latest command: ["/bin/sh", "-c"] args: ["echo hello from $HOSTNAME!"] restartPolicy: Never $ kubectl get jobs NAME DESIRED SUCCESSFUL AGE cronjob-example-1519053240 4 4 2m cronjob-example-1519053300 4 4 1m cronjob-example-1519053360 4 4 26s
Storage Pods by themselvesare useful, but many workloads require exchanging data between containers, or persisting some form of data. For this we have Volumes, PersistentVolumes, PersistentVolumeClaims, and StorageClasses.
124.
Volumes ● Storage thatis tied to the Pod’s Lifecycle. ● A pod can have one or more types of volumes attached to it. ● Can be consumed by any of the containers within the pod. ● Survive Pod restarts; however their durability beyond that is dependent on the Volume Type.
Volumes ● volumes: Alist of volume objects to be attached to the Pod. Every object within the list must have it’s own unique name. ● volumeMounts: A container specific list referencing the Pod volumes by name, along with their desired mountPath. apiVersion: v1 kind: Pod metadata: name: volume-example spec: containers: - name: nginx image: nginx:stable-alpine volumeMounts: - name: html mountPath: /usr/share/nginx/html ReadOnly: true - name: content image: alpine:latest command: ["/bin/sh", "-c"] args: - while true; do date >> /html/index.html; sleep 5; done volumeMounts: - name: html mountPath: /html volumes: - name: html emptyDir: {}
127.
Volumes ● volumes: Alist of volume objects to be attached to the Pod. Every object within the list must have it’s own unique name. ● volumeMounts: A container specific list referencing the Pod volumes by name, along with their desired mountPath. apiVersion: v1 kind: Pod metadata: name: volume-example spec: containers: - name: nginx image: nginx:stable-alpine volumeMounts: - name: html mountPath: /usr/share/nginx/html ReadOnly: true - name: content image: alpine:latest command: ["/bin/sh", "-c"] args: - while true; do date >> /html/index.html; sleep 5; done volumeMounts: - name: html mountPath: /html volumes: - name: html emptyDir: {}
128.
Volumes ● volumes: Alist of volume objects to be attached to the Pod. Every object within the list must have it’s own unique name. ● volumeMounts: A container specific list referencing the Pod volumes by name, along with their desired mountPath. apiVersion: v1 kind: Pod metadata: name: volume-example spec: containers: - name: nginx image: nginx:stable-alpine volumeMounts: - name: html mountPath: /usr/share/nginx/html ReadOnly: true - name: content image: alpine:latest command: ["/bin/sh", "-c"] args: - while true; do date >> /html/index.html; sleep 5; done volumeMounts: - name: html mountPath: /html volumes: - name: html emptyDir: {}
129.
Persistent Volumes ● APersistentVolume (PV) represents a storage resource. ● PVs are a cluster wide resource linked to a backing storage provider: NFS, GCEPersistentDisk, RBD etc. ● Generally provisioned by an administrator. ● Their lifecycle is handled independently from a pod ● CANNOT be attached to a Pod directly. Relies on a PersistentVolumeClaim
130.
PersistentVolumeClaims ● A PersistentVolumeClaim(PVC) is a namespaced request for storage. ● Satisfies a set of requirements instead of mapping to a storage resource directly. ● Ensures that an application’s ‘claim’ for storage is portable across numerous backends or providers.
apiVersion: v1 kind: PersistentVolume metadata: name:nfsserver spec: capacity: storage: 50Gi volumeMode: Filesystem accessModes: - ReadWriteOnce - ReadWriteMany persistentVolumeReclaimPolicy: Delete storageClassName: slow mountOptions: - hard - nfsvers=4.1 nfs: path: /exports server: 172.22.0.42 PersistentVolume ● capacity.storage: The total amount of available storage. ● volumeMode: The type of volume, this can be either Filesystem or Block. ● accessModes: A list of the supported methods of accessing the volume. Options include: ○ ReadWriteOnce ○ ReadOnlyMany ○ ReadWriteMany
133.
PersistentVolume ● persistentVolumeReclaimPolicy: The behaviourfor PVC’s that have been deleted. Options include: ○ Retain - manual clean-up ○ Delete - storage asset deleted by provider. ● storageClassName: Optional name of the storage class that PVC’s can reference. If provided, ONLY PVC’s referencing the name consume use it. ● mountOptions: Optional mount options for the PV. apiVersion: v1 kind: PersistentVolume metadata: name: nfsserver spec: capacity: storage: 50Gi volumeMode: Filesystem accessModes: - ReadWriteOnce - ReadWriteMany persistentVolumeReclaimPolicy: Delete storageClassName: slow mountOptions: - hard - nfsvers=4.1 nfs: path: /exports server: 172.22.0.42
134.
PersistentVolumeClaim ● accessModes: Theselected method of accessing the storage. This MUST be a subset of what is defined on the target PV or Storage Class. ○ ReadWriteOnce ○ ReadOnlyMany ○ ReadWriteMany ● resources.requests.storage: The desired amount of storage for the claim ● storageClassName: The name of the desired Storage Class kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-sc-example spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: slow
PV Phases Available PV isready and available to be consumed. Bound The PV has been bound to a claim. Released The binding PVC has been deleted, and the PV is pending reclamation. Failed An error has been encountered attempting to reclaim the PV.
138.
StorageClass ● Storage classesare an abstraction on top of an external storage resource (PV) ● Work hand-in-hand with the external storage system to enable dynamic provisioning of storage ● Eliminates the need for the cluster admin to pre-provision a PV
StorageClass ● provisioner: Definesthe ‘driver’ to be used for provisioning of the external storage. ● parameters: A hash of the various configuration parameters for the provisioner. ● reclaimPolicy: The behaviour for the backing storage when the PVC is deleted. ○ Retain - manual clean-up ○ Delete - storage asset deleted by provider kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: standard provisioner: kubernetes.io/gce-pd parameters: type: pd-standard zones: us-central1-a, us-central1-b reclaimPolicy: Delete
Configuration Kubernetes has anintegrated pattern for decoupling configuration from application or container. This pattern makes use of two Kubernetes components: ConfigMaps and Secrets.
145.
ConfigMap ● Externalized datastored within kubernetes. ● Can be referenced through several different means: ○ environment variable ○ a command line argument (via env var) ○ injected as a file into a volume mount ● Can be created from a manifest, literals, directories, or files directly.
146.
ConfigMap data: Contains key-valuepairs of ConfigMap contents. apiVersion: v1 kind: ConfigMap metadata: name: manifest-example data: state: Michigan city: Ann Arbor content: | Look at this, its multiline!
147.
ConfigMap Example apiVersion: v1 kind:ConfigMap metadata: name: manifest-example data: city: Ann Arbor state: Michigan $ kubectl create configmap literal-example > --from-literal="city=Ann Arbor" --from-literal=state=Michigan configmap “literal-example” created $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap file-example --from-file=cm/city --from-file=cm/state configmap "file-example" created All produce a ConfigMap with the same content! $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap dir-example --from-file=cm/ configmap "dir-example" created
148.
ConfigMap Example apiVersion: v1 kind:ConfigMap metadata: name: manifest-example data: city: Ann Arbor state: Michigan $ kubectl create configmap literal-example > --from-literal="city=Ann Arbor" --from-literal=state=Michigan configmap “literal-example” created $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap file-example --from-file=cm/city --from-file=cm/state configmap "file-example" created All produce a ConfigMap with the same content! $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap dir-example --from-file=cm/ configmap "dir-example" created
149.
ConfigMap Example apiVersion: v1 kind:ConfigMap metadata: name: manifest-example data: city: Ann Arbor state: Michigan $ kubectl create configmap literal-example > --from-literal="city=Ann Arbor" --from-literal=state=Michigan configmap “literal-example” created $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap file-example --from-file=cm/city --from-file=cm/state configmap "file-example" created All produce a ConfigMap with the same content! $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap dir-example --from-file=cm/ configmap "dir-example" created
150.
ConfigMap Example apiVersion: v1 kind:ConfigMap metadata: name: manifest-example data: city: Ann Arbor state: Michigan $ kubectl create configmap literal-example > --from-literal="city=Ann Arbor" --from-literal=state=Michigan configmap “literal-example” created $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap file-example --from-file=cm/city --from-file=cm/state configmap "file-example" created All produce a ConfigMap with the same content! $ cat info/city Ann Arbor $ cat info/state Michigan $ kubectl create configmap dir-example --from-file=cm/ configmap "dir-example" created
151.
Secret ● Functionally identicalto a ConfigMap. ● Stored as base64 encoded content. ● Encrypted at rest within etcd (if configured!). ● Ideal for username/passwords, certificates or other sensitive information that should not be stored in a container. ● Can be created from a manifest, literals, directories, or from files directly.
152.
Secret ● type: Thereare three different types of secrets within Kubernetes: ○ docker-registry - credentials used to authenticate to a container registry ○ generic/Opaque - literal values from different sources ○ tls - a certificate based secret ● data: Contains key-value pairs of base64 encoded content. apiVersion: v1 kind: Secret metadata: name: manifest-secret type: Opaque data: username: ZXhhbXBsZQ== password: bXlwYXNzd29yZA==
153.
Secret Example apiVersion: v1 kind:Secret metadata: name: manifest-example type: Opaque data: username: ZXhhbXBsZQ== password: bXlwYXNzd29yZA== $ kubectl create secret generic literal-secret > --from-literal=username=example > --from-literal=password=mypassword secret "literal-secret" created $ cat secret/username example $ cat secret/password mypassword $ kubectl create secret generic file-secret --from-file=secret/username --from-file=secret/password Secret "file-secret" created All produce a Secret with the same content! $ cat info/username example $ cat info/password mypassword $ kubectl create secret generic dir-secret --from-file=secret/ Secret "file-secret" created
154.
Secret Example apiVersion: v1 kind:Secret metadata: name: manifest-example type: Opaque data: username: ZXhhbXBsZQ== password: bXlwYXNzd29yZA== $ kubectl create secret generic literal-secret > --from-literal=username=example > --from-literal=password=mypassword secret "literal-secret" created $ cat secret/username example $ cat secret/password mypassword $ kubectl create secret generic file-secret --from-file=secret/username --from-file=secret/password Secret "file-secret" created All produce a Secret with the same content! $ cat info/username example $ cat info/password mypassword $ kubectl create secret generic dir-secret --from-file=secret/ Secret "file-secret" created
155.
Secret Example apiVersion: v1 kind:Secret metadata: name: manifest-example type: Opaque data: username: ZXhhbXBsZQ== password: bXlwYXNzd29yZA== $ kubectl create secret generic literal-secret > --from-literal=username=example > --from-literal=password=mypassword secret "literal-secret" created $ cat secret/username example $ cat secret/password mypassword $ kubectl create secret generic file-secret --from-file=secret/username --from-file=secret/password Secret "file-secret" created All produce a Secret with the same content! $ cat info/username example $ cat info/password mypassword $ kubectl create secret generic dir-secret --from-file=secret/ Secret "file-secret" created
156.
Secret Example apiVersion: v1 kind:Secret metadata: name: manifest-example type: Opaque data: username: ZXhhbXBsZQ== password: bXlwYXNzd29yZA== $ kubectl create secret generic literal-secret > --from-literal=username=example > --from-literal=password=mypassword secret "literal-secret" created $ cat secret/username example $ cat secret/password mypassword $ kubectl create secret generic file-secret --from-file=secret/username --from-file=secret/password Secret "file-secret" created All produce a Secret with the same content! $ cat info/username example $ cat info/password mypassword $ kubectl create secret generic dir-secret --from-file=secret/ Secret "file-secret" created
SIGs ● Kubernetes componentsand features are broken down into smaller self-managed communities known as Special Interest Groups (SIG). ● Hold weekly public recorded meetings and have their own mailing lists and slack channels.
Working Groups ● Similarto SIGs, but are topic focused, time-bounded, or act as a focal point for cross-sig coordination. ● Hold scheduled publicly recorded meetings in addition to having their own mailing lists and slack channels.
Conventions Europe: May 21 –23, 2010 Barcelona, Spain China: November 14-15, 2018 Shanghai, China North America: December 11 - 13, 2018 Seattle, WA 6/21/2018