<p>I am trying to create a <code>Role</code> and <code>RoleBinding</code> so I can use Helm. I want to use variable substitution somehow to replace <code>{{namespace}}</code> with something when I run an <code>apply</code> command.</p>

<pre><code>kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager-{{namespace}}
  namespace: {{namespace}}
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]
</code></pre>

<p>I want to pass the namespace something like this:</p>

<blockquote>
  <p>kubectl apply --file role.yaml --namespace foo</p>
</blockquote>

<p>I have seen that <code>kubectl apply</code> has a <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands" rel="nofollow noreferrer">--template</a> parameter but I can't see much information about how it might be used.</p>

Muhammad Rehan Saeed
<p>You can do it in following way.</p>

<ol>
<li><p>Write <code>Role</code> file like this:</p>

<pre><code>kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager-${NAMESPACE}
  namespace: ${NAMESPACE}
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]
</code></pre></li>
<li><p>Set <code>NAMESPACE</code> environment variable to your desired value.</p></li>
<li><p>Then create Role using following command</p>

<pre><code>envsubst &lt; role.yaml | kubectl apply -f -
</code></pre></li>
</ol>
