7.\u7ed9\u7528\u6237\u521b\u5efa\u4e00\u4e2arole\u7684\u89d2\u8272devops.role.yaml<\/strong><\/span><\/div>\napiVersion:\u00a0rbac.authorization.k8s.io\/v1\r\nkind:\u00a0Role\r\nmetadata:\r\n\u00a0\u00a0name:\u00a0devops-role\r\n\u00a0\u00a0namespace:\u00a0architechure\r\nrules:\r\n-\u00a0apiGroups:\u00a0[\"\",\u00a0\"extensions\",\u00a0\"apps\"]\r\n\u00a0\u00a0resources:\u00a0[\"deployments\",\u00a0\"replicasets\",\u00a0\"pods\"]\r\n\u00a0\u00a0verbs:\u00a0[\"get\",\u00a0\"list\",\u00a0\"watch\",\u00a0\"create\",\u00a0\"update\",\u00a0\"patch\",\u00a0\"delete\"]\u00a0#\u00a0\u4e5f\u53ef\u4ee5\u4f7f\u7528['*']<\/pre>\n\u7136\u540e\u5728\u96c6\u7fa4\u4e2d\u521b\u5efa\u8be5\u89d2\u8272<\/p>\n
kubectl\u00a0apply\u00a0-f\u00a0.\/devops.role.yaml<\/pre>\n8.\u521b\u5efa\u6743\u9650\u4e0e\u89d2\u8272\u4e4b\u95f4\u7684\u7ed1\u5b9a\u5173\u7cfbdevops-rolebinding.yaml<\/strong><\/span><\/div>\napiVersion:\u00a0rbac.authorization.k8s.io\/v1\r\nkind:\u00a0RoleBinding\r\nmetadata:\r\n\u00a0\u00a0name:\u00a0devops-rolebinding\r\n\u00a0\u00a0namespace:\u00a0architechure\r\nsubjects:\r\n-\u00a0kind:\u00a0User\r\n\u00a0\u00a0name:\u00a0devops\r\n\u00a0\u00a0apiGroup:\u00a0\"\"\r\nroleRef:\r\n\u00a0\u00a0kind:\u00a0Role\r\n\u00a0\u00a0name:\u00a0devops-role\u00a0#\u00a0\u4e0a\u4e00\u6b65\u521b\u5efa\u7684devops-role\u5b9e\u4f53\r\n\u00a0\u00a0apiGroup:\u00a0\"\"<\/pre>\n\u5728\u96c6\u7fa4\u4e2d\u521b\u5efa\u89d2\u8272\u4e0e\u7528\u6237\u4e4b\u95f4\u7684\u7ed1\u5b9a\u5173\u7cfb<\/p>\n
k\u00a0apply\u00a0-f\u00a0.\/devops-rolebinding.yaml<\/pre>\n9.\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7kubecm\u5207\u6362\u5230\u8be5\u89d2\u8272\u4e0a<\/strong><\/span><\/div>\n<\/p>\n
\u6b64\u65f6\uff0c\u4ece\u4e0b\u56fe\u5c31\u53ef\u4ee5\u67e5\u770b\u5230\u5f53\u524d\u96c6\u7fa4\u7684\u6709\u4e00\u4e2a\u65b0\u7684\u7528\u6237\u89d2\u8272devops\uff0c\u4e0a\u9762\u7528\u5230\u7684Kubecm\u6211\u4eec\u4e4b\u524d\u4e5f\u5206\u4eab\u8fc7\uff0c\u5982\u679c\u9700\u8981\u53ef\u4ee5\u70b9\u6b64\u8df3\u8f6c<\/p>\n
<\/p>\n
10.\u6743\u9650\u9a8c\u8bc1<\/strong><\/span><\/div>\n>\u00a0kubectl\u00a0get\u00a0pods\r\nNo\u00a0resources\u00a0found\u00a0in\u00a0architechure\u00a0namespace.\r\n>\u00a0kubectl\u00a0get\u00a0replicasets\r\nNo\u00a0resources\u00a0found\u00a0in\u00a0architechure\u00a0namespace.\r\n>\u00a0kubectl\u00a0get\u00a0deploy\r\nNo\u00a0resources\u00a0found\u00a0in\u00a0architechure\u00a0namespace.\r\n>\u00a0kubectl\u00a0get\u00a0svc\r\nError\u00a0from\u00a0server\u00a0(Forbidden):\u00a0services\u00a0is\u00a0forbidden:\u00a0User\u00a0\"devops\"\u00a0cannot\u00a0list\u00a0resource\u00a0\"services\"\u00a0in\u00a0API\u00a0group\u00a0\"\"\u00a0in\u00a0the\u00a0namespace\u00a0\"architechure\"<\/pre>\n\u603b\u7ed3\u4e00\u4e0b\u5c31\u662f\uff1a<\/p>\n
\n- \u6839\u636e\u96c6\u7fa4\u7684CA\u8bc1\u4e66\u521b\u5efa\u51fa\u6765\u7528\u6237\u8bc1\u4e66<\/li>\n
- \u6839\u636e\u7528\u6237\u8bc1\u4e66\u521b\u5efa\u8be5\u7528\u6237\u5728\u96c6\u7fa4\u5185\u7684\u51ed\u8bc1\u548c\u4e0a\u4e0b\u6587\u5185\u5bb9<\/li>\n
- \u8981\u60f3\u7528\u6237\u80fd\u8fdb\u884c\u57fa\u672c\u7684\u64cd\u4f5c\uff0c\u9700\u8981\u5bf9\u7528\u6237\u9488\u5bf9apiGroup\u6388\u6743<\/li>\n<\/ul>\n
\u4e3adevops\u7528\u6237\u589e\u52a0\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\u7684\u6743\u9650<\/strong><\/div>\n1.\u6211\u4eec\u5148\u628a\u5f53\u524d\u4e0a\u4e0b\u6587\u5207\u6362\u5230\u4e4b\u524d\u6709\u6743\u9650\u64cd\u4f5c\u7684user-tf26gt9mmk\u7528\u6237\u4e0a<\/strong><\/span><\/div>\nkubecm\u00a0switch\r\n#\u00a0select\u00a0dev<\/pre>\n\u5426\u5219\u4ee5\u4e0b\u6b65\u9aa4\u4f1a\u51fa\u9519\uff1a<\/p>\n
2.\u9996\u5148\u9700\u8981\u521b\u5efa\u9488\u5bf9\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\u7684\u4e0a\u4e0b\u6587<\/strong><\/span><\/div>\nkubectl\u00a0config\u00a0set-context\u00a0devops-context\u00a0--cluster=cluster-tf26gt9mmk\u00a0--namespace=default\u00a0--user=devops<\/pre>\n\u6b64\u65f6\u67e5\u8be2\u5217\u4e3edefault\u7a7a\u95f4\u4e0b\u7684pods\u662f\u4e0d\u884c\u7684\uff0c\u56e0\u4e3a\u8fd8\u6ca1\u5141\u8bb8\u64cd\u4f5c<\/p>\n
kubectl\u00a0get\u00a0pods\u00a0--context=devops-context\r\nError\u00a0from\u00a0server\u00a0(Forbidden):\u00a0pods\u00a0is\u00a0forbidden:\u00a0User\u00a0\"devops\"\u00a0cannot\u00a0list\u00a0resource\u00a0\"pods\"\u00a0in\u00a0API\u00a0group\u00a0\"\"\u00a0in\u00a0the\u00a0namespace\u00a0\"default\"<\/pre>\n3.\u521b\u5efadefault\u7a7a\u95f4\u4e0b\u7684role\u4e0erolebinding<\/strong><\/span><\/div>\ndevops-role-default.yaml<\/p>\n
apiVersion:\u00a0rbac.authorization.k8s.io\/v1\r\nkind:\u00a0Role\r\nmetadata:\r\n\u00a0\u00a0name:\u00a0devops-role\r\n\u00a0\u00a0namespace:\u00a0default\r\nrules:\r\n-\u00a0apiGroups:\u00a0[\"\",\u00a0\"extensions\",\u00a0\"apps\"]\r\n\u00a0\u00a0resources:\u00a0[\"deployments\",\u00a0\"replicasets\",\u00a0\"pods\"]\r\n\u00a0\u00a0verbs:\u00a0[\"get\",\u00a0\"list\",\u00a0\"watch\",\u00a0\"create\",\u00a0\"update\",\u00a0\"patch\",\u00a0\"delete\"]\u00a0#\u00a0\u4e5f\u53ef\u4ee5\u4f7f\u7528['*']<\/pre>\ndevops-rolebinding-default.yaml<\/p>\n
apiVersion:\u00a0rbac.authorization.k8s.io\/v1\r\nkind:\u00a0RoleBinding\r\nmetadata:\r\n\u00a0\u00a0name:\u00a0devops-rolebinding\r\n\u00a0\u00a0namespace:\u00a0default\r\nsubjects:\r\n-\u00a0kind:\u00a0User\r\n\u00a0\u00a0name:\u00a0devops\r\n\u00a0\u00a0apiGroup:\u00a0\"\"\r\nroleRef:\r\n\u00a0\u00a0kind:\u00a0Role\r\n\u00a0\u00a0name:\u00a0devops-role\r\n\u00a0\u00a0apiGroup:\u00a0\"\"<\/pre>\n\u7136\u540e\u6211\u4eec\u5728\u96c6\u7fa4\u4e2d\u521b\u5efa\u8fd9\u4e24\u4e2a\u5bf9\u8c61<\/p>\n
kubectl\u00a0apply\u00a0-f\u00a0devops-role-default.yaml\r\nkubectl\u00a0apply\u00a0-f\u00a0devops-rolebinding-default.yaml<\/pre>\n4.\u67e5\u770brole\u8d44\u6e90\u5bf9\u8c61\u662f\u5426\u521b\u5efa<\/strong><\/span><\/div>\nkubectl\u00a0get\u00a0role\u00a0-A\u00a0|grep\u00a0devops-role\u00a0#\u00a0\u5206\u522b\u5728architechure\u548cdefault\u547d\u540d\u7a7a\u95f4\u4e0b\r\narchitechure\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0devops-role\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02021-05-17T07:57:27Z\r\ndefault\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0devops-role\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02021-05-28T03:19:24Z<\/pre>\n5.\u5207\u6362\u5f53\u524d\u4e0a\u4e0b\u6587\u73af\u5883\uff0c\u9a8c\u8bc1\u662f\u5426\u53ef\u4ee5\u64cd\u4f5c\u8d44\u6e90<\/strong><\/span><\/div>\nkubecm\u00a0switch\r\n#\u00a0select\u00a0devops-context\r\nkubectl\u00a0get\u00a0pods\u00a0-n\u00a0default\r\nkubectl\u00a0get\u00a0pods\u00a0-n\u00a0architechure<\/pre>\n\u5230\u8fd9\u91cc\u5c31\u57fa\u672c\u4e0a\u8bf4\u6e05\u695a\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u3001\u6388\u6743\u64cd\u4f5ck8s\u96c6\u7fa4\u7684\u8fc7\u7a0b\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
172.16.99.128\u662f\u7684\u6211k8s\u96c6\u7fa4\u7684master\u8282\u70b9\uff0c\u6b64\u5904\u662f\u4ece\u8fd9\u91cc\u83b7\u53d6\u96c6\u7fa4\u7684\u8bc1\u4e66\u3002 openssl\u00a0g […]<\/p>\n","protected":false},"author":323,"featured_media":84231,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-220597","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/220597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=220597"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/220597\/revisions"}],"predecessor-version":[{"id":220602,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/220597\/revisions\/220602"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/84231"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=220597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=220597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=220597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}