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

时间:2016-02-17 11:01:59

标签: nginx docker kubernetes

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

dockerfile

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

的bash

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

1 个答案:

答案 0 :(得分:0)

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