logo
发布于

k8s集群中从镜像中拷贝文件

1461-–
作者
  • avatar
    姓名
    zhli

为了保证镜像的完备性,通常会把业务系统需要的文件,比如nginx配置、数据库迁移脚本打包在镜像中。 在k8s集群中,可以使用下面的Job将镜像中文件copy出来,做下一步的处理:

apiVersion: batch/v1
kind: Job
metadata:
  name: xxxservice-copy-nginx
spec:
  backoffLimit: 0
  ttlSecondsAfterFinished: 30
  template:
    metadata:
      name: xxxservice-copy-nginx
    spec:
      restartPolicy: Never      
      containers:
        - name: xxxservice
          image: xxxservice:1.0
          command: ["sh","-c", "cp /app/xxx.conf /tmp/nginxconfig/"]
          volumeMounts:
          - name: nginx-config
            mountPath: /tmp/nginxconfig
      volumes:
      - name: nginx-config
        persistentVolumeClaim:
          claimName: nginx-config