Kubernetes how inject commands before entrypoint

Adding commands before an entrypoint.

Kubernetes how inject commands before entrypoint
Page content

Introduction

This will be a quick short blog entry. Today I had an image running on Kubernetes from a vender invoked through HELM, and I needed to run some arbtirary commands however I did not want to extend the image and have to deal with maintaining yet another image. Below is the solution I came up with.

YAML to inject commands before entry point.

image:
  repository: docker.io/user/image
  pullPolicy: IfNotPresent
  tag: "latest"
  command:
   - bash
   - "-c"
   - |
     sed -i 's/^param=.*/param=newvalue/g' /path/to/folder/file.properties  
     # Additional commands go here   
     # Then original entrypoint
     /entrypoint     

First you need to inspect the image and determine what the existing entrypoint is. Next you can override the entrypoint with essentially inline bash commands, and then call the original entrypoint after the additional commands are executed.