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” 来验证其是否有效

posted @ 2020-06-28 22:25  walkingSun  阅读(570)  评论(0编辑  收藏  举报
**/