Named arguments not getting picked up from my kubernetes template

9/7/2018

I'm trying to update a kubernetes template that we have so that I can pass in arguments such as --db-config <value> when my container starts up.

This is obviously not right b/c there's not getting picked up

...
containers:
  - name: {{ .Chart.Name }}
  ...   
    args: ["--db-config", "/etc/app/cfg/db.yaml", "--tkn-config", "/etc/app/cfg/tkn.yaml"] <-- WHY IS THIS NOT WORKING
-- Catfish
docker
kubernetes

1 Answer

9/7/2018

Here's an example showing your approach working:

main.go:

package main

import "flag"
import "fmt"

func main() {

    db := flag.String("db-config", "default", "some flag")
    tk := flag.String("tk-config", "default", "some flag")


    flag.Parse()

    fmt.Println("db-config:", *db)
    fmt.Println("tk-config:", *tk)
}

Dockerfile [simplified]:

FROM scratch
ADD kube-flags /
ENTRYPOINT ["/kube-flags"]

Test:

docker run kube-flags:180906
db-config: default
tk-config: default

docker run kube-flags:180906 --db-config=henry
db-config: henry
tk-config: default

pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - image: gcr.io/.../kube-flags:180906
    imagePullPolicy: Always
    name: test
    args:
    - --db-config
    - henry
    - --tk-config
    - turnip

test:

kubectl logs test
db-config: henry
tk-config: turnip
-- DazWilkin
Source: StackOverflow