簡體   English   中英

Docker映像無法在kubernetes中啟動

[英]Docker image doesn't start in kubernetes

我試圖弄清楚docker命令docker如何將docker run -p 8080:80 webapp到kubernetes yaml。 我有一個nginx dockerized,當我使用上述命令啟動它時,該圖像可以正常工作。 當我將其推送到kubernetes時,什么都沒有發生。

Dockerfile:

FROM nginx:1.13.3-alpine

COPY nginx/default.conf /etc/nginx/conf.d/

RUN rm -rf /usr/share/nginx/html/*

COPY ./dist /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]

我的Kubernetes部署

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: webapp-production
spec:
  replicas: 1
  template:
    metadata:
      name: webapp
      labels:
        app: webapp
        role: frontend
        env: production
    spec:
      containers:
      - name: webapp
        image: eu.gcr.io/projectxyz/webapp:1.0.0
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ENVIRONMENT
          value: "production"
        resources:
          limits:
            memory: "500Mi"
            cpu: "100m"
        imagePullPolicy: Always
        ports:
        - name: webapp
          containerPort: 8080

我的服務

kind: Service
apiVersion: v1
metadata:
  name: webapp
spec:
  selector:
    app: webapp
    role: frontend
  type: NodePort
  ports:
  - name: http
    port: 8080
  - name: external
    port: 80
    targetPort: 8080

我必須在kubernetes中運行命令嗎? 端口配置是否正確? 謝謝您的幫助。

///////編輯/////來自pod日志的消息: The selected container has not logged any messages yet.

您在此處定位了錯誤的端口。 從我看到的這個應用程序可以在端口80上啟動nginx,但是您的服務定義的目標是端點pod上的端口8080。 由於沒有流量到達nginx,因此不會在stdout訪問日志上記錄任何內容。 更改服務定義以將流量定向到正確的端口(80)上,這可以解決問題。

旁注:如果容器無法過早啟動/終止,您可能會在Pod上看到崩潰循環狀態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM