{"id":31199,"date":"2024-03-12T11:23:46","date_gmt":"2024-03-12T10:23:46","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=31199"},"modified":"2024-03-12T11:23:49","modified_gmt":"2024-03-12T10:23:49","slug":"rancher-rke2-templates-assign-members-to-clusters","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/","title":{"rendered":"Rancher RKE2 templates &#8211; Assign members to clusters"},"content":{"rendered":"\n<p>When testing RKE2 templates, I faced an issue with member assignments. When creating the cluster, a management cluster name is generated with the format c-m-xxxxxxxx, but the ClusterRoleTemplateBinding requires the cluster name to work. After digging into Rancher source code, I found out how to set the management cluster name. So let&#8217;s start!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-force-the-cluster-name-with-rke2-templates\">Force the cluster name with RKE2 templates<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-investigation\">Investigation<\/h3>\n\n\n\n<p>When searching how the cluster name is generated when provisioning, I found the following code in the Rancher GitHub repository.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: go; title: ; notranslate\" title=\"\">\nfunc mgmtClusterName() (string, error) {\n\trand, err := randomtoken.Generate()\n\tif err != nil {\n\t\treturn &quot;&quot;, err\n\t}\n\treturn name.SafeConcatName(&quot;c&quot;, &quot;m&quot;, rand&#x5B;:8]), nil\n}\n<\/pre><\/div>\n\n\n<p>From the function mgmtClusterName I was able to find the following code.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: go; title: ; notranslate\" title=\"\">\nif mgmtClusterNameAnnVal, ok := cluster.Annotations&#x5B;mgmtClusterNameAnn]; ok &amp;&amp; mgmtClusterNameAnnVal != &quot;&quot; &amp;&amp; newCluster.Name == &quot;&quot; {\n\t\/\/ If the management cluster name annotation is set to a non-empty value, and the mgmt cluster name has not been set yet, set the cluster name to the mgmt cluster name.\n\tnewCluster.Name = mgmtClusterNameAnnVal\n} else if newCluster.Name == &quot;&quot; {\n\t\/\/ If the management cluster name annotation is not set and the cluster name has not yet been generated, generate and set a new mgmt cluster name.\n\tmgmtName, err := mgmtClusterName()\n\tif err != nil {\n\t\treturn nil, status, err\n\t}\n\tnewCluster.Name = mgmtName\n}\n<\/pre><\/div>\n\n\n<p>Which finally leads to the following annotation.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: go; title: ; notranslate\" title=\"\">\nmgmtClusterNameAnn    = &quot;provisioning.cattle.io\/management-cluster-name&quot;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-forced-the-management-cluster-name\">Forced the management cluster name<\/h3>\n\n\n\n<p>To avoid using the generated Cluster Name given by mgmtClusterName(), we can add the following annotation &#8220;provisioning.cattle.io\/management-cluster-name&#8221; into the cluster.provisioning.cattle.io resources.<\/p>\n\n\n\n<p>We can pick the same code from the Rancher template example in ClusterRoleTemplateBinding and do the following.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\napiVersion: provisioning.cattle.io\/v1\nkind: Cluster\nmetadata:\n  annotations:\n    provisioning.cattle.io\/management-cluster-name: c-m-{{ trunc 8 (sha256sum (printf &quot;%s\/%s&quot; $.Release.Namespace $.Values.cluster.name)) }}\n  {{- if .Values.cluster.annotations }}\n{{ toYaml .Values.cluster.annotations | indent 4 }}\n  {{- end }}\n<\/pre><\/div>\n\n\n<p>The template code above will ensure that the management cluster name will always be the one we generated ourselves.<br>Now let&#8217;s check the ClusterRoleTemplateBinding resource for automatically assigning users and groups.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-rke2-clusterroletemplatebinding\">RKE2 ClusterRoleTemplateBinding<\/h2>\n\n\n\n<p>To predefined users and groups into the cluster, we can use the template clusterroletemplatebinding.yaml.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n{{ $root := . }}\n{{- range $index, $member := .Values.clusterMembers }}\napiVersion: management.cattle.io\/v3\nclusterName: c-m-{{ trunc 8 (sha256sum (printf &quot;%s\/%s&quot; $root.Release.Namespace $root.Values.cluster.name)) }}\nkind: ClusterRoleTemplateBinding\nmetadata:\n  name: ctrb-{{ trunc 8 (sha256sum (printf &quot;%s\/%s\/%s&quot; $root.Release.Namespace $member.principalName $member.roleTemplateName )) }}\n  namespace: c-m-{{ trunc 8 (sha256sum (printf &quot;%s\/%s&quot; $root.Release.Namespace $root.Values.cluster.name)) }}\nroleTemplateName: {{ $member.roleTemplateName }}\nuserPrincipalName: {{ $member.principalName }}\n{{- end }}\n<\/pre><\/div>\n\n\n<p>For the metadata.name, I added the RoleTemplateName to avoid identical names if you add the same user with different roles.<\/p>\n\n\n\n<p>In the values.yaml you will need to provide the following information:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclusterMembers:\n- principalName: &quot;local:\/\/u-xxxxx&quot;\n   roleTemplateName: &quot;cluster-member&quot;\n- principalName: &quot;local:\/\/u-xxxxx&quot;\n   roleTemplateName: &quot;cluster-owner&quot;\n<\/pre><\/div>\n\n\n<p>When using only local users, it is easier as you only specify local:\/\/ with the ID of the user. But if you use groups, you may not know what value to provide. The same applies to your custom roles. The easiest way is to manually assign your members, and read the YAML files created.<\/p>\n\n\n\n<p>For this example, I am adding my GitHub group &#8220;teamA&#8221; as a cluster member, and a local user &#8220;autoscaler&#8221; as a cluster owner.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"340\" src=\"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png\" alt=\"\" class=\"wp-image-31104\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-300x99.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-768x255.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1536x509.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41.png 1912w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now go to More Resources &gt; RBAC &gt; ClusterRoleBindings and sort by age.<br>You should find the values to specify for principalName and roleTemplateName.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"352\" src=\"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-42-1024x352.png\" alt=\"\" class=\"wp-image-31105\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-42-1024x352.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-42-300x103.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-42-768x264.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-42-1536x528.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-42.png 1913w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-new-issues\">New issues<\/h2>\n\n\n\n<p>When the cluster is created for the first time, Rancher automatically creates the namespace. ClusterRoleTemplateBinding needs to be deployed into this namespace. Therefore it cannot be created at the creation of the cluster. In addition, it needs to wait for the Cluster resources to be provisioned by Rancher.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nhelm install --generate-name=true --namespace=fleet-default --timeout=10m0s --values=\/home\/shell\/helm\/values-dbiservices-template-ec2-0.0.1.yaml --version=0.0.1 --wait=true \/home\/shell\/helm\/dbiservices-template-ec2-0.0.1.tgz\n2024-02-28T12:57:21.998195671Z Error: INSTALLATION FAILED: 1 error occurred:\n2024-02-28T12:57:21.998226718Z \t* namespaces &quot;c-m-dc91e1f4&quot; not found\n\nor \n\n2024-03-04T11:48:15.121066673Z \t* admission webhook &quot;rancher.cattle.io.clusterroletemplatebindings.management.cattle.io&quot; denied the request: clusterroletemplatebinding.clusterName: Invalid value: &quot;c-m-dc91e1f4&quot;: specified cluster c-m-dc91e1f4 not found\n<\/pre><\/div>\n\n\n<p>Therefore, to ensure the assignment of users, the Helm charts must be updated after being deployed the first time.<\/p>\n\n\n\n<p>In the local &gt; Apps &gt; Installed Apps, in the fleet-default namespace, edit\/update the App, and redeploy it. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"268\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-105-1024x268.png\" alt=\"\" class=\"wp-image-31442\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-105-1024x268.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-105-300x79.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-105-768x201.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-105-1536x402.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-105-2048x536.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You don&#8217;t need to change any values. It will deploy correctly the ClusterRoleTemplateBinding and assign the users\/groups.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nhelm upgrade --history-max=5 --install=true --namespace=fleet-default --timeout=10m0s --values=\/home\/shell\/helm\/values-dbiservices-template-ec2-0.0.1.yaml --version=0.0.1 --wait=true dbiservices-template-ec2-0-1709125040 \/home\/shell\/helm\/dbiservices-template-ec2-0.0.1.tgz\n2024-02-28T13:02:07.755854608Z checking 6 resources for changes\n2024-02-28T13:02:07.770167607Z Patch Amazonec2Config &quot;dbiservices-template-rke2-ec2-template-controlplane&quot; in namespace fleet-default\n2024-02-28T13:02:07.795076109Z Patch Amazonec2Config &quot;dbiservices-template-rke2-ec2-template-workers&quot; in namespace fleet-default\n2024-02-28T13:02:07.831247897Z Patch Cluster &quot;dbiservices-template-rke2-ec2&quot; in namespace fleet-default\n2024-02-28T13:02:07.931325393Z Created a new ClusterRoleTemplateBinding called &quot;ctrb-d4063a0e&quot; in c-m-dc91e1f4\n2024-02-28T13:02:07.931347721Z \n2024-02-28T13:02:07.961962070Z Patch ManagedChart &quot;monitoring-crd-dbiservices-template-rke2-ec2&quot; in namespace fleet-default\n2024-02-28T13:02:08.027434827Z Patch ManagedChart &quot;monitoring-dbiservices-template-rke2-ec2&quot; in namespace fleet-default\n2024-02-28T13:02:08.065622593Z beginning wait for 6 resources with timeout of 10m0s\n2024-02-28T13:02:08.126940145Z Release &quot;dbiservices-template-ec2-0-1709125040&quot; has been upgraded. Happy Helming!\n2024-02-28T13:02:08.126959636Z NAME: dbiservices-template-ec2-0-1709125040\n2024-02-28T13:02:08.126964700Z LAST DEPLOYED: Wed Feb 28 13:02:06 2024\n2024-02-28T13:02:08.126969197Z NAMESPACE: fleet-default\n2024-02-28T13:02:08.126973071Z STATUS: deployed\n2024-02-28T13:02:08.126977312Z REVISION: 2\n2024-02-28T13:02:08.126981410Z TEST SUITE: None\n2024-02-28T13:02:08.150360499Z \n2024-02-28T13:02:08.150390675Z ---------------------------------------------------------------------\n2024-02-28T13:02:08.156224976Z SUCCESS: helm upgrade --history-max=5 --install=true --namespace=fleet-default --timeout=10m0s --values=\/home\/shell\/helm\/values-dbiservices-template-ec2-0.0.1.yaml --version=0.0.1 --wait=true dbiservices-template-ec2-0-17091\n\/home\/shell\/helm\/dbiservices-template-ec2-0.0.1.tgz\n2024-02-28T13:02:08.157013523Z ---------------------------------------------------------------------\n<\/pre><\/div>\n\n\n<p>The following member roles have been created for the clusters and are showing in the cluster configuration.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n- principalName: &quot;local:\/\/u-g9bq8&quot;\n  roleTemplateName: &quot;cluster-owner&quot;\n- principalName: &quot;github_team:\/\/8426662&quot;\n  roleTemplateName: &quot;cluster-member&quot;\n- principalName: &quot;local:\/\/u-g9bq8&quot;\n  roleTemplateName: &quot;rt-tz9xs&quot;\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"396\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-106-1024x396.png\" alt=\"\" class=\"wp-image-31443\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-106-1024x396.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-106-300x116.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-106-768x297.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-106-1536x595.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-106-2048x793.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-helm-lookup\">Helm lookup<\/h2>\n\n\n\n<p>Due to that issue with the namespace, setting the management cluster name doesn&#8217;t bring much advantage, as we need to manually redeploy the App (cluster template) to assign the users\/groups.<\/p>\n\n\n\n<p>Therefore we can use Helm function lookup, which can directly read the cluster name from the Kubernetes local cluster. Same as precedent, we need to redeploy the App (cluster template) the first time as it needs multiple resources to be provisioned by Rancher first.<\/p>\n\n\n\n<p>Here is the code for the clusterroletemplatebinding.yaml<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n{{- $root := . }}\n{{- $fetchedcluster :=  (lookup &quot;provisioning.cattle.io\/v1&quot; &quot;Cluster&quot; &quot;fleet-default&quot; .Values.cluster.name) }}\n{{- if ($fetchedcluster.status| default nil).clusterName | default nil }}\n  {{- range $index, $member := .Values.clusterMembers }}\n---\napiVersion: management.cattle.io\/v3\nclusterName: {{ $fetchedcluster.status.clusterName }}\nkind: ClusterRoleTemplateBinding\nmetadata:\n  name: ctrb-{{ trunc 8 (sha256sum (printf &quot;%s\/%s\/%s&quot; $root.Release.Namespace $member.principalName $member.roleTemplateName )) }}\n  namespace: {{ $fetchedcluster.status.clusterName }}\nroleTemplateName: {{ $member.roleTemplateName }}\nuserPrincipalName: {{ $member.principalName }}\n  {{- end }}\n{{- end }}\n<\/pre><\/div>\n\n\n<p>It will look into fleet-default for the cluster.provisionning.catte.io\/v1 that is created by the RKE2 templates itself. On the first deployment of the RKE2 templates, it doesn&#8217;t exist yet, therefore an &#8220;if&#8221; condition is added.<br>Once the RKE2 template is deployed, you can like precedently, edit the App to redeploy it, and it will then create the ClusterRoleTemplateBinding.<\/p>\n\n\n\n<p>The helm install will show no errors as the ClusterRoleTemplateBinding resources are skipped.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\nhelm install --generate-name=true --namespace=fleet-default --timeout=10m0s --values=\/home\/shell\/helm\/values-dbiservices-template-ec2-0.0.1.yaml --version=0.0.1 --wait=true \/home\/shell\/helm\/dbiservices-template-ec2-0.0.1.tgz\n2024-02-28T13:18:48.886232477Z creating 5 resource(s)\nbeginning wait for 5 resources with timeout of 10m0s\n2024-02-28T13:18:49.098629894Z NAME: dbiservices-template-ec2-0-1709126327\n2024-02-28T13:18:49.098705783Z LAST DEPLOYED: Wed Feb 28 13:18:47 2024\nNAMESPACE: fleet-default\nSTATUS: deployed\n2024-02-28T13:18:49.098717154Z REVISION: 1\n2024-02-28T13:18:49.098720727Z TEST SUITE: None\n2024-02-28T13:18:49.126871035Z \n2024-02-28T13:18:49.126936065Z ---------------------------------------------------------------------\n2024-02-28T13:18:49.135118662Z SUCCESS: helm install --generate-name=true --namespace=fleet-default --timeout=10m0s --values=\/home\/shell\/helm\/values-dbiservices-template-ec2-0.0.1.yaml --version=0.0.1 --wait=true \/home\/shell\/helm\/dbiservices-template-ec2-0.0.1.tgz\n---------------------------------------------------------------------\n<\/pre><\/div>\n\n\n<p>And then, when redeploying the App, it does show the creation of the resources as the cluster name now exists.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nhelm upgrade --history-max=5 --install=true --namespace=fleet-default --timeout=10m0s --values=\/home\/shell\/helm\/values-dbiservices-template-ec2-0.0.1.yaml --version=0.0.1 --wait=true dbiservices-template-ec2-0-1709126327 \/home\/shell\/helm\/dbiservices-template-ec2-0.0.1.tgz\nchecking 8 resources for changes\nPatch Amazonec2Config &quot;kke-test-template-controlplane&quot; in namespace fleet-default\nPatch Amazonec2Config &quot;kke-test-template-workers&quot; in namespace fleet-default\nPatch Cluster &quot;kke-test&quot; in namespace fleet-default\nCreated a new ClusterRoleTemplateBinding called &quot;ctrb-96090621&quot; in c-m-58wcfhnl\n2024-02-28T13:24:13.652797054Z \nCreated a new ClusterRoleTemplateBinding called &quot;ctrb-2c866242&quot; in c-m-58wcfhnl\n\nCreated a new ClusterRoleTemplateBinding called &quot;ctrb-d4063a0e&quot; in c-m-58wcfhnl\n2024-02-28T13:24:13.689031588Z \nPatch ManagedChart &quot;monitoring-crd-kke-test&quot; in namespace fleet-default\nPatch ManagedChart &quot;monitoring-kke-test&quot; in namespace fleet-default\nbeginning wait for 8 resources with timeout of 10m0s\nRelease &quot;dbiservices-template-ec2-0-1709126327&quot; has been upgraded. Happy Helming!\n2024-02-28T13:24:13.872941208Z NAME: dbiservices-template-ec2-0-1709126327\n2024-02-28T13:24:13.872946743Z LAST DEPLOYED: Wed Feb 28 13:24:11 2024\n2024-02-28T13:24:13.872951269Z NAMESPACE: fleet-default\n2024-02-28T13:24:13.872955002Z STATUS: deployed\n2024-02-28T13:24:13.872958850Z REVISION: 4\n2024-02-28T13:24:13.872962507Z TEST SUITE: None\n\n---------------------------------------------------------------------\nSUCCESS: helm upgrade --history-max=5 --install=true --namespace=fleet-default --timeout=10m0s --values=\/home\/shell\/helm\/values-dbiservices-template-ec2-0.0.1.yaml --version=0.0.1 --wait=true dbiservices-template-ec2-0-1709126327 \/home\/shell\/helm\/dbiservices-template-ec2-0.0.1.tgz\n---------------------------------------------------------------------\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"455\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-108-1024x455.png\" alt=\"\" class=\"wp-image-31449\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-108-1024x455.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-108-300x133.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-108-768x341.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-108-1536x683.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-108-2048x910.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"448\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-107-1024x448.png\" alt=\"\" class=\"wp-image-31448\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-107-1024x448.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-107-300x131.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-107-768x336.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-107-1536x673.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-107-2048x897.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>The assignment of users\/groups to a cluster through a template is not simple. My approach might be wrong but It was the first solution I thought of when I encountered the problem.<br>The issue of waiting for the creation (first deployment with Helm) is a little bit annoying but is not much of an issue when you are aware of redeploying the RKE2 template. Also if you use Fleet to continuously deploy\/update managed clusters, you could add the values for member configuration after the first deployment to avoid managing through the UI like above.<br><br>Below is the link to the GitHub Repository branch for the RKE2 templates using a fixed management cluster name and Helm function lookup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-sources\">Sources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Official documentation for RKE2 templates<br><a href=\"https:\/\/ranchermanager.docs.rancher.com\/how-to-guides\/new-user-guides\/manage-clusters\/manage-cluster-templates#rke2-cluster-template\">https:\/\/ranchermanager.docs.rancher.com\/how-to-guides\/new-user-guides\/manage-clusters\/manage-cluster-templates#rke2-cluster-template<\/a><\/li>\n\n\n\n<li>GitHub Branch for clusterroles<br><a href=\"https:\/\/github.com\/kkedbi\/cluster-template-examples\/tree\/clusterroles\">https:\/\/github.com\/kkedbi\/cluster-template-examples\/tree\/clusterroles<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-blog\">Blog<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RKE2 Autoscaling<br><a href=\"https:\/\/www.dbi-services.com\/blog\/rancher-autoscaler-enable-rke2-node-autoscaling\/\n\">https:\/\/www.dbi-services.com\/blog\/rancher-autoscaler-enable-rke2-node-autoscaling\/<\/a><\/li>\n\n\n\n<li>Reestablish administrator role access to rancher users<br><a href=\"https:\/\/www.dbi-services.com\/blog\/reestablish-administrator-role-access-to-rancher-users\/\">https:\/\/www.dbi-services.com\/blog\/reestablish-administrator-role-access-to-rancher-users\/<\/a><\/li>\n\n\n\n<li>Introduction and RKE2 cluster template for AWS EC2<br><a href=\"https:\/\/www.dbi-services.com\/blog\/?p=30957\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.dbi-services.com\/blog\/rancher-rke2-cluster-templates-for-aws-ec2<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When testing RKE2 templates, I faced an issue with member assignments. When creating the cluster, a management cluster name is generated with the format c-m-xxxxxxxx, but the ClusterRoleTemplateBinding requires the cluster name to work. After digging into Rancher source code, I found out how to set the management cluster name. So let&#8217;s start! Force the [&hellip;]<\/p>\n","protected":false},"author":132,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1320,1504,1522],"tags":[2667,2634,2276,309],"type_dbi":[3017,2943,3244],"class_list":["post-31199","post","type-post","status-publish","format-standard","hentry","category-devops","category-docker","category-kubernetes","tag-devops-2","tag-kubernetes-2","tag-rancher","tag-suse","type-devops","type-kubernetes","type-suse"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Rancher RKE2 templates - Assign members to clusters - dbi Blog<\/title>\n<meta name=\"description\" content=\"The assignment of users\/groups to a cluster through RKE2 templates is not simple. Let&#039;s see how with RKE2 templates concrete examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Rancher RKE2 templates - Assign members to clusters\" \/>\n<meta property=\"og:description\" content=\"The assignment of users\/groups to a cluster through RKE2 templates is not simple. Let&#039;s see how with RKE2 templates concrete examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-12T10:23:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-12T10:23:49+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png\" \/>\n<meta name=\"author\" content=\"K\u00e9vin Keovilay\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"K\u00e9vin Keovilay\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/\"},\"author\":{\"name\":\"K\u00e9vin Keovilay\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7\"},\"headline\":\"Rancher RKE2 templates &#8211; Assign members to clusters\",\"datePublished\":\"2024-03-12T10:23:46+00:00\",\"dateModified\":\"2024-03-12T10:23:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/\"},\"wordCount\":832,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png\",\"keywords\":[\"devops\",\"kubernetes\",\"Rancher\",\"SuSE\"],\"articleSection\":[\"DevOps\",\"Docker\",\"Kubernetes\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/\",\"name\":\"Rancher RKE2 templates - Assign members to clusters - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png\",\"datePublished\":\"2024-03-12T10:23:46+00:00\",\"dateModified\":\"2024-03-12T10:23:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7\"},\"description\":\"The assignment of users\/groups to a cluster through RKE2 templates is not simple. Let's see how with RKE2 templates concrete examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41.png\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41.png\",\"width\":1912,\"height\":634},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Rancher RKE2 templates &#8211; Assign members to clusters\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7\",\"name\":\"K\u00e9vin Keovilay\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g\",\"caption\":\"K\u00e9vin Keovilay\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/kevinkeovilay\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Rancher RKE2 templates - Assign members to clusters - dbi Blog","description":"The assignment of users\/groups to a cluster through RKE2 templates is not simple. Let's see how with RKE2 templates concrete examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/","og_locale":"en_US","og_type":"article","og_title":"Rancher RKE2 templates - Assign members to clusters","og_description":"The assignment of users\/groups to a cluster through RKE2 templates is not simple. Let's see how with RKE2 templates concrete examples.","og_url":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/","og_site_name":"dbi Blog","article_published_time":"2024-03-12T10:23:46+00:00","article_modified_time":"2024-03-12T10:23:49+00:00","og_image":[{"url":"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png","type":"","width":"","height":""}],"author":"K\u00e9vin Keovilay","twitter_card":"summary_large_image","twitter_misc":{"Written by":"K\u00e9vin Keovilay","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/"},"author":{"name":"K\u00e9vin Keovilay","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7"},"headline":"Rancher RKE2 templates &#8211; Assign members to clusters","datePublished":"2024-03-12T10:23:46+00:00","dateModified":"2024-03-12T10:23:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/"},"wordCount":832,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage"},"thumbnailUrl":"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png","keywords":["devops","kubernetes","Rancher","SuSE"],"articleSection":["DevOps","Docker","Kubernetes"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/","url":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/","name":"Rancher RKE2 templates - Assign members to clusters - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage"},"thumbnailUrl":"http:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41-1024x340.png","datePublished":"2024-03-12T10:23:46+00:00","dateModified":"2024-03-12T10:23:49+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7"},"description":"The assignment of users\/groups to a cluster through RKE2 templates is not simple. Let's see how with RKE2 templates concrete examples.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2024\/02\/image-41.png","width":1912,"height":634},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/rancher-rke2-templates-assign-members-to-clusters\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Rancher RKE2 templates &#8211; Assign members to clusters"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/3fb75c1e02be0c3b331471c8313cd9f7","name":"K\u00e9vin Keovilay","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/aea984148a511f3db5117060e702df298f486588cee7781bb56a7bd92ac44a50?s=96&d=mm&r=g","caption":"K\u00e9vin Keovilay"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/kevinkeovilay\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/31199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/132"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=31199"}],"version-history":[{"count":11,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/31199\/revisions"}],"predecessor-version":[{"id":31633,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/31199\/revisions\/31633"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=31199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=31199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=31199"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=31199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}