简体   繁体   中英

How do I pass a script.sh file to a container while creating it using kubernetes from a yaml file and without changing the image file?

How do I pass a script.sh file to a container while creating it using kubernetes from the following ds-scheduler.yaml file and without changing the image file?

When kubernetes create the container from the yaml file, it uses a start.sh script residing inside the images file . I would like to push my my-start.sh file to the image file before kubelet creates container from it. So that kubelet uses my script instead of the one residing inside the image.

Thanks in advance.

ds-scheduler.YAML

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: scheduler-nodes
  labels:
    role: scheduler
spec:
  selector:
    matchLabels:
      role: scheduler
  template:
    metadata:
      labels:
        role: scheduler
    spec:
            #nodeSelector:
            # role: scheduler
      hostNetwork: true
      hostIPC: true
      containers:
      - name: scheduler-container
        image: hydroproject/cloudburst
  
        imagePullPolicy: Always
        env:
        - name: ROUTE_ADDR
          value: ROUTE_ADDR_DUMMY
        - name: MGMT_IP
          value: MGMT_IP_DUMMY
        - name: ROLE
          value: scheduler
        - name: REPO_ORG
          value: hydro-project
        - name: REPO_BRANCH
          value: master
        - name: ANNA_REPO_ORG
          value: hydro-project
        - name: ANNA_REPO_BRANCH
          value: master
        - name: POLICY
          value: locality
          # resources::
                # limits:
                  #ephemeral-storage: "64Mi"

You would generally build a new image with FROM hydroproject/cloudburst and then layer in your customizations.

Another option is to use ConfigMap volume mounts over key files however this can get tedious and error prone.

ConfigMap is best suited for your requirement. create a configMap and mount it as volume so that when you container starts up it will get that file from volume. for more info please checkout how you can mount configMap etc.

https://kubernetes.io/docs/concepts/configuration/configmap/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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