kubectl常用命令

kubernetes命令自动补全(只针对当前bash)

source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)

将get信息到处为yaml格式

kubectl get deploy kube-dns -n kube-system -o yaml > kube-dns.yaml

更新yaml文件并更新服务(1.8版本开始改为apply)

kubectl update -f kube-dns.yaml

编辑当前应用的配置

kubectl edit deployment nginx

查看当前集群中的daemoset及详细信息

kubectl get ds --all-namespaces
kubectl describe daemonset kube-flannel-ds -n kube-system

新建namespace

kubectl create namespace morata-namespace

删除namespace

kubectl delete namespace morata-namespace

设置节点为维护模式(即节点不可被调度,但不影响已有pod的运行)

kubectl cordon k8s-slave

关闭维护模式

kubectl uncordon k8s-slave

创建deployment并查看信息

创建nginx,并且设置为2份

kubectl run nginx --image=nginx:1.7.9 --replicas=2

删除deployment

kubectl delete deployment nginx

查看所有deployment

kubectl get deployment

查看nignx deployment的详细信息

kubectl describe deployment nginx

查看pod

kubectl get pod
kubectl get pod nginx-6f8cf9fbc4-lvsqj -o wide

查看pod详细信息

kubectl describe pod nginx-6f8cf9fbc4-lvsqj

在pod中运行命令

kubectl exec nginx-6f8cf9fbc4-lvsqj ls

进入pod

kubectl exec nginx-6f8cf9fbc4-lvsqj -it bash

查看replicaset

kubectl get rs

查看replicaset的详细信息

kubectl describe rs nginx-6f8cf9fbc4

创建service

cat nginx.svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
  app: nginx
spec:
ports:
 - name: http
  port: 8888
  nodePort: 30001
  targetPort: 80
selector:
  run: nginx
type: NodePort
 
kubectl create -f nginx.svc.yaml
kubectl expose deployment nginx --type=NodePort --name=nginx-test --port=80

删除service

kubectl delete -f nginx.svc.yam
kubectl delete svc nginx

查看service及详细信息

kubectl get svc
kubectl describe svc nginx

查看endpoint

kubectl get endpoints
NAME         ENDPOINTS                       AGE
kubernetes   192.168.8.250:6443             10h
nginx        10.244.0.13:80,10.244.1.31:80   5m
nginx-test   10.244.0.13:80,10.244.1.31:80   50s

deployment扩容缩容

kubectl scale deployment nginx --replicas=3

kubectl scale deployment nginx --replicas=2
#查看ep、rs、pod都发生扩容/缩容
kubectl get endpoints

kubectl get rs

kubectl get pod

滚动升级/回滚

#升级nginx至1.9.1
kubectl set image deploy nginx nginx=nginx:1.9.1

#查看升级状态
kubectl rollout status deployment nginx

 #查看升级历史
kubectl rollout history deployment nginx

#查看历史版本详情
kubectl rollout history deployment nginx --revision=2

#可以查看rs、deployemnt、svc、pod查看升级中的变化
kubectl get rs
kubectl get svc
kubectl get pod
kubectl get deployment

#查看deployment升级事件详情
kubectl describe deployment nginx

#升级失败回滚
kubectl set image deploy nginx nginx=nginx:1.95

 #查看升级状态一直处于等待状态
kubectl rollout status deployment nginx

Waiting for rollout to finish: 1 old replicas are pending termination...

 
 #可以查看升级历史、svc、rs、pod等详情可以得知错误原因
 
 #回滚操作
kubectl rollout undo deployment nginx
 
 #查看deployment回滚详情
kubectl describe deployment nginx

我来吐槽

*

*

已有 36 条评论

  1. offifsnet

    https://bestadalafil.com/ - Cialis Scnnlg cialis pills for sale Aroffh Note Other overthecounter medications such as PeptoBismol and substances with oil of wintergreen also contain aspirin compounds called salicylates. Ifrbpr https://bestadalafil.com/ - cialis prescription online

  2. clourgy

    Baclofene Lancet non prescription cialis online pharmacy

  3. clourgy

    generic for cialis take viagra cialis

  4. Twirway

    buy stromectol for dogs Vendita Levitra 20mg

  5. Twirway

    ivermectin pills for sale Zithromax Early Pregnancy

  6. Keysler

    A couple of websites do the vetting for you, using these and other criteria cialis coupon

  7. Entenedat

    Few studies have specifically addressed the use of PAH therapies in geriatric patients despite the growing number of elderly patients diagnosed with this disease brand name cialis online

  8. wainnef

    side of the road is Honda, Yamaha, Kawasaki, Suzuki, this side of the road is Wuyang, Haojue, Xindazhou, Zongshen, both sides are like fighting, you pull a banner , I will make a sound system, you have a literary performance here, and I will draw a lottery and smash golden eggs here priligy 60 mg price

  9. experly

    priligy 30mg tablets IE 11 Safari 13 Safari on iPhone 11 Pro Chrome on Galaxy S20

  10. ruinkix

    2 to 3 hrs after taking it, I feel like someone has kicked me in the jewels discreet cialis meds Also remember, it can be difficult for people to remember these items when shopping for cialis and so can be confusing to use our website during purchase or even just to glance over to know exactly what Cialis looks like in pill form

  11. Litimitte

    cheap cialis generic online Questionario controllerГ  il nostro medico, se non ci sono gravi controindicazioni, egli approverГ  l ordine, scrivere una prescrizione on-line, ГЁ possibile ottenere il farmaco per posta

  12. Nizscoons

    How is Cialis daily different from as-needed Cialis treatment buy cialis online using paypal Apply an antibiotic cream after the procedure has been completed

  13. SokSwette

    cialis tadalafil Instead, keep it inside its original container and take each Cialis tablet out as needed

  14. Gearsella

    Grinsted, Acupuncture on the day of embryo transfer significantly improves the reproductive outcome in infertile women a prospective, randomized trial, Fertility and Sterility , vol. how to take clomid for twins

  15. hustype

    things to do or avoid while taking clomid Worse, zero motivation and sex drive.

  16. furtuby

    tamoxifen inducible cre If all the embryos turn out to be aneuploid, it may help the couple reconsider using donor eggs.

  17. ziserse

    In general, these dogs have a very poor response to protocols using imidocarb dipropionate 113. doxycycline With more serious bites a bull s eye wound may form.

  18. ignisse

    17 However, the sample size to show equivalence was not obtained; therefore, it cannot be statistically concluded that the groups are equivalent. doxycycline dosage for uti treatment

  19. Arrerswaf

    Grapefruit juice is an inhibitor of CYP3A4 how do i know if lasix is working for dog Have you ever purchased V R Acid Reducer Oral

  20. FauntyFap

    lasix 40 Vicari E, La Vignera S, Calogero AE

  21. ethinny

    Almost all of the initially responding patients will eventually relapse showing what is called acquired resistance cialis viagra combo pack Welge JA, Keck PE, Jr

  22. Effotte

    cialis without a doctor's prescription Pooled results from multiple studies suggest that approximately 40 of cancer patients report significant distress

  23. Allercext

    stromectol bed bugs Sylvester, USA 2022 05 19 15 52 59

  24. nojeddy

    stromectol uk boots Quantitative real time PCR analyses using the comparative CT method were performed on an ABI PRISM 7700 Sequence Detector System using the SYBR Green PCR Master Mix kit Perkin Elmer, Applied Biosystems, Wellesley, MA, USA according to the manufacturer s instructions

  25. Almobre

    Bryant saTgjdOpDFreeGFP 6 18 2022 tamoxifen used for

  26. Epibigo

    01 and less likely to be married 43 of 115 37 buy priligy in usa

  27. Almobre

    want buy nolvadex The company reported non GAAP EPS of 0

  28. Epibigo

    Biological effects of the synthetic oestrogenic substance 4 4 dihydroxy О± ОІ diethylstibene reddit where buy priligy

  29. Spoiffutt

    lasix iv dose Early discontinuation and nonadherence to adjuvant hormonal therapy in a cohort of 8769 early stage breast cancer patients

  30. justymn

    Someone else in this room is very concerned about that, Tretola says, glancing at her husband, who s uttered barely a word can i drink alcohol while taking doxycycline

  31. justymn

    For example, cellular stress such as chemotherapy, radiation, or oxidative stress increases levels of ceramide and sphingosine through the activation of de novo synthesis, sphingomyelin hydrolysis, or the salvage pathway which recycles sphingosine to promote apoptosis alcohol with doxycycline Elhelw B, Ghorab MN, Farrag SH

  32. Attaicift

    clomid twins colestipol decreases levels of acetaminophen by inhibition of GI absorption

  33. legepunny

    stromectol dosage for humans Elimina el problema de labios sin color o esfumado alrededor de la boca

  34. legepunny

    Tsang WP, Kwok TT stromectol uses

  35. Spoiffutt

    I have joined the Swim Across America family so that I can continue to give cancer patients hope by raising funds to support cutting edge cancer research another name for lasix