Kubernetes Part 1 Lecture PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document is a lecture on Kubernetes, providing an overview of its architecture, deployment, and containerization concepts. It covers microservices design and the underlying principles of Kubernetes.
Full Transcript
Official (Open) Kubernetes – Part 1 Official (Open) Microservice Architecture Often architected in REST-style web services Independently scalable - easier to expand or shrink one component of the system without impacting others. Main...
Official (Open) Kubernetes – Part 1 Official (Open) Microservice Architecture Often architected in REST-style web services Independently scalable - easier to expand or shrink one component of the system without impacting others. Maintain a smaller surface area of code Reduce inter-dependency between application modules Monolithic and microservice architectures Official (Open) Deploying an application with a container Solutions require something that can run anything, everywhere and is consistent, lightweight, and portable Virtual machines and containers for application deployment Official (Open) Kubernetes and Docker working together (Multiple nodes have distributions (where images are working in 1 docker) stored) Official (Open) Official definition of Kubernetes (k8s) ➔ Comes from the Greek work meaning Helmsman – the person who steers a seafaring ship ➔ Open-source container orchestration framework which was originally developed by Google ➔ Helps you manage containerized applications in different deployment environments (physical, cloud, virtual) Official (Open) Need for container orchestration tool Increased usage of containers Demand for a proper way of managing those thousands of containers What features do orchestration tools offer? M = Master (Master need to control the nodes) S = Slave High availability or no downtime Scalability or high performance Disaster recovery - backup and restore Official (Open) K8s as the Operating System of the cloud The de-facto platform for deploying and managing cloud-native applications Abstracts cloud resources and schedules application microservices Abstracts the differences between different private and public clouds Major step towards a true hybrid cloud In the cloud-native world, we just say “Hey Kubernetes, here’s an app. Please deploy it and make sure it keeps running...“. Official (Open) A quick analogy Consider process of sending goods via a courier service The only thing you need to do is package and label the goods On Kubernetes, you package the app as a container and give it a Kubernetes manifest Official (Open) Master Node Master nodes are where important k8s processes running API server = Entry point to k8s server Controller manager = keeps track of what’s happening in the cluster Scheduler = ensures Pod placement Scheduler decides which Node new pod should be scheduled ETCD = kubernetes backing store Official (Open) Worker Node or Node Node = virtual or physical machine Worker nodes = mostly just referred to as “Nodes” kubelet = primary node agent Your applications are running on worker nodes Official (Open) Master Node vs Worker Node handful of master processes much more important higher workload much bigger and more resources Official (Open) Packaging apps for Kubernetes An application needs to tick a few boxes to run on a Kubernetes cluster. These include. 1. Packaged as a container 2. Wrapped in a Pod 3. Deployed via a declarative manifest file Application code packaged as a container, running inside a Pod, managed by a Deployment controller. Official (Open) The declarative model and desired state The declarative model and the concept of desired state are at the very heart of Kubernetes. So, it’s vital you understand them. It works like this: 1. Declare the desired state of an application microservice in a manifest file 2. Post it to the API server 3. Kubernetes stores it in the cluster store as the application’s desired state 4. Kubernetes implements the desired state on the cluster 5. A controller makes sure the observed state of the application doesn’t vary from the desired state Official (Open) For example… Your app has a desired state of 10 replicas of a web front-end Pod but a node running two replicas fails… Official (Open) Getting Kubernetes Three typical ways of getting a Kubernetes: 1. Playground – Play with Kubernetes 2. Hosted Kubernetes 3. DIY install Official (Open) kubectl kubectl is the main Kubernetes command-line tool it converts user-friendly commands into HTTP REST requests with JSON required by the API server it uses a configuration file (kubeconfig) to know which cluster and API server endpoint to send commands to Kubeconfig contains: Clusters Users (credentials) Contexts Official (Open) A sample kubeconfig file Single cluster called shield Single user called coulson Single context called director You can view your kubeconfig using the kubectl config view command. Official (Open) Pod Smallest unit in Kubernetes Abstraction over container my-app db Can run one or more containers per pod IP IP Each pod gets its own IP address New IP address on re-creation Official (Open) Pods and shared networking Multi-container Pod: Single-container Pod: All containers share the IP, port range and routing table Container has full access to IP, port range and routing table Official (Open) The pod network The pod network is flat, meaning every Pod can talk directly to every other Pod without the need for complex port mappings. Official (Open) Pod immutability Pods are immutable objects – you can’t modify them after they are deployed. When updates are needed, replace all old Pods with new ones that have the updates When failures occur, replace failed Pods with new identical ones Official (Open) Pod manifest files pod.yml type of object the schema version to use for object creation where you attach things such as names, labels, annotations and Namespace define the containers the Pod will run Official (Open) kind tells Kubernetes the type of object being defined. Some commonly used objects includes: Pods Services Deployment PersistentVolume Storageclasses Namespaces Secrets ConfigMaps Official (Open) apiVersion Format is / For example: StorageClass objects -> storage.k8s.io/v1 However, Pods are in the core API group which omits the api-group part. We can describe them in YAML files as just v1 Detailed information about Kubernetes API can be found here: https://kubernetes.io/docs/reference/kubernetes-api/ Official (Open) metadata Where you attach things such as names, labels, annotations and Namespace Name: Helps to identify the object in the cluster Label: Helps to create loose couplings with other objects Annotations: Helps to integrate with 3rd part tools and services Namespace: Partition Kubernetes cluster Official (Open) spec define the container the Pod will run This example is running a container based on nigelpoulton/k8sbook:1.0 image. It is calling the container hello-ctr and exposing it on port 8080. Official (Open) kubectl commands - Pods kubectl Commands Usage kubectl apply –f Deploy pod from the manifest file kubectl get pods List the current pods kubectl describe pod Get information for the pod kubectl logs Print out the logs for the pod kubectl exec Execute commands in the pod