--- title: Introduction to Kubernetes image: https://i.imgur.com/jvrZKzm.png --- :::warning # <center><i class="fa fa-book"></i> Introduction to Kubernetes </center> ::: ###### tags: `study` `Kubernetes` ![](https://i.imgur.com/jvrZKzm.png =500x) <!-- <font class="highlight"> --> <!-- <font class="title"> --> <!-- 縮寫提示 --> <!-- *[O-RAN]:Open Radio Access Network --> :::success **🎯 Goals:** - [x] - <a href="#12-Kubernetes-Architecture">To know Kubernetes Architecture</a> - [x] - <a href="#Module-2-Basic-concept">To know the basic concept</a> - [x] - <a href="#Module-3-Benefits-of-Kubernetes">To know the benefits of Kubernetes</a> - [x] - <a href="#Module-4-Summary">Summary </a> ::: :::info :bookmark: **Reference:** - [[video] Friendly Introduction to Containers](https://www.youtube.com/watch?v=O-S1JGVS1X0&t=8s) --- :link: **++Links++ to my notes on the same topic** - [![](https://i.imgur.com/7DC4LFX.png =200x)](/@MingHung/Docker) &emsp;&emsp;&emsp;[![](https://i.imgur.com/dLRpxGH.png =x110)](/@MingHung/Helm) ::: [toc] # Module 1: Introduce ## 1.1 What the Kubernetes - **If there are ==many Containers== that need to be managed together** - One of the Containers has a problem and needs to be fixed in time. - The updated version needs to be seamlessly replaced with the new version file. ![](https://i.imgur.com/jHJOBDP.png =500x) - Automated deployment - Extend and manage multiple containers (Container) - Stable container environment - Manage resource or permission assignments ## 1.2 Kubernetes Architecture ![](https://i.imgur.com/i2Lx43l.png) - **The relationship between each level:** <!-- ```graphviz digraph Kubernetes { rankdir = LR nodesep = 1.0 // increases the separation between nodes node [color=black,fontname="微軟正黑體",shape=box, style="rounded,filled", fillcolor=gray] //All nodes will this shape and colour edge [color=black, style=dashed] //All the lines look like this Cluster->Master Master->WorkerNode WorkerNode->Pod Pod->Container } ``` --> ![](https://i.imgur.com/GbTLrdl.png) <!-- ![](https://i.imgur.com/2uaQa6r.png) --> ## 1.3 Compared to Docker Swarm :::danger - Docker Swarm must be built under the ++**Docker**++ architecture, and the function is limited ::: ### 1.3.1 K8S - 🟩 Can **support a variety** of Container tools, such as Docker, Rocket - 🟥 If the project needs to use Docker-Compose, it needs to be **converted** first. ### 1.3.2 Docker Swarm - [[ Link to Introduction ]](/@MingHung/Docker#27-Docker-Swarm) - 🟥 Containers that **only support Docker** - 🟩 Can use Docker-Compose **directly** # Module 2: Basic concept ## 2.1 Container :::info **Include:** - Associated system programs required by the application - Necessary executable ::: ### 2.1.1 Container Status ```cmd= kubectl describe <pod_name/pod_id> -n <namespace> ``` | Status | Description | |:---------- | ------------------------------------------------------------------------- | | Waiting | The Container is still in the process of starting the required operation. | | <span style="color:#FFF;background:#33cc33; border-radius:8px; padding: 3px 9px;"> Running </span> | The container is executing state and no problems occurred. | | Terminated | The container ended normally or failed for some reason. | ## 2.2 Pod :::info - The **smallest unit** in which Kubernetes operates - Can contain **one or more** Containers - Corresponding to an application - Containers in a Pod will **share** the same network resources (such as IP addresses, host names, etc.) ::: ### 2.2.1 Pod State | Status | Description | |:--------- |:------------------------------------------------------------------------------------------------------------------------- | | <span style="color:#FFF;background:orange; border-radius:8px; padding: 3px 9px;"> Pending </span> | Pods have been accepted by the Kubernetes system <br>but containers have not yet been created. | | <span style="color:#FFF;background:#33cc33; border-radius:8px; padding: 3px 9px;"> Running </span> | All containers in the Pod have been created<br> some containers are still running, or are in the startup or restart state. | | <span style="color:#FFF;background:#33cc33; border-radius:8px; padding: 3px 9px;"> Succeeded </span> | All containers in the Pod have terminated successfully and will not be restarted. | | <span style="color:#FFF;background:indianred; border-radius:8px; padding: 3px 9px;"> Failed </span> | Fail to terminate. | | <span style="color:#FFF;background:gray; border-radius:8px; padding: 3px 9px;"> Unknow </span> | Unable to get the status of the Pod. | ## 2.3 Namespaces ![](https://i.imgur.com/UebjTmM.png) - Namespaces allow to **split-up resources** into different groups. - Resource names should be **unique** in a namespace - We can use namespaces to create multiple environments like dev, staging and production etc - Kubernetes will always list the resources from `default namespace` unless we provide exclusively from which namespace we need information from. ## 2.4 Worker Node (Node) :::info - The running node of the **main** execution - Corresponding to a machine - **Contains three components:** - kubelet - kube-proxy - Container Runtime ::: ### 2.4.1 kubelet :::warning - **Administrator** of Node - Manage the state of **all Pods** on this Node - Communicate with Master ::: ### 2.4.2 kube-proxy :::warning - Node's **messenger** - Keep the outside world informed of the latest status of all Pods on the Node ::: ### 2.4.3 Container Runtime :::warning - The program that is actually responsible for the **execution** of the container > Take Docker container as an example, its corresponding is **Docker Engine** ::: ## 2.5 Master Node (Master) :::info - **Manage** Worker Nodes - **Contains four components:** - kube-apiserver - etcd - kube-scheduler - kube-controller-manager ::: ### 2.5.1 kube-apiserver :::warning - An interface to the **API** required to manage the entire Kubernetes - Responsible for the **communication bridge between Nodes** - Requested Authentication and Authorization ::: ### 2.5.2 etcd :::warning - Store data as a **backup** ::: ### 2.5.3 kube-controller-manager :::warning - Responsible for managing and running the **Kubernetes controller** - > controller : Process responsible for monitoring Cluster status - Monitoring and trying to update also need to be achieved by accessing [(1.4.2.1) kube-apiserver](#1421-kube-apiserver) ::: ### 2.5.4 kube-scheduler :::warning - Pods scheduler - Coordinate a Node that is most suitable for placement to let the Pod run ::: ## 2.6 Cluster :::info - The unit that aggregates all Nodes in the same environment - A collection of multiple Nodes and Masters - This cluster is sort of like a central nervous system for your application ::: ## 2.7 Logs ### 2.7.1 Get all namespace & pod name ```cmd= kubectl get pod -A ``` ![](https://i.imgur.com/OVRVv0Q.jpg) ### 2.7.2 Log This will be the real-time monitoring screen, you need to press **Ctrl + C or Ctrl + Z** ```cmd= kubectl logs -f -n <namespace> <pod name> ``` ### 2.7.3 Describe pod ```cmd= kubectl describe pod -n <namespace> <pod name> ``` # Module 3: Benefits of Kubernetes :::success - **Automate management, restart, expand** 1. Automatically **detect** and **manage** the status of each Container 2. Perform **auto-scaling** on Container 3. Automatically restarts the Container when an error is detected to ensure that the service **continues to run** ::: - Deploy **multiple containers** to one machine at the same time, or even multiple machines. - **Manage the state of each container.** If a container providing a service crashes accidentally, Kubernetes will detect and restart the container to ensure continuous service delivery - **Move all containers from one machine to another.** - A Kubernetes cluster can be extended from one machine to multiple machines running together. # Module 4: Summary Kubernetes (K8S) is an open source system designed by Google to automate the deployment, expansion and management of containerized applications. It supports a variety of different container tools such as Docker, etc. ---- <!-- >**Name**: `名稱` --> <style> .alert-info img{ background-color: #fff0 } /* 僅指定連結的圖片去背且靠右模擬置中 */ img[src^="https://i.imgur.com/jvrZKzm.png"]{ position: relative; left: 17%; background-color: #fff0; } .title { color: #009933; font-weight:bold; } .highlight { color: #ff4d4d; font-weight:bold; border-bottom:2px red solid; padding-bottom:2px; } </style>