云計(jì)算 K8S Pod status的狀態(tài)分析
CrashLoopBackOff: 容器退出,kubelet正在將它重啟
InvalidImageName: 無(wú)法解析鏡像名稱
ImageInspectError: 無(wú)法校驗(yàn)鏡像
ErrImageNeverPull: 策略禁止拉取鏡像
ImagePullBackOff: 正在重試?yán)?RegistryUnavailable: 連接不到鏡像中心
ErrImagePull: 通用的拉取鏡像出錯(cuò)
CreateContainerConfigError: 不能創(chuàng)建kubelet使用的容器配置
CreateContainerError: 創(chuàng)建容器失敗
m.internalLifecycle.PreStartContainer 執(zhí)行hook報(bào)錯(cuò)
RunContainerError: 啟動(dòng)容器失敗
PostStartHookError: 執(zhí)行hook報(bào)錯(cuò)
ContainersNotInitialized: 容器沒(méi)有初始化完畢
ContainersNotReady: 容器沒(méi)有準(zhǔn)備完畢
ContainerCreating:容器創(chuàng)建中
PodInitializing:pod 初始化中
DockerDaemonNotReady:docker還沒(méi)有完全啟動(dòng)
NetworkPluginNotReady: 網(wǎng)絡(luò)插件還沒(méi)有完全啟動(dòng)
K8S-YAML的使用及命令
10多年的孝昌網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷型網(wǎng)站的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整孝昌建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“孝昌網(wǎng)站設(shè)計(jì)”,“孝昌網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。YAML配置文件管理對(duì)象
對(duì)象管理:
# 創(chuàng)建deployment資源
kubectl create -f nginx-deployment.yaml
# 查看deployment
kubectl get deploy
# 查看ReplicaSet
kubectl get rs
# 查看pods所有標(biāo)簽
kubectl get pods --show-labels
# 根據(jù)標(biāo)簽查看pods
kubectl get pods -l app=nginx
# 滾動(dòng)更新鏡像
kubectl set image deployment/nginx-deployment nginx=nginx:1.11
或者
kubectl edit deployment/nginx-deployment
或者
kubectl apply -f nginx-deployment.yaml
# 實(shí)時(shí)觀察發(fā)布狀態(tài):
kubectl rollout status deployment/nginx-deployment
# 查看deployment歷史修訂版本
kubectl rollout history deployment/nginx-deployment
kubectl rollout history deployment/nginx-deployment --revision=3
# 回滾到以前版本
kubectl rollout undo deployment/nginx-deployment
kubectl rollout undo deployment/nginx-deployment --to-revision=3
# 擴(kuò)容deployment的Pod副本數(shù)量
kubectl scale deployment nginx-deployment --replicas=10
# 設(shè)置啟動(dòng)擴(kuò)容/縮容
kubectl autoscale deployment nginx-deployment --min=10 --max=15 --cpu-percent=80
對(duì)象管理實(shí)例:vim nginx.deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- containerPort: 80
服務(wù)發(fā)現(xiàn)實(shí)例:vim nging.service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
run: nginx
name: nginx
namespace: default
spec:
ports:
- port: 88
targetPort: 80
selector:
app: nginx
清理:
# kubectl delete -f nginx-deployment.yaml
# kubectl delete -f nginx-service.yaml
POD作用:
Pod管理-創(chuàng)建/查詢/更新/刪除
基本管理:
# 創(chuàng)建pod資源
kubectl create -f pod.yaml
# 查看pods
kubectl get pods pod-test
# 查看pod描述
kubectl describe pod pod-test
# 替換資源
kubectl replace -f pod.yaml -force
# 刪除資源
kubectl delete pod pod-test
支持三種策略:
Always:當(dāng)容器終止退出后,總是重啟容器,默認(rèn)策略。
OnFailure:當(dāng)容器異常退出(退出狀態(tài)碼非0)時(shí),才重啟容器。
Never:當(dāng)容器終止退出,從不重啟容器。
Pod實(shí)例:vim pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-test
labels:
os: centos
spec:
containers:
- name: hello
image: centos:7
env:
- name: Test
value: 123456
command: [bash,-c,while true;do date;sleep 1;done]
restartPolicy: OnFailure
Pod管理-健康檢查:
提供Probe機(jī)制,有以下兩種類型:
livenessProbe
如果檢查失敗,將殺死容器,然后根據(jù)Pod的重啟策略來(lái)決定是否
重啟。
readinessProbe
如果檢查失敗,Kubernetes會(huì)把Pod從服務(wù)代理的分發(fā)后端剔除。
Probe支持以下三種檢查方法:
httpGet
發(fā)送HTTP請(qǐng)求,返回200-400范圍狀態(tài)碼為成功。
exec
執(zhí)行Shell命令返回狀態(tài)碼是0為成功。
tcpSocket
發(fā)起TCP Socket建立成功。
實(shí)例:vim pod2.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /index.html
port: 80
Pod管理-數(shù)據(jù)持久化和共享:
vim pod3.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-test1
labels:
test: centos
spec:
containers:
# 第一個(gè)容器
- name: hello-write
image: centos:7
command: [bash,-c,for i in {1..1000};do echo $i >> /data/hello;sleep 1;done]
# 第二個(gè)容器
- name: hello-read
image: centos:7
command: [bash,-c,for i in {1..1000};do cat $i >> /data/hello;sleep 1;done]
volumeMounts:
- name: data
mountPath: /data
# 數(shù)據(jù)卷
volumes:
- name: data
hostPath:
path: /data
Pod端口映射:
vim pod4.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- name: http
containerPort: 80
hostIP: 0.0.0.0
hostPort: 80
protocol: TCP
- name: https
containerPort: 443
hostIP: 0.0.0.0
hostPort: 443
protocol: TCP