天天看點

ali CNCF kubernetes基礎

新核心能力

1 存儲編排能力

2 批量執行

NODE元件

1 container runtime

2 storage plugin

3 network plugin

4 kube-proxy

k8s node 内網絡

1 The Kubernetes network proxy runs on each node.

2 This reflects services as defined in the Kubernetes API on each node and can do simple TCP, UDP, and SCTP stream forwarding or round robin TCP, UDP, and SCTP forwarding across a set of backends.

3 Service cluster IPs and ports are currently found through Docker-links-compatible environment variables specifying ports opened by the service proxy.

3.1 There is an optional addon that provides cluster DNS for these cluster IPs.

3.2 The user must create a service with the api server API to configure the proxy.

service

實作 Service 有多種方式,Kubernetes 支援 Cluster IP,上面我們講過的 kuber-proxy 的組網,它也支援 nodePort、 LoadBalancer 等其他的一些通路的能力。

API基礎

HTTP+JSON或者YAML

調用方式

1 kubectl

2 UI

3 curl

Label

1 用于Selector

2 資源集合的預設表達形式:service 對應的一組pod也是selector實作的

POD

pod 了解為程序組,實作:

1 超親密關系

2 直接的檔案交換

3 使用localhost或者socket檔案進行本地通訊

4 頻繁RPC調用

5 IPC等共享

機制

1 共享網絡

1.1 infra container-pause image

1.2 lstio會使用自己的 pause

2 共享存儲

2.1 volume 挂着pod級别

例子

1 war包和tomcat 分開image,部署到一個pod

2 initContainer的使用:嚴格按定義順序執行

SdieCar

1 initContainer的使用

2 嚴格按定義順序執行:在POD内定義專門容器,來執行主業務容器需要的輔助工作

3 輔助工作舉例

1 擴充卡-控制-修改對外開發端口(内容)

2 代理容器-控制外部通路

3 需要ssh執行的腳本

4 debug 應用

5 應用監控

6 日志收集

4 解耦和重用

資源對象

1 spec

2 status:runtime

3 Metadata

3.1 annotations

3.1.1 存儲資源的非辨別性資訊

3.1.2 擴充資源的spect、status

3.1.3 特點

3.1.3.1 比lebel更大

3.1.3.2 可以有特殊字元

3.1.3.3 可以結構化也可以非結構化

3.2 onwer eference

3.2.1 集合類資源

3.2.2 replicaset、statefulset

3.2.3 友善反向查找建立資源的對象

3.2.4 友善進行級聯删除

3.3 labeles

3.3.1 用于篩選資源

3.3.2 唯一的組合資源的方法

3.3.3 用于selector query

3.3.4 預設and關系

3.3.5 支援in ‘env in (t.b)’

3.3.6 The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (), dots (.), and alphanumerics between.

3.3.7 The kubernetes.io/ and k8s.io/ prefixes are reserved for Kubernetes core components.

3.3.8 values must be 63 characters or less and must be empty or begin and end with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (), dots (.), and alphanumerics between.

聲明式指令優勢

1 記錄了狀态

2 幂等操作、可以反複操作

3 正常操作即巡檢

4 可以合并多個變更

控制循環

sensor

reflector

1 list * watch

2 watch為增量動作

3 send data to Delta Queue:Delta 保證同一對象隻有一個記錄

informer

1 調用callback

2 彈出對象

3 資料交給indexer

indexer

1 controller 從indexer擷取資料

2 維護一個工作隊列

3 K/V

controller的workqueue

一個controller的workqueue一般隻存儲一種類型資源的名稱

可以參考:https://www.kubernetes.org.cn/3655.html

Informer:

1 跟API server保持通訊擷取資源的最新狀态并更新到本地的cache中,一旦跟蹤的資源有變化,informer就會調用callback。把關心的變更的Object放到workqueue裡面

2 Controller可以有一個或多個informer來跟蹤某一個resource

Woker: woker執行真正的業務邏輯

控制器模式

1 聲明式API

2 異步實作,最終一緻

3 使系統的自動化及無人值守成為可能

4 便于擴充-自定義資源和控制器 : CRD+operator