1
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におけるsecurityContextの基本:Podレベルとコンテナレベルの違いと注意点

Posted at

こんにちは。今回は Kubernetes の securityContext に関する基本知識 と、Podレベルとコンテナレベルでの設定の違いについて解説します。


🔐 securityContext とは?

securityContext は、Pod やコンテナのセキュリティ設定を指定するためのフィールドです。
適切に設定することで、権限やユーザーID、Linux capabilities などを制御できます。


🧐 Podレベルとコンテナレベルの違い

Podレベルの securityContext

  • spec.securityContext 配下に設定します。
  • Pod 内のすべてのコンテナに共通の設定として適用されます。
  • 例:runAsUser(実行ユーザーID)などを指定可能。

コンテナレベルの securityContext

  • spec.containers[].securityContext 配下に設定します。
  • 各コンテナ単位で個別に設定可能。
  • capabilities(Linux capabilities の追加・削除)は コンテナレベルでのみ定義可能です。

⚠️ Capabilities はコンテナレベルのみ

capabilities は Linux の権限拡張機能ですが、必ずコンテナ単位の securityContext 内でのみ定義可能です。
Podレベルでの設定はサポートされていません。


🔄 runAsUser は両方で設定可能

runAsUser は実行時のユーザーIDを指定する項目で、

  • Podレベルの spec.securityContext.runAsUser
  • コンテナレベルの spec.containers[].securityContext.runAsUser

どちらにも設定可能です。
コンテナレベルの設定が優先されます。


📝 まとめ

設定場所 設定可能項目例 備考
Podレベル (spec.securityContext) runAsUser、fsGroup など Pod内すべてのコンテナに適用可能
コンテナレベル (spec.containers[].securityContext) runAsUser、capabilities 等 個別コンテナ単位で詳細設定可能。capabilities はここでのみ定義可

🎯 おわりに

Kubernetes の securityContext は、Pod全体に適用するかコンテナ単位で細かく制御するかを使い分けることが重要です。
特に capabilities はコンテナ単位でのみ設定可能な点に注意しましょう。

疑問や質問があれば、ぜひコメントで教えてくださいね 😊

1
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
1
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?