問題描述以及解決:
問題一 CrashLoopBackOff
如容器運行報如下錯誤:
且在describe和kubelet日志中沒有明確記錄原因,基本都是因為command命令不合法導致
如需要運行多條命令,使用;不要使用&&
如下示例:
command: ["/bin/sh"]
args: ["-c","/usr/local/bin/redis_start;while true;do echo hello;sleep 1;done"]
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
k8s的command對應如上docker命令的[COMMAND] [ARG...]
1. 但在k8里這樣報錯,top必須得有個參數,錯誤寫法:
apiVersion: v1 kind: Pod metadata: name: centos labels: app: centos spec: containers: - name: mycentos image: centos imagePullPolicy: IfNotPresent command: ["top",]
報錯是:env找不到...
給top加上參數:
apiVersion: v1 kind: Pod metadata: name: centos labels: app: centos spec: containers: - name: mycentos image: centos imagePullPolicy: IfNotPresent command: ["top","-b"]
也可以這樣寫:
apiVersion: v1 kind: Pod metadata: name: centos labels: app: centos spec: containers: - name: mycentos image: centos imagePullPolicy: IfNotPresent command: ["top"] args: ["-b"]
使用shell命令的寫法:
apiVersion: v1 kind: Pod metadata: name: centos labels: app: centos spec: containers: - name: mycentos image: centos imagePullPolicy: IfNotPresent command: ["/bin/sh"] args: ["-c","while true;do echo hello;sleep 1;done"]
或者這樣:
apiVersion: v1 kind: Pod metadata: name: centos labels: app: centos spec: containers: - name: mycentos image: centos imagePullPolicy: IfNotPresent command: ["/bin/sh","-c","while true;do echo hello;sleep 1;done"]