Kubernets>Pod分析

一個Pod代表集羣上正在運行的一個進程。Pod是Kubernetes創建或部署的最小/最簡單的基本單位。 由一個或多個容器(container)構成的>集合,作爲一個整體被部署到一個單一節點。同一個 pod 中的容器共享 IP 地址、進程間通訊(IPC)、主機名以及其它資源。Pod 將底層>容器的網絡和存儲抽象出來,使得集羣內的容器遷移更爲便捷。


pod的狀態

kubectl -n namespace  get pod #查看一個命名空間下所有pod和其狀態

在這裏插入圖片描述


遇到的問題
在這裏插入圖片描述
可以看到一些pod的狀態爲ImagePullBackOff、CrashLoopBackOff、Pending

kubectl -n hummingbird describe pod mysql-hb-7c5cc54bd8-m8tmm #查看hummingbird命名空間下的pod mysql-hb-7c...的詳細信息
kubectl -n hummingbird logs mysql-hb-7c5cc54bd8-m8tmm #查看指定pod的日誌

可能會遇到報錯:

Error from server (BadRequest): a container name must be specified for pod mysql-hb-7c5cc54bd8-m8tmm, choose one of: [mysql-hb metrics] or one of the init containers: [remove-lost-found]

這是因爲 pod mysql-hb-7c5cc54bd8-m8tmm 啓動了兩個容器 mysql-hb metrics 和 remove-lost-found,
查看日誌時需要指定查看那個容器,可通過命令 -c <container_name>指定

kubectl -n hummingbird logs -f pod/mysql-hb-7c5cc54bd8-m8tmm -c mysql-hb #查看mysql-hb日誌
kubectl -n hummingbird logs -f pod/mysql-hb-7c5cc54bd8-m8tmm -c metrics #查看metrics日誌

出現以下錯誤

2020-02-24 01:04:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.28-1debian9 started.
2020-02-24 01:04:04+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-02-24 01:04:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.28-1debian9 started.
2020-02-24 01:04:05+00:00 [Note] [Entrypoint]: Initializing database files
2020-02-24T01:04:05.045945Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysqld: Can't create/write to file '/tmp/ibxkbsPe' (Errcode: 13 - Permission denied)
2020-02-24T01:04:05.082274Z 0 [ERROR] InnoDB: Unable to create temporary file; errno: 13
2020-02-24T01:04:05.082302Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2020-02-24T01:04:05.082324Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2020-02-24T01:04:05.082333Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-02-24T01:04:05.082347Z 0 [ERROR] Failed to initialize builtin plugins.
2020-02-24T01:04:05.082354Z 0 [ERROR] Aborting

mysqld: Can’t create/write to file ‘/tmp/ibxkbsPe’ (Errcode: 13 - Permission denied)
無法對文件進行寫入,初步推測是文件和路徑的問題,參考1參考2
進一步分析發現,mysql服務沒有啓動,

netstat -apn | grep 3306 #沒有反應
service mysql status #Unit mysql.service could not be found.找不到服務
systemctl restart mysqld.service #重啓還是找不到
chkconfig --list #查看服務列表,發現是沒有mysql服務的

參考解決一下試試,使用root:root用戶,創建/data/mysql目錄,不知道是不是要重啓pod,不會重啓,沒有成功
參考解決一下試試,還是沒有成功

kubectl -n namespace delete pods podname #刪除一個pod,刪除之後會被重建,只不過後綴名會不一樣

發現mysql的values.yaml與77有所不同
187的values.yaml:

# Custom mysql configuration files used to override default mysql settings
configurationFiles:
  mysql_custom.cnf: |-
    [mysqld]
    innodb_buffer_pool_size=2G
    max_connections=1000
    innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:5G
    innodb_file_per_table=1
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    tmpdir=/data/mysql

77的values.yaml
在這裏插入圖片描述
修改爲一樣的之後還是不行
最後

kubectl -n namespace edit deploy mysql-hb #查看服務的配置

參考文章
簡書----kubelet Pod 的狀態分析

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章