0%

Kubernetes学习

Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

Tutorials

概述

Node/节点

kubernetes是用于大规模部署分布式应用的平台,管理着一系列主机或者服服务器 [被称之为**Node/节点**]

pod

每个节点运行若干相互独立的pod[**pod是Kubernetes中可以部署的最小执行单元 = 一个或者多个容器的集合**,其中运行了应用的某一部分核心的组件]

Control Plane

需要一个中心计算机来协调均衡多个pod,被称之为**Control Plane/控制平面**。控制平面通过专有API与各个节点进行通信,实时检测节点的网络状态来平衡服务器的负载或临时下发指令来应对突发的状况。

Replica Set

备用容器被称之为**Replica Set/副本集合**

Cluster/集群

以上所有节点连同control plane被称之为**Cluster/集群**

image-20220312135630781

Services/服务

NodePort

最基本的将应用端口暴露给外网的方式(还有诸如LoadBalancer, Ingress等)

Download Kubernetes

  1. Core Kubernetes components

  2. kubectl

    The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters.

    You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. For more information including a complete list of kubectl operations, see the kubectl reference documentation.

https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/

1
2
3
brew install kubectl 
# ensure the version is up-to-date
kubectl version --client

image-20220311150643812

image-20220311150717705

image-20220312125715498

Minikube

Minikube

https://minikube.sigs.k8s.io/docs/start/

https://github.com/kubernetes/minikube

brew install minikube

image-20220311212622084

We need a container runtime or virtual machine manager on laptop

Minikube has Docker pre-installed to run the containers in the cluster

​ Driver means we are hosting Minikube as a container on our local machine

2 Layers of Docker

image-20220311213805871

minikube启动

如果纯粹是为了学习和测试,使用Minikube**在本地模拟一个Kubernetes集群**(可以使用 全部功能,但不是真实的生产环境)

1
minikube start #启用本地模拟的集群

image-20220312125510277

kubectl

command line tool for k8s cluster

命令行工具kubectl来**与kubernetes集群进行交互**

全平台通用(类似docker命令行),可以操纵任何集群,包括minikube

(docker桌面版本一般自带kubectl命令)

CLI = command -line interface

1
kubectl version

image-20220312131635588

应用的部署

app deployment


首先需要创建一个yaml文件,在其中定义应用的基本信息,描述应用部署的整个过程

image-20220312130020333

比如由哪些pods组成,其中运行了哪些容器,什么网络配置

[类似dockerfile,当作一个自动化脚本]