学习资料
kubectl run testapp --image=ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s:v1
kubectl create namespace <namespace-name> kubectl cluster-info kubectl --server=https://192.168.58.2:8443 get nodes
kubectl get nodes kubectl get pod
创建文件pod.yaml,写入下面内容
pod.yaml
apiVersion: v1 kind: Pod metadata: name: test-k8s spec: # 定义容器,可以多个 containers: - name: test-k8s # 容器名字 image: ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s:v1 # 镜像
kubectl apply -f pod.yaml
kubectl get pod
NAME READY STATUS RESTARTS AGE nginx 0/1 ContainerCreating 0 8m18s test-k8s 1/1 Running 0 36s testapp 1/1 Running 3 (21m ago) 21d
apiVersion: apps/v1 kind: Deployment metadata: # 部署名字 name: test-k8s spec: replicas: 5 # 用来查找关联的 Pod,所有标签都匹配才行 selector: matchLabels: app: test-k8s # 定义 Pod 相关数据 template: metadata: labels: app: test-k8s spec: # 定义容器,可以多个 containers: - name: test-k8s # 容器名字 image: ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s:v1 # 镜像
kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx 0/1 ContainerCreating 0 11m <none> minikube <none> <none> slurm-nextflow 0/1 ContainerCreating 0 12m <none> minikube <none> <none> test-k8s 1/1 Running 0 3m37s 10.244.0.21 minikube <none> <none> test-k8s-6c97f5c8d5-22bkk 1/1 Running 0 2m2s 10.244.0.24 minikube <none> <none> test-k8s-6c97f5c8d5-7bwv8 1/1 Running 0 2m2s 10.244.0.26 minikube <none> <none> test-k8s-6c97f5c8d5-bpzft 1/1 Running 0 2m2s 10.244.0.25 minikube <none> <none> test-k8s-6c97f5c8d5-jc4ll 1/1 Running 0 2m1s 10.244.0.22 minikube <none> <none> test-k8s-6c97f5c8d5-nzm2m 1/1 Running 0 2m1s 10.244.0.23 minikube <none> <none> testapp 1/1 Running 3 (24m ago) 21d 10.244.0.17 minikube <none> <none> testapp1 1/1 Running 0 22m 10.244.0.18 minikube <none> <none>
kubectl describe pod test-k8s-6c97f5c8d5-22bkk
kubectl logs slurm-nextflow -f
kubectl exec -it slurm-nextflow -- bash
kubectl scale deployment test-k8s --replicas=10
kubectl port-forward test-k8s-6c97f5c8d5-nzm2m 8080:8080 kubectl logs test-k8s-6c97f5c8d5-nzm2m -f
# 查看历史 kubectl rollout history deployment test-k8s # 回到上个版本 kubectl rollout undo deployment test-k8s # 回到指定版本 kubectl rollout undo deployment test-k8s --to-revision=2 # 删除部署 kubectl delete deployment test-k8s
# 查看全部 kubectl get all # 重新部署 kubectl rollout restart deployment test-k8s # 命令修改镜像,--record 表示把这个命令记录到操作历史中 kubectl set image deployment test-k8s test-k8s=ccr.ccs.tencentyun.com/k8s-tutorial/test-k8s:v2-with-error --record # 暂停运行,暂停后,对 deployment 的修改不会立刻生效,恢复后才应用设置 kubectl rollout pause deployment test-k8s # 恢复 kubectl rollout resume deployment test-k8s # 输出到文件 kubectl get deployment test-k8s -o yaml >> app2.yaml # 删除全部资源 kubectl delete all --all
将 Pod 指定到某个节点运行:nodeselector限定 CPU、内存总量:文档
apiVersion: v1 kind: Pod metadata: name: nginx labels: env: test spec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent nodeSelector: disktype: ssd
工作负载分类Deployment
文档
现存问题
将节点置于不可调度状态,这意味着调度器将不会在该节点上启动新的Pods。
kubectl cordon <node-name>
驱逐节点上的所有Pods,这样它们会在另一个节点上重新调度。
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data
如果你想要将节点重新设置为可调度,可以使用 uncordon 命令:
kubectl uncordon <node-name>