{"id":234,"date":"2020-02-29T16:06:43","date_gmt":"2020-02-29T08:06:43","guid":{"rendered":"http:\/\/118.25.47.203\/?page_id=234"},"modified":"2025-12-26T10:53:44","modified_gmt":"2025-12-26T02:53:44","slug":"three","status":"publish","type":"page","link":"https:\/\/blog.ywdevops.cn\/index.php\/three\/","title":{"rendered":"k8s\u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>kubectl get all -n kube-system  \/\/\u67e5\u770b\u6b64\u547d\u540d\u7a7a\u95f4\u4e0b\u7684\u5168\u90e8\u8d44\u6e90<\/li>\n\n\n\n<li>kubectl get po -n kube-system  \/\/\u67e5\u627e\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\u7684pod,pod\u540d\u79f0\u4e00\u822c\u4ee5deployment\u5bf9\u5e94\u7684replicaset\u540d\u79f0\u4f5c\u4e3a\u524d\u7f00<\/li>\n\n\n\n<li>kubectl get nodes          \/\/\u67e5\u8be2\u8282\u70b9\u72b6\u6001\u4fe1\u606f<\/li>\n\n\n\n<li>kubectl get po -n A   \/\/\u67e5\u8be2\u6240\u6709\u547d\u540d\u7a7a\u95f4\u7684po\u4fe1\u606f<\/li>\n\n\n\n<li>kubectl get  ns           \/\/\u67e5\u8be2\u6240\u6709\u7684\u547d\u540d\u7a7a\u95f4<\/li>\n\n\n\n<li>kubectl get   deployments   \/\/\u67e5\u770bdeployment\u4fe1\u606f<\/li>\n\n\n\n<li>kubectl get rs   -n test   \/\/\u67e5\u770b ReplicaSet\u540d\u79f0\uff0c\u547d\u540d\u4e0edeploy\u540d\u79f0\u6709\u5173<\/li>\n\n\n\n<li> kubectl get svc -n test   \/\/\u67e5\u770bservice\u4fe1\u606f<\/li>\n\n\n\n<li> kubectl get svc -n test   -o yaml    \/\/\u67e5\u770bservice\u4fe1\u606f\uff0c\u901a\u8fc7yaml\u683c\u5f0f\u663e\u793a<\/li>\n\n\n\n<li>kubectl delete -i svc \u540d\u5b57 -n test   \/\/\u5220\u9664\u540d\u79f0\u7a7a\u95f4test\u4e2d\u6307\u5b9a\u540d\u5b57\u7684service<\/li>\n\n\n\n<li>kubectl get endpoints\uff08ep\uff09\/\/\u67e5\u770bservice\u7684 Endpoint\u5217\u8868\u4fe1\u606f<\/li>\n\n\n\n<li>kubectl get configmap -n kube-system  \/\/\u67e5\u770bconfigmap\u4fe1\u606f<\/li>\n\n\n\n<li>kubectl delete -i  rs +\u540d\u5b57   \/\/\u5220\u9664rs<\/li>\n\n\n\n<li> kubectl label nodes k8s-node2 hello=world  \/\/\u7ed9\u8282\u70b9k8s-node2\u6253\u4e0a\u6807\u7b7ehello=world<\/li>\n\n\n\n<li>kubectl label nodes k8s-node2  hello=hello &#8211;overwrite    \/\/\u7ed9\u8282\u70b9k8s-node2\u6253\u6807\u7b7e\uff0c\u5f3a\u5236\u8986\u76d6\u539f\u6709\u7684hello\u952e<\/li>\n\n\n\n<li>kubectl get node &#8211;show-labels=true  \/\/\u5c55\u793a\u8282\u70b9\u6807\u7b7e<\/li>\n\n\n\n<li>kubectl label node k8s-node2 hello-    \/\/\u5220\u9664\u6807\u7b7e\uff0chello\u8868\u793a\u952e,\u6ce8\u610f\u540e\u9762\u8fd8\u6709\u4e00\u4e2a\u51cf\u53f7<\/li>\n\n\n\n<li>kubectl taint nodes k8s-node1 key=value:NoSchedule  \/\/\u4e3a\u8282\u70b9k8s-node1\u6dfb\u52a0\u6c61\u70b9\uff0c\u5e76\u8bbe\u7f6e\u4e0d\u8c03\u5ea6<\/li>\n\n\n\n<li> kubectl taint nodes k8s-node1 key=value:NoSchedule-   \/\/\u53bb\u9664\u6c61\u70b9<\/li>\n\n\n\n<li>kubectl taint node k8s-master1 node-role.kubernetes.io\/master- \/\/\u53bb\u9664\u8282\u70b9master\u7684\u6c61\u70b9\u8bbe\u7f6e<\/li>\n\n\n\n<li>kubectl describe nodes k8s-node1  \/\/\u67e5\u770bk8s-node1\u8282\u70b9\u4fe1\u606f\uff0c\u4e5f\u53ef\u770b\u5230\u6c61\u70b9\u60c5\u51b5<\/li>\n\n\n\n<li>kubectl create -f nginx.yml &#8211;record   \/\/\u521b\u5efapod\u5e76\u6dfb\u52a0\u7248\u672c\u5386\u53f2\u8bb0\u5f55\u529f\u80fd<\/li>\n\n\n\n<li>kubectl set image deploy\/nginx-app nginx-app=nginx:v1 \/\/\u6267\u884c\u6eda\u52a8\u66f4\u65b0\uff0c\u5176\u4e2dnginx-app\u4e3apod\u4e2d\u5b9a\u4e49\u7684deploy\u548cpod\u540d\u5b57<\/li>\n\n\n\n<li>kubectl rollout history deploy\/nginx-app \/\/\u67e5\u770b\u5386\u53f2\u53d1\u5e03\u7248\u672c<\/li>\n\n\n\n<li>kubectl rollout undo deploy\/nginx-app  \/\/\u56de\u6eda\u5230\u66f4\u65b0\u4e4b\u524d\u7248\u672c<\/li>\n\n\n\n<li>kubectl rollout undo deploy\/nginx-app &#8211;to-revision=2 \/\/\u56de\u6eda\u5230\u6307\u5b9a\u7248\u672c<\/li>\n\n\n\n<li>kubectl rollout pause deploy\/nginx-app    \/\/\u6682\u505cdeployment<\/li>\n\n\n\n<li>kubectl rollout resume deploy\/nginx-app \/\/\u6062\u590ddeployment<\/li>\n\n\n\n<li>kubectl rollout  status deploy\/nginx-app  \/\/\u67e5\u770bdeploy\u521b\u5efa\u7684\u72b6\u6001<\/li>\n\n\n\n<li>kubectl scale deployment nginx-app &#8211;replicas=2  \/\/\u624b\u52a8\u6269\u7f29\u5bb9<\/li>\n\n\n\n<li>kubectl patch deployment nginx -p &#8216;{&#8220;spec&#8221;:{&#8220;replicas&#8221;:2}}&#8217; \/\/\u901a\u8fc7patch\u624b\u52a8\u6269\u5bb9\u4e3a2\u4e2a\u526f\u672c\uff0c\u7f29\u5bb9\u4e00\u6837<\/li>\n\n\n\n<li>kubectl cordon master1    \/\/\u5c06master1\u8282\u70b9\u6807\u8bb0\u4e3a\u4e0d\u53ef\u8c03\u5ea6\u72b6\u6001<\/li>\n\n\n\n<li>kubectl uncordon  master1   \/\/\u5c06master1\u8282\u70b9\u6807\u8bb0\u4e3a\u53ef\u8c03\u5ea6\u72b6\u6001<\/li>\n\n\n\n<li>kubectl drain k8s-node1 &#8211;ignore-daemonsets   \/\/\u6392\u9664\u8282\u70b9\uff0c\u6b64\u8282\u70b9\u4e0bpod\u5c06\u4f1a\u8f6c\u79fb\u5230\u5176\u4ed6Node\u4e0b<\/li>\n\n\n\n<li>kubectl get ns &#8211;show-labels       \/\/\u67e5\u770b\u547d\u540d\u7a7a\u95f4\u6807\u7b7e<\/li>\n\n\n\n<li>kubectl get pod  &#8211;show-labels       \/\/\u67e5\u770bpod\u6807\u7b7e<\/li>\n\n\n\n<li>kubectl label  ns echo project=echo    \/\/\u8868\u793a\u7ed9\u547d\u540d\u7a7a\u95f4echo\u6253\u4e0a\u6807\u7b7eproject=echo<\/li>\n\n\n\n<li>kubectl label  ns echo project-      \/\/\u8868\u793a\u5220\u9664\u547d\u540d\u7a7a\u95f4echo\u4e2d\u7684\u6807\u7b7eproject<\/li>\n\n\n\n<li>kubectl delete deploy front-end &#8211;cascade=orphan   \/\/\u5220\u9664deploy\uff0c\u4f46\u662f\u4e0d\u5220\u9664\u7531\u5176\u63a7\u5236\u7684pod<\/li>\n\n\n\n<li>kubectl  config get-contexts        \/\/\u67e5\u770b\u6240\u6709\u7684\u4e0a\u4e0b\u6587<\/li>\n\n\n\n<li>kubectl config current-context    \/\/\u67e5\u770b\u5f53\u524d\u7684\u4e0a\u4e0b\u6587<\/li>\n\n\n\n<li>kubectl config use-context   guan@kubernetes    \/\/\u5207\u6362\u4e0a\u4e0b\u6587<\/li>\n\n\n\n<li>yamllint file.yaml                   \/\/\u68c0\u67e5yaml\u8bed\u6cd5\u662f\u5426\u9519\u8bef\uff0c\u9700\u8981\u63d0\u524d\u5b89\u88c5yamllint\uff0capt\/yum install yamllint<\/li>\n\n\n\n<li>kubectl api-resources           \/\/\u5217\u51fak8s\u8d44\u6e90\u4fe1\u606f<\/li>\n\n\n\n<li>kubectl delete pod   podname  -n namespace   \/\/\u5220\u9664\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\u4e2d\u7684pod<\/li>\n\n\n\n<li>kubectl delete po podname -n namespace &#8211;grace-period=0 &#8211;force  \/\/\u5f3a\u5236\u5220\u9664pod<\/li>\n\n\n\n<li>kubectl get po podname -n namespace  -o jsonpath={.spec.volumes} | jq   \/\/\u67e5\u770bpod\u662f\u5426\u6709\u6302\u5728\u5377volume<\/li>\n\n\n\n<li>kubectl explain  deployments         \/\/\u67e5\u770bdeployment\u63a7\u5236\u5668\u8d44\u6e90\u5b9a\u4e49\u6e05\u5355\u5b57\u6bb5<\/li>\n\n\n\n<li>kubectl explain  pods                     \/\/\u67e5\u770bpods\u8d44\u6e90\u5b9a\u4e49\u6e05\u5355\u5b57\u6bb5<\/li>\n\n\n\n<li>kubectl explain pods.spec.containers    \/\/\u67e5\u770bpod\u8d44\u6e90\u5b9a\u4e49\u6e05\u5355\u5b57\u6bb5containers\u4e0b\u9762\u7684\u5b57\u6bb5<\/li>\n\n\n\n<li>kubectl get po  podname -o yaml &gt; podname.yaml       \/\/\u4ece\u73b0\u6709\u7684pod\u4e2d\u5bfc\u51fa\u8d44\u6e90\u5b9a\u4e49\u6e05\u5355\uff0c\u4fee\u6539\u540e\u5373\u53ef\u91cd\u65b0\u521b\u5efapod<\/li>\n\n\n\n<li>kubectl get pods myapp-pod -o jsonpath={.spec.containers[*].name}  \/\/\u67e5\u770bpod\u91cc\u4e1a\u52a1\u5bb9\u5668<\/li>\n\n\n\n<li>kubectl top pod &#8211;sort-by=cpu -A     \/\/\u67e5\u770bcpu\u4f7f\u7528\u7387\u5360\u7528\u6700\u9ad8\u7684pod<\/li>\n\n\n\n<li>kubectl get po -w      \/\/\u52a8\u6001\u67e5\u770bpod\uff0c-w\u53c2\u6570\u53ef\u4ee5\u5b9e\u65f6\u7684\u67e5\u770b\u5185\u5bb9<\/li>\n\n\n\n<li>kubectl delete statefulset nginx &#8211;cascade=false \/\/\u975e\u7ea7\u8054\u5220\u9664(\u53ea\u5220\u9664statefulset\uff0c\u4e0d\u5220\u9664pod)<\/li>\n\n\n\n<li>kubectl delete statefulset nginx \/\/\u7ea7\u8054\u5220\u9664(\u5220\u9664sts\u540c\u65f6\u5220\u9664pod\uff0c\u4e0d\u52a0\u53c2\u6570&#8211;cascode\u5c31\u662f\u7ea7\u8054)<\/li>\n\n\n\n<li>kubectl get svc -l &#8216;app in (service1,service2)&#8217; &#8211;show-labes \/\/\u5217\u51fa\u6807\u7b7e\u5339\u914dapp=service1\u548capp=service2\u7684\u5168\u90e8service<\/li>\n\n\n\n<li>kubectl label svc nginx-service  app=service1 &#8211;overwrite \/\/\u5c06nginx-service\u4fee\u6539<\/li>\n\n\n\n<li>kubectl exec -it nginx  -n default &#8212; \/bin\/sh     \/\/\u8fdb\u5165pod\u5185\u90e8\uff0c\u5982\u679c\u4e0d\u6307\u5b9a-n\uff0c\u9ed8\u8ba4\u5c31\u662fdefault<\/li>\n\n\n\n<li>kubectl exec -it kube-apiserver-k8s-master01 &#8212; kube-apiserver -h |grep ExpandCSIVolumes \/\/\u5728kube-apiserver\u4e2d\u6267\u884c\u547d\u4ee4\uff0c\u67e5\u770b\u662f\u5426\u5f00\u542fExpandCSIVolumes\uff0cdefault\u4e3atrue\u8868\u793a\u5f00\u542f<\/li>\n\n\n\n<li>kubectl exec -it pod &#8212; command    \/\/\u5728pod\u4e2d\u6267\u884c\u547d\u4ee4command<\/li>\n\n\n\n<li>kubectl autoscale deployment nginx &#8211;cpu-percent=10 &#8211;min=1 &#8211;max=10  \/\/\u81ea\u52a8\u6269\u7f29\u5bb9\uff0c\u5f53cpu\u4f7f\u7528\u7387\u8d85\u8fc710%\u5c31\u589e\u52a0pod\u6570\u91cf\uff0c\u4e2a\u6570\u6700\u591a\u4e3a10\uff0c\u6700\u5c11\u4e3a1<\/li>\n\n\n\n<li>kubectl delete pod [pod name] &#8211;force &#8211;grace-period=0 -n [namespace] \/\/\u5f3a\u5236\u5220\u9664pod<\/li>\n\n\n\n<li>&nbsp;kubectl drain node1 &#8211;delete-local-data &#8211;force &#8211;ignore-daemonsets  \/\/\u9a71\u9010\u8282\u70b9\u4e0aPod<\/li>\n\n\n\n<li>kubectl delete node node01 \/\/\u5220\u9664\u8282\u70b9<\/li>\n\n\n\n<li>kubectl rollout restart deployment  hello -n  namespace   \/\/\u91cd\u542fpod <\/li>\n\n\n\n<li>kubectl logs pod-name -n namespace  #\u67e5\u770bpod\u65e5\u5fd7<\/li>\n\n\n\n<li>kubectl logs pod-name -c container-name -n namespace #\u67e5\u770bpod\u5185\u5bb9\u5668\u65e5\u5fd7<\/li>\n\n\n\n<li>kubectl logs -f pod-name -n namespace #\u6301\u7eed\u76d1\u63a7\u65e5\u5fd7<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Helm\u5e38\u7528\u547d\u4ee4\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>helm repo update                     \/\/\u66f4\u65b0\u9ed8\u8ba4\u4ed3\u5e93\u7684\u5143\u6570\u636e<\/li>\n\n\n\n<li>helm repo list                           \/\/\u5217\u51fa\u672c\u5730\u914d\u7f6e\u7684Chart\u4ed3\u5e93<\/li>\n\n\n\n<li>helm  repo remove                  \/\/\u79fb\u9664\u6307\u5b9a\u4ed3\u5e93<\/li>\n\n\n\n<li>helm search repo etcd            \/\/\u5728\u672c\u5730\u4ed3\u5e93\u4e2d\u641c\u7d22etcd<\/li>\n\n\n\n<li>helm search hub   etcd           \/\/\u5728\u7ebf\u641c\u7d22Hub\u4e2d\u5b58\u5728\u7684\u6240\u6709\u4ed3\u5e93\u4e2d\u7684etcd<\/li>\n\n\n\n<li>helm show all      chart\u540d       \/\/\u67e5\u770b\u67d0\u4e2aChart\u7684\u8be6\u7ec6\u4fe1\u606f<\/li>\n\n\n\n<li>helm inspect all   chart\u540d       \/\/\u67e5\u770b\u67d0\u4e2aChart\u7684\u8be6\u7ec6\u4fe1\u606f<\/li>\n\n\n\n<li>helm pull  bitnami\/redis        \/\/\u4ece\u4ed3\u5e93bitnami\u4e2d\u4e0b\u8f7dredis\uff0c\u6b64\u65f6\u4e0b\u8f7d\u7684\u662f\u6700\u65b0\u7248<\/li>\n\n\n\n<li>helm search repo bitnami\/redis -l   \/\/\u67e5\u770bChart\u7684\u5386\u53f2\u7248\u672c<\/li>\n\n\n\n<li>helm pull bitnami\/redis &#8211;version 16.11.2  \/\/\u4e0b\u8f7d\u6307\u5b9a\u7248\u672c\u7684redis\u7684Chart<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>helm\u56fd\u5185\u955c\u50cf\u5730\u5740\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/mirrors.huaweicloud.com\/helm\/v3.13.3\/\">Index of helm-local\/v3.13.3 (huaweicloud.com)<\/a><\/li>\n\n\n\n<li>https:\/\/mirrors.huaweicloud.com\/helm\/v3.13.3\/<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5f00\u6e90k8s\u7ba1\u7406\u9762\u677f\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>kuboard\uff1a\u4e2a\u4eba\u5f00\u6e90,       \u5730\u5740\uff1ahttps:\/\/kuboard.cn\/<\/li>\n\n\n\n<li>kubepi\uff1a   \u98de\u81f4\u4e91\u5f00\u6e90\uff0c\u5730\u5740\uff1ahttps:\/\/github.com\/1Panel-dev\/KubePi<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Kro: \u8fd9\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u3001\u57fa\u4e8eKubernetes\u7684\u9879\u76ee\uff0c\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u7b80\u5355\u76f4\u89c2\u7684\u914d\u7f6e\u5b9a\u4e49\u81ea\u5b9a\u4e49Kubernetes API<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CI\/CD:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tekton\u548cArgoCD\u914d\u5408\uff0cTekton\u8d1f\u8d23CI\uff0cArgoCD\u8d1f\u8d23CD<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Helm\u5e38\u7528\u547d\u4ee4\uff1a helm\u56fd\u5185\u955c\u50cf\u5730\u5740\uff1a \u5f00\u6e90k8s\u7ba1\u7406\u9762\u677f\uff1a Kro: \u8fd9\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u3001\u57fa\u4e8eKuberne [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-234","page","type-page","status-publish","hentry"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages\/234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=234"}],"version-history":[{"count":68,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages\/234\/revisions"}],"predecessor-version":[{"id":19331,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages\/234\/revisions\/19331"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}