0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【簡単Kubernetes】【CKAD向け】KubernetesのRBACをシンプルに理解する:RoleとBindingの基本とServiceAccountとの連携

Posted at

Kubernetesにおけるアクセス制御の仕組み「RBAC(Role-Based Access Control)」について、基本的な流れとポイントを簡潔にまとめました。

📌 基本の流れ

RBACを使う場合、以下の順序で設定を行います:

  1. Role または ClusterRole の作成
  2. 対応する RoleBinding または ClusterRoleBinding の作成

🧩 RoleとBindingの違い

リソース 適用範囲
Role 特定のNamespace内に限定されるアクセス制御
ClusterRole クラスタ全体に適用されるアクセス制御
RoleBinding RoleとUser/Group/ServiceAccountをNamespace内で関連付ける
ClusterRoleBinding ClusterRoleをクラスタ全体でUser/Group/ServiceAccountに関連付ける

👥 subjects.kindの種類

RoleBindingClusterRoleBindingsubjects.kindには以下の3つがあります:

  • User: 個別のユーザー
  • Group: ユーザーのグループ
  • ServiceAccount: Podなどに割り当てるサービスアカウント

🛠️ ServiceAccountとPodの関連付け

  • PodserviceAccountNameを指定することで、PodはそのServiceAccountの権限で動作します。
  • ServiceAccountRoleClusterRoleとバインディングすることで、Podのアクセス権限を制御できます。
apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  serviceAccountName: example-sa
  containers:
  - name: app
    image: nginx

✅ まとめ

RBACの基本はシンプルです。

  • まず**権限(Role/ClusterRole)**を定義し、
  • 次に**それを誰に適用するか(RoleBinding/ClusterRoleBinding)**を決める。

特にServiceAccountと組み合わせれば、Pod単位で細かい権限制御が可能になります。
セキュリティ強化のためにも、ぜひ活用してみましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?