260 likes | 505 Views
Introduction to Kubernetes. Topics. Overview Docker containers Container orchestration Kubernetes project Architecture PODs Cluster architecture Concepts and Features Concepts (Services, Labels/Selectors) Container Network Interface (CNI) Links. Overview: Docker Containers.
E N D
Topics • Overview • Docker containers • Container orchestration • Kubernetes project • Architecture • PODs • Cluster architecture • Concepts and Features • Concepts (Services, Labels/Selectors) • Container Network Interface (CNI) • Links Northforge Innovations
Overview: Docker Containers Benefits of using containers • Rapid deployment • Sharing • Portability • Version control and component reuse • Lightweight footprint • Simpler maintenance Container Application KERNEL RAM Network CPU • Hard drive segment • bin • dev • etc • home • proc • root • ... Northforge Innovations
Overview: Container Orchestration • The orchestrator intelligently installs, starts, and stops containers on multiple nodes. • This is where Kubernetes comes into the picture Orchestrator Node Node Container Container Node Container Northforge Innovations
Overview: Kubernetes • http://kubernetes.io • Latest stable release 1.14 • Originally designed by Google • Maintained by the Cloud Native Computing Foundation (https://www.cncf.io/) • OpenSource Written in Go (https://github.com/kubernetes/kubernetes) Northforge Innovations
Overview: Why is Kubernetes needed? • Isolation: Keep jobs from interfering with each other • Scheduling: Where should my job be run? • Lifecycle: Keep my job running • Health: How is my job feeling? • Monitoring: What’s happening with my job? • Discovery: Where is my job now? • Constituency: Who is part of my job? • Scale-up: Making my jobs bigger or smaller • Auth{n,z}: Who can do things to my job? Northforge Innovations
Architecture: PODs POD • Grouping of containers with common purpose • All containers in a POD need to be tightly dependent on each other • Smallest unit that Kubernetes can deploy • Set of metadata (name, labels) for the POD • Shared Volume (persistent for container only, not for POD) • Inter-Process communication (POSIX queues, shared memories) • Inter-container network communication POD Container 1 POSIX IPC Container 2 Container 3 Volume Network (localhost) Northforge Innovations
Architecture: Kubernetes Cluster Master Components • Cluster’s control plane • These components make global decisions about the cluster, detecting and responding to cluster events. Kubernetes Master Controller Manager Scheduler API Server etcd HTTPS HTTPS Worker1 Kube Proxy Kubelet Worker2 Worker Components • Run on every node • Maintaining running pods and providing the runtime environment POD POD POD Worker3 Container Engine Northforge Innovations
Architecture: Kubernetes Cluster etcd • etcd is a distributed and consistent key-value store • The only storage backend currently supported by Kubernetes • Primary store for all Kubernetes API objects and their configuration • The etcd database also stores the actual state of the system and the desired state of the system. • Etcd has a watch functionality to monitor any changes. It monitors if actual and desired states diverge, Kubernetes will make the appropriate changes to the system. • For a demo of etcd: http://play.etcd.io/ Kubernetes Master Controller Manager Scheduler API Server etcd HTTPS HTTPS Worker1 Kube Proxy Kubelet Worker2 POD POD POD Worker3 Container Engine Northforge Innovations
Architecture: Kubernetes Cluster API Server • It is the entry point to the system. It processes REST operations, validates them, and updates the corresponding objects in etcd • kubectl CLI communicate with the API Server. • Responsible for authentication and authorization mechanism. All API clients should be authenticated in order to interact with the API Server. Kubernetes Master Controller Manager Scheduler API Server etcd HTTPS HTTPS Worker1 Kube Proxy Kubelet Worker2 POD POD POD Worker3 Container Engine Northforge Innovations
Architecture: Kubernetes Cluster Controller Manager • Watches the state of the cluster through the API Server watch feature • when it gets notified, it makes the necessary changes attempting to move the current state towards the desired state. • Example: Replication Controller, Endpoints Controller, and Namespace Controller. Kubernetes Master Controller Manager Scheduler API Server etcd HTTPS HTTPS Worker1 Kube Proxy Kubelet Worker2 POD POD POD Worker3 Container Engine Northforge Innovations
Architecture: Kubernetes Cluster Scheduler • The Kubernetes scheduler is in charge of scheduling pods onto nodes • Every pod that needs scheduling gets added to a queue • When new pods are created, they also get added to the queue • The scheduler continuously takes pods off that queue and binds them to nodes. • It schedules according to the availability of the requested resources, quality of service requirements, affinity and other constraints. • Once the pod has a node assigned, the regular behavior of the Kubelet is triggered and the pod and its containers are created Kubernetes Master Controller Manager Scheduler API Server etcd HTTPS HTTPS Worker1 Kube Proxy Kubelet Worker2 POD POD POD Worker3 Container Engine Northforge Innovations
Architecture: Create POD flow Northforge Innovations
Architecture: Kubernetes Cluster Kube Proxy • Window to the outside world • Inspect the requests and route to the appropriate service Kubernetes Master Controller Manager Scheduler API Server etcd HTTPS HTTPS Worker1 Kube Proxy Kubelet Worker2 POD POD POD Worker3 Container Engine Northforge Innovations
Architecture: Kubernetes Cluster Kubelet • The kubelet uses liveness probes to know when to restart a Container. • The kubelet uses readiness probes to know when a Container is ready to start accepting traffic. • Check types include: • Http (code 2xx or 3xx) • tcpSocket (tries tcp connection to port) • Exec • Probe is configurable: • timeoutSeconds (timeout of check in seconds) • failureThreshold (min consec failure till give up) • initialDelaySeconds (start check x seconds) • periodSeconds (check every x seconds) • successThreshold Kubernetes Master Controller Manager Scheduler API Server etcd HTTPS HTTPS Worker1 Kube Proxy Kubelet Worker2 POD POD POD Worker3 Container Engine Northforge Innovations
Architecture: Multi-Master Cluster Master 1 Master 2 Master 3 • All etcd instances will be clustered • Each API server will talk to the local etcd • Only one instance of the controllers, schedulers and auto-scaler will be active in the cluster. Etcd Cluster etcd etcd etcd Load Balancer API Server API Server API Server Scheduler Scheduler Scheduler Controller Manager Controller Manager Controller Manager Cluster Auto-scaler Cluster Auto-scaler Cluster Auto-scaler Worker1 Kube Proxy • A load balancer containing the replicas is created and the IP address of the first replica will be promoted to IP address of load balancer. • Kubelets connect to the load balancer Kubelet Worker2 POD POD POD Worker3 Container Engine Northforge Innovations
Concepts/Features: Services Service • The types of Services that can be created are: ClusterIP, NodePort, LoadBalancer, Ingress (The example on the left is for NodePort) • NodePort: Expose a container to the outside world • Nodeport: high value 30000-32767 Labels/Selectors • A service is identified by a selector • The service routes to PODs with labels matching the selector User Node NodePort Kube Proxy Service NodePort (Selector: example1) POD (Label: example2) POD (Label: example1) TargetPort X TargetPort Y Container Container Northforge Innovations
Concepts/Features: Networking Networking Plugins • Calico (https://www.projectcalico.org/) • Flanel (https://coreos.com/flannel/) • Weave (https://www.weave.works/) • Cilium (https://cilium.io/) Northforge Innovations
Links • https://kubernetes.io/docs/home/ • https://www.udemy.com/docker-and-kubernetes-the-complete-guide/ • https://github.com/kelseyhightower/kubernetes-the-hard-way • https://github.com/fabiosvaz/playground/tree/master/k8s • https://github.com/fabiosvaz/playground/tree/master/vagrant Northforge Innovations