kebectl 部署常用操作

kebectl 部署常用操作

起deployment、service、cronJob、ingress

kubectl apply -f web-click.yaml

delete

kubectl delete -f web-click.yaml

獲取deployment

kubectl get deployment --namespace=bigdata

pod

kubectl get pods --namespace=bigdata |grep adc

查看pod日誌

kubectl logs adc-web-click-5f64b5fc-6qs6w -n bigdata

刪除deployment

kubectl delete deployment adc-web-click --namespace=bigdata

查找服務

kubectl get svc -n bigdata

刪除服務

kubectl delete svc adc-web -n bigdata

查看詳細信息

kubectl describe pods adc-web-click-5f64b5fc-5v5n4 -n bigdata

查看ingress

kubectl get ingress -n bigdata
kubectl describe ingress adc-ingress -n bigdata

cronjob查看

kubectl get cronjob smcheck-cronjob -n bigdata

監控job

kubectl get jobs --watch -n bigdata

Replace "hello-4111706356" with the job name in your system

pods=$(kubectl get pods --selector=job-name=smcheck-cronjob-1589540820 --output=jsonpath={.items[*].metadata.name})

kubectl get pods --selector=job-name=smcheck-cronjob-1589540640

smcheck-cronjob-1589536140y

查看容器

kubectl exec -it [pod name] --container [container name] -n [namespace] [執行命令]

kubectl exec -it callbackconsume-job-758874f99d-pgmtf --container adc-callback -n bigdata ls config/debug

查看日誌

kubectl logs callbackconsume-job-758874f99d-pgmtf -n bigdata

將pod分配給節點

https://kubernetes.io/zh/docs/concepts/configuration/assign-pod-node/

查看節點 顯示標籤

kubectl get nodes --show-labels

添加標籤

kubectl label nodes <node-name> <label-key>=<label-value>

添加 nodeSelector 字段到 pod 配置中

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd

kubectl apply -f https://k8s.io/examples/pods/pod-nginx.yaml 命令,pod 將會調度到將標籤添加到的節點上。
可以通過運行 kubectl get pods -o wide 並查看分配給 pod 的 “NODE” 來驗證其是否有效

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章