摘要:查看版本查看節(jié)點(diǎn)部署說(shuō)明提供名稱和鏡像地址鏡像地址再如查看測(cè)試獲取名字測(cè)試使用進(jìn)行故障排除主要使用如下命令列出資源顯示資源詳情打印中的日志在中的上執(zhí)行命令獲取應(yīng)用配置查看應(yīng)用是否在運(yùn)行查看中有哪些結(jié)
查看版本
kubectl version查看節(jié)點(diǎn)
kubectl get nodes部署app
說(shuō)明: 提供deployment名稱和app鏡像地址(docker鏡像地址)
kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080
再如:
run test --image=preparedman/mytomcat:tagname --port=8088查看app
kubectl proxy
測(cè)試:curl http://localhost:8001/version
{ "major": "1", "minor": "13", "gitVersion": "v1.13.3", "gitCommit": "721bfa751924da8d1680787490c54b9179b1fed0", "gitTreeState": "clean", "buildDate": "2019-02-01T20:00:57Z", "goVersion": "go1.11.5", "compiler": "gc", "platform": "linux/amd64" }
獲取pod名字
export POD_NAME=$(kubectl get pods -o go-template --template "{{range .items}}{{.metadata.name}}{{" "}}{{end}}")
測(cè)試:echo Name of the Pod: $POD_NAME
使用kubectl進(jìn)行故障排除主要使用如下命令
kubectl get - list resources 列出資源 kubectl describe - show detailed information about a resource 顯示資源詳情 kubectl logs - print the logs from a container in a pod 打印`pod` 中container的日志 kubectl exec - execute a command on a container in a pod 在`pod`中的container上執(zhí)行命令獲取應(yīng)用配置
查看應(yīng)用是否在運(yùn)行
kubectl get pods
查看pod 中有哪些container
kubectl describe pods
結(jié)果如下:
Name: kubernetes-bootcamp-6bf84cb898-jk4jc Namespace: default Priority: 0 PriorityClassName:打印container日志Node: minikube/172.17.0.72 Start Time: Wed, 24 Apr 2019 13:21:58 +0000 Labels: pod-template-hash=6bf84cb898 run=kubernetes-bootcamp Annotations: Status: Running IP: 172.18.0.4 Controlled By: ReplicaSet/kubernetes-bootcamp-6bf84cb898 Containers: kubernetes-bootcamp: Container ID: docker://55491b363d26b62e432cd4841ed4f65cc5b98e645d172c6ed88feaebcb4ec06c Image: gcr.io/google-samples/kubernetes-bootcamp:v1 Image ID: docker-pullable://jocatalin/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af Port: 8080/TCP Host Port: 0/TCP State: Running Started: Wed, 24 Apr 2019 13:22:00 +0000 Ready: True Restart Count: 0 Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-l7v8b (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-l7v8b: Type: Secret (a volume populated by a Secret) SecretName: default-token-l7v8b Optional: false QoS Class: BestEffort Node-Selectors: Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 3m6s default-scheduler Successfully assigned default/kubernetes-bootcamp-6bf84cb898-jk4jc to minikube Normal Pulled 3m4s kubelet, minikube Container image "gcr.io/google-samples/kubernetes-bootcamp:v1" already present on machine Normal Created 3m4s kubelet, minikube Created container Normal Started 3m4s kubelet, minikube Started container
kubectl logs $POD_NAME在container中直接執(zhí)行命令
比如:獲取pod名字是kubernetes-bootcamp-6bf84cb898-jk4jc的日期,默認(rèn)使用第一個(gè)container container by default
kubectl exec kubernetes-bootcamp-6bf84cb898-jk4jc date
再入:進(jìn)入container的命令行環(huán)境
kubectl exec kubernetes-bootcamp-6bf84cb898-jk4jc bash
退出使用
exit暴露你的應(yīng)用service 列出當(dāng)前集群中的service
kubectl get services創(chuàng)建一個(gè)新的service并暴露給外部流量
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080查看service詳情
$ kubectl describe services/kubernetes-bootcamp
結(jié)果:
Name: kubernetes-bootcamp Namespace: default Labels: run=kubernetes-bootcamp Annotations:創(chuàng)建一個(gè)環(huán)境變量NODE_PORT,它的值等于service暴露的端口Selector: run=kubernetes-bootcamp Type: NodePort IP: 10.105.231.53 Port: 8080/TCP TargetPort: 8080/TCP NodePort: 32400/TCP Endpoints: 172.18.0.4:8080 Session Affinity: None External Traffic Policy: Cluster Events:
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template="{{(index .spec.ports 0).nodePort}}") echo NODE_PORT=$NODE_PORT
測(cè)試:
curl $(minikube ip):$NODE_PORT使用labels 查看label
kubectl describe deployment
你能看到這樣一行:
Labels: run=kubernetes-bootcamp通過(guò)label查詢pod
kubectl get pods -l run=kubernetes-bootcamp通過(guò)label查詢service
kubectl get services -l run=kubernetes-bootcamp獲取pod名字,并保存到環(huán)境變量POD_NAME中
export POD_NAME=$(kubectl get pods -o go-template --template "{{range .items}}{{.metadata.name}}{{" "}}{{end}}") echo name of the pod: $POD_NAME添加新的lebel
使用label命令
kubectl label pod $POD_NAME app=v1
查看:
kubectl describe pods $POD_NAME刪除service 通過(guò)label刪除service
kubectl delete service -l run=kubernetes-bootcamp
確認(rèn)刪除:
kubectl get services
確認(rèn)沒(méi)有暴露給集群外部:
curl $(minikube ip):$NODE_PORT
確認(rèn)集群內(nèi)部還可以訪問(wèn):
kubectl exec -ti $POD_NAME curl localhost:8080
擴(kuò)容 設(shè)置deployments的replica數(shù)量為4kubectl scale deployments/kubernetes-bootcamp --replicas=4
查看結(jié)果:
可以看到修改replica設(shè)置生效
NAME READY UP-TO-DATE AVAILABLE AGE kubernetes-bootcamp 4/4 4 4 3m17s
pod數(shù)量已經(jīng)改變,查看詳情
kubectl get pods -o wide
結(jié)果:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES kubernetes-bootcamp-6bf84cb898-7tbrg 1/1 Running 0 2m50s 172.18.0.5 minikubekubernetes-bootcamp-6bf84cb898-fx68f 1/1 Running 0 3m52s 172.18.0.4 minikube kubernetes-bootcamp-6bf84cb898-prgsc 1/1 Running 0 2m50s 172.18.0.6 minikube kubernetes-bootcamp-6bf84cb898-qv4gc 1/1 Running 0 2m50s 172.18.0.7 minikube
查看4個(gè)pod
kubectl describe deployments/kubernetes-bootcamp
結(jié)果:
Replicas: 4 desired | 4 updated | 4 total | 4 available | 0 unavailable查看service是否是負(fù)載均衡的 查看具體IP
kubectl describe services/kubernetes-bootcamp
結(jié)果:
Endpoints: 172.18.0.2:8080,172.18.0.4:8080,172.18.0.6:8080 + 1 more...創(chuàng)建環(huán)境變量NODE_PORT
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template="{{(index .spec.ports 0).nodePort}}") echo NODE_PORT=$NODE_PORT調(diào)用請(qǐng)求
可以看到,每次請(qǐng)求的都是不同的pod
curl $(minikube ip):$NODE_PORT
結(jié)果:
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-2l975 | v=1 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-zbmj4 | v=1 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-qg5xh | v=1 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-zbmj4 | v=1 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-bn98t | v=1 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-zbmj4 | v=1 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-zbmj4 | v=1 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-6bf84cb898-zbmj4 | v=1縮容
kubectl scale deployments/kubernetes-bootcamp --replicas=2 ## 更新到版本2 kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
驗(yàn)證更新
查看暴露出來(lái)的ip和端口
kubectl describe services/kubernetes-bootcamp
結(jié)果:
Name: kubernetes-bootcamp Namespace: default Labels: run=kubernetes-bootcamp Annotations:Selector: run=kubernetes-bootcamp Type: NodePort IP: 10.98.28.235 Port: 8080/TCP TargetPort: 8080/TCP NodePort: 31419/TCP Endpoints: 172.18.0.10:8080,172.18.0.11:8080,172.18.0.8:8080 + 1 more... Session Affinity: None External Traffic Policy: Cluster Events:
創(chuàng)建環(huán)境變量
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template="{{(index .spec.ports 0).nodePort}}") echo NODE_PORT=$NODE_PORT
訪問(wèn):
curl $(minikube ip):$NODE_PORT
結(jié)果:
訪問(wèn)版本2,且每次訪問(wèn)不同的地址
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5bf4d5689b-tcxpf | v=2 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5bf4d5689b-tcxpf | v=2 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5bf4d5689b-86c8g | v=2 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5bf4d5689b-fx9tf | v=2 $ curl $(minikube ip):$NODE_PORT Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-5bf4d5689b-tcxpf | v=2確認(rèn)更新
kubectl rollout status deployments/kubernetes-bootcamp回滾
更新到版本10
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=gcr.io/google-samples/kubernetes-bootcamp:v10
查看發(fā)現(xiàn)報(bào)錯(cuò),因?yàn)榘姹編?kù)中沒(méi)有版本10
kubectl get deployments kubectl get pods kubectl describe pods
報(bào)錯(cuò)
Warning Failed 38s (x3 over 77s) kubelet, minikube Failed to pull image "gcr.io/google-samples/kubernetes-bootcamp:v10": rpc error: code = Unknown desc = Error response from daemon: manifest for gcr.io/google-samples/kubernetes-bootcamp:v10 not found
執(zhí)行會(huì)滾
kubectl rollout undo deployments/kubernetes-bootcamp
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/33180.html
摘要:查看版本查看節(jié)點(diǎn)部署說(shuō)明提供名稱和鏡像地址鏡像地址再如查看測(cè)試獲取名字測(cè)試使用進(jìn)行故障排除主要使用如下命令列出資源顯示資源詳情打印中的日志在中的上執(zhí)行命令獲取應(yīng)用配置查看應(yīng)用是否在運(yùn)行查看中有哪些結(jié) 查看版本 kubectl version 查看節(jié)點(diǎn) kubectl get nodes 部署app 說(shuō)明: 提供deployment名稱和app鏡像地址(docker鏡像地址) kub...
摘要:平臺(tái)上的微服務(wù)架構(gòu)應(yīng)用再來(lái)看一下我眼中的基于當(dāng)前最流行的微服務(wù)架構(gòu)的設(shè)計(jì)是什么樣的,即我們平臺(tái)上要運(yùn)行的典型應(yīng)用是什么樣的。 showImg(https://segmentfault.com/img/remote/1460000010900878); 8月19日的數(shù)人云Container Meetup上,張龍老師做了《基于Kubernetes的PaaS平臺(tái)的設(shè)計(jì)和思考》的精彩分享,分別...
摘要:標(biāo)識(shí)是與操作對(duì)象間的紐帶。集群為每個(gè)對(duì)象維護(hù)三類信息對(duì)象元數(shù)據(jù)期望狀態(tài)與實(shí)際狀態(tài)元數(shù)據(jù)指對(duì)象的基本信息,比如命名標(biāo)簽注釋等等,用于識(shí)別對(duì)象期望狀態(tài)一般由用戶配置來(lái)描述的實(shí)際狀態(tài)是由集群各個(gè)組件上報(bào)的集群實(shí)際的運(yùn)行情況。 綜述 學(xué)習(xí)Kubernetes時(shí),發(fā)現(xiàn)它的概念和術(shù)語(yǔ)還是比較多的,光靠啃官方文檔比較晦澀。所以邊學(xué)習(xí)邊整理,對(duì)主要的概念和術(shù)語(yǔ)做一下分類及簡(jiǎn)要說(shuō)明。感覺(jué)把重要概念都理解...
摘要:核心概念是最小的調(diào)度單元,可以由一個(gè)或者多個(gè)容器組成。該模式會(huì)跟云服務(wù)商有關(guān),比如可以通過(guò)等創(chuàng)建一個(gè)外部的負(fù)載均衡器,將請(qǐng)求轉(zhuǎn)發(fā)到對(duì)應(yīng)的服務(wù)組。而可以提供外部服務(wù)可訪問(wèn)的負(fù)載均衡器等。 概述 Kubernetes 有各類資源對(duì)象來(lái)描述整個(gè)集群的運(yùn)行狀態(tài)。這些對(duì)象都需要通過(guò)調(diào)用 kubernetes api 來(lái)進(jìn)行創(chuàng)建、修改、刪除,可以通過(guò) kubectl 命令工具,也可以直接調(diào)用 k8...
摘要:知識(shí)點(diǎn)核心組件保存整個(gè)集群的狀態(tài)信息,感覺(jué)相當(dāng)于的數(shù)據(jù)庫(kù)提供對(duì)資源操作的唯一入口,并提供認(rèn)證授權(quán),訪問(wèn)控制,注冊(cè)與發(fā)現(xiàn)等機(jī)制負(fù)責(zé)維護(hù)集群的狀態(tài),故障檢測(cè),自動(dòng)擴(kuò)展,滾動(dòng)更新等負(fù)責(zé)對(duì)資源的調(diào)度,按著預(yù)定的調(diào)度策略將調(diào)度到相應(yīng)的集群上負(fù)責(zé)維護(hù)容 kubernetes kubernetes 知識(shí)點(diǎn) 1. 核心組件 etcd 保存整個(gè)集群的狀態(tài)信息,感覺(jué)相當(dāng)于k8s的數(shù)據(jù)庫(kù) apiserve...
閱讀 2744·2021-10-26 09:50
閱讀 2385·2021-10-11 11:08
閱讀 2128·2019-08-30 15:53
閱讀 1906·2019-08-30 15:44
閱讀 2382·2019-08-28 18:12
閱讀 2520·2019-08-26 13:59
閱讀 2853·2019-08-26 12:19
閱讀 2752·2019-08-26 12:09