gpt4 book ai didi

kubernetes - minikube : how to add second container to the pod?

转载 作者:行者123 更新时间:2023-12-02 11:38:48 25 4
gpt4 key购买 nike

我正在寻求有关如何将第二个容器添加到现有 pod(我的意思是一个带有两个容器的 pod)的帮助。错误是 CrashLoopBackOff .我正在使用 minikube。我请求任何帮助解决问题将不胜感激。

wordpress.yaml
--------XXXX------------------
apiVersion: v1
kind: Service
metadata:
name: my-nginx-svc
labels:
app: nginx
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
- name: wordpress
image: wordpress
ports:
- containerPort: 80
#watch kubectl get pods

Every 2.0s: kubectl get pods cent8-minikube: Wed Jun 10 16:47:30 2020

NAME READY STATUS RESTARTS AGE
my-nginx-6b474476c4-9p4cn 1/1 Running 0 5h41m
my-nginx-6b474476c4-m2xkd 1/1 Running 0 5h41m
my-nginx-9f44b5996-744n5 1/2 CrashLoopBackOff 9 21m
my-nginx-9f44b5996-vl6g2 1/2 CrashLoopBackOff 9 22m
test-minikube-f4df69575-2sbl5 1/1 Running 0 26h
[root@cent8-minikube ~]# kubectl describe pod my-nginx-9f44b5996-vl6g2
Name: my-nginx-9f44b5996-vl6g2
Namespace: default
Priority: 0
Node: cent8-minikube/192.168.194.128
Start Time: Wed, 10 Jun 2020 16:25:14 -0700
Labels: app=nginx
pod-template-hash=9f44b5996
Annotations: <none>
Status: Running
IP: 172.17.0.8
IPs:
IP: 172.17.0.8
Controlled By: ReplicaSet/my-nginx-9f44b5996
Containers:
nginx:
Container ID: docker://5e4cfd4e726373916a105a95644a7a286966482e33eaaac986e44514aef86606
Image: nginx:1.14.2
Image ID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 10 Jun 2020 16:25:16 -0700
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
wordpress:
Container ID: docker://5e37277badca1658a10d4d826428f538a45d5e0eaecabd5e196f8b6ab5848ec7
Image: wordpress
Image ID: docker-pullable://wordpress@sha256:ff8be61894e74b6a005ab54ba73aa7084b6dbd11605f12ac383549763918bf09
Port: 80/TCP
Host Port: 0/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Wed, 10 Jun 2020 16:46:37 -0700
Finished: Wed, 10 Jun 2020 16:46:38 -0700
Ready: False
Restart Count: 9
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-lqnj8:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-lqnj8
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 23m default-scheduler Successfully assigned default/my-nginx-9f44b5996-vl6g2 to cent8-minikube
Normal Pulled 23m kubelet, cent8-minikube Container image "nginx:1.14.2" already present on machine
Normal Created 23m kubelet, cent8-minikube Created container nginx
Normal Started 23m kubelet, cent8-minikube Started container nginx
Normal Pulling 22m (x4 over 23m) kubelet, cent8-minikube Pulling image "wordpress"
Normal Pulled 22m (x4 over 23m) kubelet, cent8-minikube Successfully pulled image "wordpress"
Normal Created 22m (x4 over 23m) kubelet, cent8-minikube Created container wordpress
Normal Started 22m (x4 over 23m) kubelet, cent8-minikube Started container wordpress
Warning BackOff 3m35s (x95 over 23m) kubelet, cent8-minikube Back-off restarting failed container
[root@cent8-minikube ~]#
[root@cent8-minikube ~]# kubectl describe pod my-nginx-9f44b5996-744n5
Name: my-nginx-9f44b5996-744n5
Namespace: default
Priority: 0
Node: cent8-minikube/192.168.194.128
Start Time: Wed, 10 Jun 2020 16:25:33 -0700
Labels: app=nginx
pod-template-hash=9f44b5996
Annotations: <none>
Status: Running
IP: 172.17.0.10
IPs:
IP: 172.17.0.10
Controlled By: ReplicaSet/my-nginx-9f44b5996
Containers:
nginx:
Container ID: docker://9e3d6f0073e51eb475c2f2677fa413509f49a07c955d04b09417811d37ba8433
Image: nginx:1.14.2
Image ID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 10 Jun 2020 16:25:35 -0700
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
wordpress:
Container ID: docker://2ca8f22ab14b88973dca8d4d486f82a5b0d9bc7b84960882cff0a81afd744bf4
Image: wordpress
Image ID: docker-pullable://wordpress@sha256:ff8be61894e74b6a005ab54ba73aa7084b6dbd11605f12ac383549763918bf09
Port: 80/TCP
Host Port: 0/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Wed, 10 Jun 2020 16:46:41 -0700
Finished: Wed, 10 Jun 2020 16:46:42 -0700
Ready: False
Restart Count: 9
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-lqnj8:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-lqnj8
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 26m default-scheduler Successfully assigned default/my-nginx-9f44b5996-744n5 to cent8-minikube
Normal Pulled 26m kubelet, cent8-minikube Container image "nginx:1.14.2" already present on machine
Normal Created 26m kubelet, cent8-minikube Created container nginx
Normal Started 26m kubelet, cent8-minikube Started container nginx
Normal Pulling 25m (x4 over 26m) kubelet, cent8-minikube Pulling image "wordpress"
Normal Pulled 25m (x4 over 26m) kubelet, cent8-minikube Successfully pulled image "wordpress"
Normal Created 25m (x4 over 26m) kubelet, cent8-minikube Created container wordpress
Normal Started 25m (x4 over 26m) kubelet, cent8-minikube Started container wordpress
Warning BackOff 67s (x116 over 26m) kubelet, cent8-minikube Back-off restarting failed container
[root@cent8-minikube ~]#
``` [root@cent8-minikube ~]# kubectl logs my-nginx-9f44b5996-vl6g2 -c wordpress WordPress not found in /var/www/html - copying now... Complete! WordPress has been successfully copied to /var/www/html AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.8. Set the 'ServerName' directive globally to suppress this message (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down AH00015: Unable to open logs 
  • 如何向 Pod 添加第二个容器?
  • 在哪里检查崩溃容器的日志或如何调试?
  • 你能指导我,如何解决这个错误?
  • 最佳答案

    虽然我同意在单独的 Pod 中运行单独的应用程序,但有时将它们放在一起更容易。在目前的情况下,这可以通过以下方式实现:

    Wordpress 是硬配置,因此将 Nginx 移动到单独的端口更可行(如果不是完全直接的话)

        apiVersion: v1
    kind: ConfigMap
    metadata:
    name: nginx
    data:
    default.conf.template: |
    server {
    listen ${NGINX_PORT};
    server_name localhost;

    location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }
    }
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: my-nginx
    labels:
    app: nginx
    spec:
    replicas: 3
    selector:
    matchLabels:
    app: nginx
    template:
    metadata:
    labels:
    app: nginx
    spec:
    containers:
    - name: nginx
    image: nginx
    env:
    - name: NGINX_PORT
    value: "81"
    volumeMounts:
    - mountPath: /etc/nginx/templates/
    name: config
    ports:
    - containerPort: 81
    - name: wordpress
    image: wordpress
    ports:
    - containerPort: 80
    volumes:
    - name: config
    configMap:
    name: nginx

    关于kubernetes - minikube : how to add second container to the pod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62316293/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com