<p>In the <a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="nofollow noreferrer">installation guide</a> of setting up NGINX Ingress on Google Kubernetes Engine, you have to run the following command to generate a <code>clusterrolebinding</code>:</p>

<pre><code>kubectl create clusterrolebinding cluster-admin-binding \
  --clusterrole cluster-admin \
  --user $(gcloud config get-value account)
</code></pre>

<p>Since I'd like to automate the entire setup process I don't want to run this command every time I create a new cluster.</p>

<p>So I want to know if there is a way to create a configuration <code>.yaml</code> file which automatically applies the above <code>clusterrolebinding</code> to my cluster on GKE?</p>

<p>You can see the resulting yaml created by the kubectl command like so:</p>

<pre><code>kubectl create clusterrolebinding cluster-admin-binding \
  --clusterrole cluster-admin \
  --user $(gcloud config get-value account)
  --dry-run
  -o yaml
</code></pre>

<p>This will give you an output like this:</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  creationTimestamp: null
  name: cluster-admin-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: User
  name: your_user
</code></pre>

<p>You can then create a yaml file (e.j. <code>clusterrolebinding.yaml</code>) with its content and deploy to the cluster as you would with any other config file:</p>

<pre><code>kubectl create -f clusterrolebinding.yaml
</code></pre>

<p>I don't think this is going to be any easier to automate than the <code>kubectl create clusterrolebinding</code> command itself though, you still need to tell the cluster about this new binding.</p>
