When deploying k8s resources from task runners (like Jenkins) its often convenient to use environment variables directly in the template, and then pre-process the template using envsubst before feeding it to kubectl apply.
That can be accomplished by the following one liner (assuming you have gettext GNU package installed, which provides envsubst):
envsubst < k8s_template.yml | kubectl apply -f -example k8s_template.yml:
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: $NAME
    image: nginx:1.7.9
    ports:
    - containerPort: 80In the above template, the NAME environment variable can be exported beforehand, and will get replaced.
Acknowledgements: