一. k8s 簡介
如下圖所示 物理組成是有master和worker節點組成,目前最少搭配三台物理服務器實現 k8s高可用集群

省略,參考如下連接
https://zhuanlan.zhihu.com/p/93460345
二. k8s各組件的使用
1. deployment
1.1 新增
kubectl apply -f xx.yaml -n test
xx.yaml :部署的yaml文件,里面描述了如何創建deployment,service,pod
-n test : 命名空間 test
1.2 刪除
kubect delete deployment xx -n test
xx: deployment 的名稱
1.3 查詢
kubect get deployment -n test
1.4 修改
直接修改 xx.yaml內容 再執行應用
kubect apply -f xx.yaml -n test
2.node 物理部署節點
2.1 查詢:
kubect get node -n test
3. pod
3.1 查詢
kubect get pod -n test
3.2 新增
可以由deployment 聯動創建,也可單獨寫 pod.yaml 執行創建,執行方式如下
kubectl apply -f pod.yaml -n test
//pod.yaml可以按照這個格式書寫
apiVersion: v1
kind: Pod
metadata:
name: testpod
namespace: test
labels:
app: testpod
spec:
containers:
- name: testpod
image: test:0.0.1
ports:
- containerPort: 80 --容器端口
hostPort: 80 --暴露端口
3.3 刪除
kubectl delete pod podName -n test
3.4 修改
可以修改yaml 然后apply 應用
也可以
debug<--->running
kubectl label pod <podname> --overwrite status=debuging
kubectl label pod <podname> --overwrite status=running
3.5 通過bash方式進入到pod 容器內部 (它執行方式和docker有點類似)
kubectl exec -it podName -n test -- sh
進入到容器內部可以看容器內部的日志文件,容器里面的進程
3.6 查看日志
kubectl logs podName -n test
3.7 查看pod 節點的ip
kubectl get pod -n test -o wide
3.8 查詢詳細日志
查詢pod詳細錯誤信息
kubect describe pod podName -n test
4. service
4.1 新增
創建service
kubectl create -f service.yaml
配置文件格式:
apiVersion: v1
kind: Service
metadata:
name: testservice
namespace: test
labels:
app: testpod
spec:
type: NodePort
ports:
- port: 12345 --對應容器的端口
nodePort: 30000 --service對外暴露的端口
selector:
app: testpod
4.2 刪除
kubectl delete service testservice -n test
4.3 修改
修改xx.yaml 通過apply 應用實現
4.4.查詢
kubectl get service -n test
4.5 查詢詳細資料
kubectl describe service testservice
