Inject an Executable Script into a Container in Kubernetes

Inject an Executable Script into a Container
We want to execute a script inside a container
The Deployment
A volume is created from the ConfigMap with defaultMode: 0744, that’s what makes it executable. It’s then mounted to a /scripts dir but it could be mounted anywhere. The command: ["/scripts/wrapper.sh"] overrides the Docker image’s entry point and runs the wrapper.sh instead.
# cat deploy.yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ghost
  labels:
    role: blog
spec:
  replicas: 1
  template:
    metadata:
      labels:
        role: blog
    spec:
      containers:
      - name: ghost
        image: ghost:0.11-alpine
        command: ["/scripts/wrapper.sh"]
        ports:
        - name: ghost
          containerPort: 2368
          protocol: TCP
        volumeMounts:
        - name: wrapper
          mountPath: /scripts
      volumes:
      - name: wrapper
        configMap:
          name: wrapper
          defaultMode: 0744
The Code will Inject an Executable Script into a Container in Kubernetes




Recent Comments

No comments

Leave a Comment