簡體   English   中英

本地 docker 和 k8s 的反應不同

[英]Local docker and k8s react differently

我有一個基於nginx:alpine的簡單 docker-image。 在我本地的 docker-deamon 上,我可以毫無問題地啟動它。 但是當我通過 k8s 部署它時,容器無法啟動並出現以下錯誤:

2020/03/04 08:01:38 [emerg] 1#1: open() "/var/run/nginx.pid" failed (13: Permission denied)
nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied)

有人知道發生了什么嗎? 我敢打賭,k8s 集群有問題。

我的 dockerfile 看起來像這樣:

#Dockerfile
# build nginx-container
FROM nginx:alpine

# delete nginx-default-page and creates non root user
RUN rm -rf /usr/share/nginx/html/* \
  && addgroup --gid 98761 nonroot \
  && adduser -u 9876 -G nonroot --disabled-password nonroot \
  && touch /var/run/nginx.pid \
  && chown 9876:98761 /var/run/nginx.pid \
  && chown -R 9876:98761 /var/cache/nginx

# copy our conf and web into nginx
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY static-webfiles/* /usr/share/nginx/html/

USER 9876:98761

編輯

這是用於部署的 yaml。 沒有同名部署,我使用kubectl apply -f deloyment.yaml將其分配給kubectl apply -f deloyment.yaml 我確定使用 docker-image 進行部署。

#deployment.yaml
apiVersion: apps/v1
kind: Deployment

metadata:
  name: frontend
  labels:
    app: frontend
    environment: review

spec:
  replicas: 1
  revisionHistoryLimit: 1
  selector:
    matchLabels:
      app: frontend
      environment: review

  template:
    metadata:
      labels:
        app: frontend
        environment: review

    spec:
      containers:
        - name: frontend
          image: frontend:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8080

編輯²

在我的 mini-kube-cluster 上,相同的圖像運行沒有任何問題。

編輯³

我認為存在 docker-layer-caching 問題。 以前使用根映像的所有環境都無法解決此錯誤。 當我在本地構建 docker-image 並推送它時,一切都很好。
我在 Dockerfile 中唯一改變的是非 root 更新。

我將刪除我們存儲庫中的所有緩存版本,然后再試一次。

我很確定該錯誤來自kaniko。
看到這個https://github.com/GoogleContainerTools/kaniko/issues/550
https://github.com/GoogleContainerTools/kaniko/issues/647

因此,在我們更新 kaniko 之前,我們無法使用我們的管道構建本地圖像。

暫無
暫無

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

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