默认容器"container-1":容器 1、容器 2



在K8s中,我正在练习示例6.1。一个有两个容器共享相同体积的舱:幸运舱。kubernetes in Action。在卷概念中,我的pod包含2个容器,其中一个容器没有运行,请引导我在哪里我做错了。成功运行pod。在检查容器的日志时,我得到以下错误:

Defaulted container "fortune-cont" out of: fortune-cont, web-server 

但是在pod描述事件中,它看起来是这样的。

Events:
Type     Reason     Age                  From               Message
----     ------     ----                 ----               -------
Normal   Scheduled  40m                  default-scheduler  Successfully assigned book/vol-1-fd556f5dc-8ggj6 to minikube
Normal   Pulled     40m                  kubelet            Container image "nginx:alpine" already present on machine
Normal   Created    40m                  kubelet            Created container web-server
Normal   Started    40m                  kubelet            Started container web-server
Normal   Created    39m (x4 over 40m)    kubelet            Created container fortune-cont
Normal   Started    39m (x4 over 40m)    kubelet            Started container fortune-cont
Normal   Pulled     38m (x5 over 40m)    kubelet            Container image "xxxx/fortune:v1" already present on machine
Warning  BackOff    25s (x188 over 40m)  kubelet            Back-off restarting failed container

这是我的部署文件

apiVersion: apps/v1
kind: Deployment
metadata:
name: vol-1
namespace: book
spec:
replicas: 1
selector:
matchLabels:
name: fortune-vol-1
type: volume
template:
metadata:
labels:
name: fortune-vol-1
type: volume
spec:
containers:
- image: ****/fortune:v1
name: fortune-cont
volumeMounts:
- name: html 
mountPath: /var/htdocs
- image: nginx:alpine
name: web-server
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
readOnly: true
ports:
- containerPort: 80
protocol: TCP
volumes:
- name: html
emptyDir: {}

这是我对容器的pod描述。

Containers:
fortune-cont:
Container ID:   docker://3959e47a761b670ee826b2824efed09d8f5d6dfd6451c4c9840eebff018a3586
Image:          prav33n/fortune:v1
Image ID:       docker-pullable://prav33n/fortune@sha256:671257f6387a1ef81a293f8aef27ad7217e4281e30b777a7124b1f6017a330f8
Port:           <none>
Host Port:      <none>
State:          Waiting
Reason:       CrashLoopBackOff
Last State:     Terminated
Reason:       Completed
Exit Code:    0
Started:      Thu, 24 Nov 2022 02:05:26 +0530
Finished:     Thu, 24 Nov 2022 02:05:26 +0530
Ready:          False
Restart Count:  17
Environment:    <none>
Mounts:
/var/htdocs from html (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-spdq4 (ro)
web-server:
Container ID:   docker://37d831a2f7e97abadb548a21ecb20b5c784b5b3d6102cf8f939f2c13cdfd08c0
Image:          nginx:alpine
Image ID:       docker-pullable://nginx@sha256:455c39afebd4d98ef26dd70284aa86e6810b0485af5f4f222b19b89758cabf1e
Port:           80/TCP
Host Port:      0/TCP
State:          Running
Started:      Thu, 24 Nov 2022 01:02:55 +0530
Ready:          True
Restart Count:  0
Environment:    <none>
Mounts:
/usr/share/nginx/html from html (ro)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-spdq4 (ro)
Conditions:
Type              Status
Initialized       True 
Ready             False 
ContainersReady   False 
PodScheduled      True 
Volumes:
html:
Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:     
SizeLimit:  <unset>
kube-api-access-spdq4:
Type:                    Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds:  3607
ConfigMapName:           kube-root-ca.crt
ConfigMapOptional:       <nil>
DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type     Reason   Age                    From     Message
----     ------   ----                   ----     -------
Warning  BackOff  4m20s (x281 over 64m)  kubelet  Back-off restarting failed container

您的Pod命名为vol-1有两个容器:

  • 一个名为fortune-cont
  • 一个名为web-server

如果你运行kubectl logs vol-1, Kubernetes不知道你问的是哪个容器,所以它必须选择一个,并告诉你:

默认容器"fortune-cont"Out of: fortune- content, web-server

您可以使用-c选项显式地选择容器:

kubectl logs vol-1 -c web-server

您的财富容器在启动后立即终止,退出代码为0。在不知道它应该做什么的情况下,很难判断出哪里出了问题。退出代码0通常表示正常退出,没有错误。在kubernetes中,这通常是从init容器中导出的。那么,你的Pod规范错了吗,fortune应该是一个init容器?如果没有,可以使用-p标志显示先前终止的容器的日志退出:

kubectl logs vol-1 -c fortune-cont -p

也许这给了你一个提示为什么它退出。

相关内容

  • 没有找到相关文章

最新更新