[update-2016-8] 在最新的Kubernetes版本中,您可以使用一个非常好的功能命名
init-container为替换
postStart下面我的答案中的部分,这将确保容器顺序。
apiVersion: v1kind: Podmetadata: name: javaweb-2spec: initContainers: - name: war image: resouer/sample:v2 command: ["cp", "/sample.war", "/app"] volumeMounts: - mountPath: /app name: app-volume containers: - name: tomcat image: resouer/mytomcat:7.0 command: ["sh","-c","/root/apache-tomcat-7.0.42-v2/bin/start.sh"] volumeMounts: - mountPath: /root/apache-tomcat-7.0.42-v2/webapps name: app-volume ports: - containerPort: 8080 hostPort: 8001 volumes: - name: app-volume emptyDir: {}
注意 :initContainer仍然是一个 beta功能,
因此该Yaml的工作版本实际上类似于:http : //kubernetes.io/docs/user-guide/production-
pods/#handling-initialization,请注意该
pod.beta.kubernetes.io/init-containers部分。
-原始答案开始-
其实可以。您需要使用容器生命周期处理程序来控制要与其他容器共享的文件/目录。喜欢:
---apiVersion: v1kind: Podmetadata: name: serverspec: restartPolicy: onFailure containers: - image: resouer/sample:v2 name: war lifecycle: postStart: exec: command: - "cp" - "/sample.war" - "/app" volumeMounts: - mountPath: /app name: hostv1 - name: peer image: busybox command: ["tail", "-f", "/dev/null"] volumeMounts: - name: hostv2 mountPath: /app/sample.war volumes: - name: hostv1 hostPath: path: /tmp - name: hostv2 hostPath: path: /tmp/sample.war
请检查我的要点以获取更多详细信息:
https://gist.github.com/resouer/378bcdaef1d9601ed6aa
当然,您可以使用emptyDir。因此,war容器可以将其/sample.war共享给对等容器,而不会陷入对等方的/ app目录。
如果我们可以容忍/ app被覆盖,它将更加简单:
---apiVersion: v1kind: Podmetadata: name: javaweb-2spec: restartPolicy: onFailure containers: - image: resouer/sample:v2 name: war lifecycle: postStart: exec: command: - "cp" - "/sample.war" - "/app" volumeMounts: - mountPath: /app name: app-volume - image: resouer/mytomcat:7.0 name: tomcat command: ["sh","-c","/root/apache-tomcat-7.0.42-v2/bin/start.sh"] volumeMounts: - mountPath: /root/apache-tomcat-7.0.42-v2/webapps name: app-volume ports: - containerPort: 8080 hostPort: 8001 volumes: - name: app-volume emptyDir: {}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)