【问题标题】:Kubernetes how to run container only after volume(nfs) is mountedKubernetes如何仅在安装卷(nfs)后运行容器
【发布时间】:2016-05-29 01:07:21
【问题描述】:

官方 nginx 映像没有在我的设置中启动,因为我正在从这个 nfs 卷安装配置文件。我正在尝试使用如下所示的 bash 脚本来克服这个问题,但它不起作用。有什么建议? kubectl logs conteinerxxx -p 返回nginx: invalid option: "off"。但是nginx -g "daemon off;"似乎在我的外壳上运行良好。有没有更惯用的方式来做到这一点?顺便说一句,这是 DigitalOcean 上的一个 coreos 集群。

码头文件

//REPLACE THE OLD `CMD ["nginx", "-g", "daemon off;"]`
ADD nginxinit.sh /nginxinit.sh
ENTRYPOINT ["./nginxinit.sh"]

重击

#!/usr/bin/env bash
until mountpoint -q /etc/nginx; do
    echo "$(date) - wainting for NGINX config files to be mounted..."
    sleep 1
done

nginx -g "daemon off;"

RC

apiVersion: v1
kind: ReplicationController
metadata:
  name: mypod
  labels:
    name: mypod
spec:
  replicas: 1
  selector:
    name: mypod
  template:
    metadata:
      labels:
        name: mypod
    spec:
      containers:
        - image: cescoferraro/nginx
          name: myfrontend
          volumeMounts:
          - mountPath: "/etc/nginx"
            name: nginx-nfs
      volumes:
        - name: nginx-nfs
          persistentVolumeClaim:
            claimName: nginx-nfs

PV

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nginx-nfs
spec:
  capacity:
    storage: 32Mi
  accessModes:
    - ReadWriteMany
  nfs:
    # FIXME: use the right IP
    server: x.x.x.x
    path: "/nginx"

PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nginx-nfs
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 32Mi

【问题讨论】:

  • 既然您是从外部卷挂载配置文件,那么将“守护程序关闭”部分放在配置中不是更容易吗?或者之后添加它,例如:echo "daemon off;" >> /etc/nginx/nginx.conf ?
  • 是的!我很确定这个问题可以用 bash 解决,尽管我没有付出太多努力。我想知道是否没有 Kubernetes 方法来处理这种情况。我将尝试在 nginx 配置文件上使用 daemon off。目前我正在使用 nginx 配置,我将“docker cp”添加到我的 nfs 卷。
  • 嗨@CESCO,在挂载卷之前不应启动 pod——如果没有,那是一个错误。您多久可以重现此问题?
  • @PaulMorie 我复制 nginx 文件的方式有问题。 "docker cp containerxxx:/etc/nginx/* /tmp" 没有复制 conf.d 目录(愚蠢的我)。所以我修好了它,这一切都适用于我的形象。我虽然它可以与官方图像一起使用,但它没有。我看起来可以使用 nginx 图像重现

标签: nginx docker kubernetes


【解决方案1】:

最好将配置放入 configMap

      volumeMounts:
        - name: nfsvol
          mountPath: /srv/nfs/share
        - name: config-volume
          mountPath: /etc/nginx
  volumes:
    - name: nfsvol
      persistentVolumeClaim:
        claimName: nfs-pvc
    - name: config-volume
      projected:
        sources:
        - configMap:
            name: core-nginx-config
            items:
             - key: fastcgi_params
               path: fastcgi_params
             - key: mime.types
               path: mime.types
             - key: nginx.conf
               path: nginx.conf

【讨论】:

    猜你喜欢
    • 2017-10-21
    • 1970-01-01
    • 2019-11-18
    • 2019-12-18
    • 1970-01-01
    • 2020-09-07
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多