繁体   English   中英

Kubernetes如何仅在安装卷(nfs)之后运行容器

[英]Kubernetes how to run container only after volume(nfs) is mounted

正式的nginx映像无法在我的安装程序上启动,因为我正在从此nfs卷挂载配置文件。我正在尝试使用如下所示的bash脚本来克服此问题,但它无法正常工作。 有什么建议么? kubectl logs conteinerxxx -p返回nginx: invalid option: "off" 但是nginx -g "daemon off;" 似乎在我的shell上运行良好。 有没有更惯用的方法呢? 顺便说一句,这是DigitalOcean上的coreos集群。

dockerfile

//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

最好将配置放入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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM