負責master和節點(node)之間的通訊、交互和數據上報 到master的apiservernode
總體來說 的職責是
一、Node管理
二、pod管理
三、容器健康檢查
四、容器監控
五、資源清理
六、和容器運行時交互(docker 、rkt、Virtlet等等)nginx
通常狀況下kubectl會暴露 10250端口 用於和apiserver 交互
經常使用的查詢API
GET
/pods
/stats/summary
/metrics
/healthzweb
訪問方式:
docker exec -it kubelet curl -k https://localhost:10250/healthz --header "Authorization: Bearer kubeconfig-user-mtxnk.c-gfv2c:h86t2zzpjcq8lksd82l24l6ld7pkdwsh4264thvbfxldntkmdmf2c8" docker
外部經過NodePort、ClusterIP等方式訪問服務。api
kube-proxy 運行在每一個Node 上,負責Pod網絡代理, 維護網絡規則和四層負載均衡工做 網絡
在master中。
kube-controller-manager負責節點管理、pod複製和endpoint建立.
監控集羣中各類資源的狀態使之和定義的狀態保持一致,.app
如:
節點控制器(Node Controller): 負責在節點出現故障時進行通知和響應。負載均衡
副本控制器(Replication Controller): 負責爲系統中的每一個副本控制器對象維護正
確數量的 Pod。(如今是Deployment Controller+Replication Set)curl
apiVersion: apps/v1 kind: Deployment metadata: name: myngx namespace: myweb spec: selector: matchLabels: app: nginx replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginxtest image: nginx:1.18-alpine # 只有鏡像不存在時進行鏡像拉取 imagePullPolicy: IfNotPresent ports: # Pod 端口 - containerPort: 80
kubectl create -f ngx.yamlurl
apiVersion: apps/v1 kind: Deployment metadata: #元數據 name: myngx namespace: myweb spec: selector: #標籤選擇器 matchLabels: app: nginx #自定義標籤 replicas: 1 template: #定義模板 metadata: labels: app: nginx #和上面matchLables的app對應 spec: #定義容器 containers: - name: nginxtest image: nginx:1.18-alpine # 只有鏡像不存在時進行鏡像拉取 imagePullPolicy: IfNotPresent ports: # Pod 端口 - containerPort
查看deployment
kubectl get deployment -n myweb
刪除deployment
kubectl delete deployment myngx -n myweb
建立service
apiVersion: v1 kind: Service metadata: name: myngx-service spec: selector: app: nginx #這個和前面的app也是對應 ports: - protocol: TCP port: 80 targetPort: 80 type: ClusterIP #ClusterIP、NodePort和LoadBalancer
指定主機名稱的方式
一、直接添加 nodeName : xxxx
二、根據標籤
kubectl get node --show-labels
添加標籤:
kubectl label nodes <node-name> <label-key>=<label-value>
kubectl label nodes dsjs name=a1
kubectl label nodes dsjs2 name=a2
刪除標籤:
kubectl label nodes <node-name> <label-key>-
kubectl label nodes dsjs name-
修改標籤:kubectl label nodes <node-name> <label-key>=<label-value> --overwrite