{"id":2051,"date":"2020-06-17T20:58:29","date_gmt":"2020-06-17T17:58:29","guid":{"rendered":"https:\/\/artem.services\/?p=2003"},"modified":"2020-11-09T12:47:37","modified_gmt":"2020-11-09T09:47:37","slug":"2051","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=2051&lang=en","title":{"rendered":"Kubernetes &#8212; One role for multiple namespaces"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-full wp-image-149 alignleft\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo.png\" alt=\"\" width=\"844\" height=\"217\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo.png 844w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo-300x77.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2018\/10\/Kubernetes-Logo-768x197.png 768w\" sizes=\"(max-width: 844px) 100vw, 844px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>Goal:<\/h3>\n<p>There are 2 namespaces, they are &quot;<strong>kube-system<\/strong>&quot; and &quot;<strong>default<\/strong>&quot;. It is necessary to run a cron task in the &quot;<strong>kube-system<\/strong>&quot; namespace, which will clear the executed jobs and pods in the &quot;<strong>default<\/strong>&quot; space. To do this, create a service account in the &quot;<strong>kube-system<\/strong>&quot; namespace, a role with the necessary rights in the &quot;<strong>default<\/strong>&quot; namespace, and bind the created role for the created account.<\/p>\n<h3>cross-namespace-role.yaml<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\napiVersion: v1\r\nkind: ServiceAccount\r\nmetadata:\r\n  name: jobs-cleanup\r\n  namespace: kube-system\r\nautomountServiceAccountToken: false\r\n---\r\napiVersion: rbac.authorization.k8s.io\/v1beta1\r\nkind: Role\r\nmetadata:\r\n  name: jobs-cleanup\r\n  namespace: default\r\nrules:\r\n- apiGroups: [&quot;&quot;]\r\n  resources: [&quot;pods&quot;]\r\n  verbs: [&quot;get&quot;, &quot;watch&quot;, &quot;list&quot;, &quot;delete&quot;]\r\n- apiGroups: [&quot;batch&quot;, &quot;extensions&quot;]\r\n  resources: [&quot;jobs&quot;]\r\n  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;, &quot;delete&quot;]\r\n---\r\napiVersion: rbac.authorization.k8s.io\/v1\r\nkind: RoleBinding\r\nmetadata:\r\n  name: jobs-cleanup\r\n  namespace: default\r\nroleRef:\r\n  apiGroup: rbac.authorization.k8s.io\r\n  kind: Role\r\n  name: jobs-cleanup\r\nsubjects:\r\n- kind: ServiceAccount\r\n  name: jobs-cleanup\r\n  namespace: kube-system\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; Goal: There are 2 namespaces, they are &quot;kube-system&quot; and &quot;default&quot;. It is necessary to run a cron task in the &quot;kube-system&quot; namespace, which will clear the executed jobs and pods in the &quot;default&quot; space. To do this, create a service account in the &quot;kube-system&quot; namespace, a role with the necessary rights in the &hellip; <a href=\"https:\/\/artem.services\/?p=2051&#038;lang=en\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;Kubernetes &#8212; One role for multiple namespaces&quot;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[559],"tags":[549,551,1681,1683],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2051"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2051"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2051\/revisions"}],"predecessor-version":[{"id":2053,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/2051\/revisions\/2053"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}