Search code examples
kubernetesopenshiftkubectl

How to set env with dashes?


How to set env with dashes?

I execute the command:

kubectl set env deployment/service "--cron.updates=0 */10 8-9 * * *" 

And get error:

Error: unknown flag: --cron.full-update-check-status See 'oc set env --help' for usage.

How to add environment to service with dashes?


Solution

  • Solution-1:

    Use single quotes

    kubectl set env deployment/foo  -- "--cron.updates='0 */10 8-9 * * *'"
    

    This would change the env of the pod to:

    k exec -it foo-78fff84996-5mskb -- printenv |grep cron.updates
    --cron.updates='0 */10 8-9 * * *'
    

    Solution-2:

    Disable glob , which would prevent use of single quotes.

    You may disable glob and do the following:

    set -f #disable glob
    kubectl set env deployment/foo  -- "--cron.updates1=0 */10 8-9 * * *"
    set +f #enable glob
    

    This would also work, example output:

    k exec -it foo-5d4998668b-6gc9j  -- printenv |grep cron.updates
    --cron.updates='0 */10 8-9 * * *'
    --cron.updates1=0 */10 8-9 * * *