Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kubernetes APIに Pod内からアクセスしてみた
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ry
July 27, 2020
Technology
2.1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kubernetes APIに Pod内からアクセスしてみた
ry
July 27, 2020
More Decks by ry
See All by ry
Kubernetesにおける学習基盤とLLMOpsの概要
ry
1
500
Kubernetesにおける推論基盤
ry
3
1.4k
eBPF Tools on Kubernetes part1
ry
0
410
Vault Secrets Operator Tutorial
ry
0
650
KyvernoとRed Hat ACMを用いたマルチクラスターの一元的なポリシー制御
ry
0
1.4k
明日から始められるKyvernoを用いたポリシー制御
ry
4
1k
CNDT2022 k8snovice Community introduction
ry
0
200
Policy Engine on Kubernetes
ry
1
1.5k
ConfigMap and Secret
ry
0
470
Other Decks in Technology
See All in Technology
AIエージェントの監視、思考を見るか行動を見るか / Monitoring AI Agents: Thoughts or Actions
yusukeshimizu
2
170
Gifu WordPress Meetup #200 に向けて、私たちには何ができるだろうか?/ 2026-11-07 Gifu WordPress Meetup
torounit
0
240
サボる子はいねぇがー!AgentCoreハーネスの脆弱性に学ぶ、エージェントの入力バリデーション
iwamot
PRO
5
310
IBC 2026 動画技術関連レポート / IBC 2026 Report
cyberagentdevelopers
PRO
2
450
Context Ontology Accelerator 入門 (業務データの意味を、AI エージェントに渡す)
inariku
PRO
3
590
Sizing, Benchmarking and Performance Tuning Apache Flink Clusters
rmetzger
0
140
生成AI時代のIAMのマニアックな話
takuros
6
2.8k
会社説明資料_最新版
demaecan
0
32k
長い仕事を任せる (Workflows、クラウドセッション、Kiro Web) | 目指せ Kiro マスター 10
inariku
PRO
3
150
2026 Apache Flink Community Checkpoint
rmetzger
0
200
Claude Codeで作ったアプリを安全に公開する/Built with Claude Japan 2026
yoshidashingo
0
210
llm-d に入門してみた / Try out llm-d
kota2and3kan
0
100
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
330
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.9k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
530
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
520
Darren the Foodie - Storyboard
khoart
PRO
4
4.1k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
560
Context Engineering - Making Every Token Count
addyosmani
9
1.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Transcript
機密 <会社名> 専用 バージョン 1.0 Kubernetes APIに Pod内からアクセスしてみた
自己紹介 ry (@URyo_0213) インフラエンジニア 主な仕事内容: - Storageの導入・設定 (+ 自動化) -
社内app作成 - 社内app基盤の運用・管理 (kubernetes with PKS)
機密 <会社名> 専用 バージョン 1.0 1. 今日学ぶこと 2. まず初めに 3.
Practice 4. まとめ Agenda
今日学ぶこと
今日学ぶこと 1 RBACについて 2 Pod内からKubernetes APIを叩く方法
まず初めに
Kubernetes API Kubernetesを操作する際の指示を受け取る口。 CLIツールである「kubectl」や、yaml形式で書かれた「manifest」 を用いた先では、このAPIを叩いています。
Kubernetes API へのアクセス クライアントからのアクセスが入ると、 ・Authentication(認証) アクセスが許可されているかを判断 ・Authorization(認可) 処理の権限を持っているのかを判断 ・Admission Control(リクエスト制御)
そのリクエストを受け入れるのかを判断 Authorization Authentication Client Admission Control Excecute
PodからAPIを叩くために必要なもの 1 Service Account 2 Role / Cluster Role 3
Role Binding / Cluster Role Binding
Service Account 01 kubernetes内で管理され、認証情報をPodに割り当てるリソース 特徴: ・Nampespaceに紐づく。 ・1つ1つに「Token」と「証明書」が割り当てられる。 ・Pod起動時にService Accountを必ず1つ割り当てる必要がある。 (指定しない場合、default
service accountが割り当てられる)
Service Account Token
Service Account Token による認証 1 HTTPリクエスト時、Service Account tokenをHeaderにいれる 2 Kubernetesは、どのService
Accountを使用しているかを認識 3 認証をpassする
Service Account による認可 (RBAC) Role Role Binding Service Account Cluster
Role Cluster Role Binding Service Account どういった操作を許可するのかを定めた Roleを作成し、Service Accountに対して RoleBindingを用いてRoleを紐づけることで権限を管理します。
Role / Cluster Role 02 付与する権限を指定するリソース Role vs Cluster Role
ここの違いは、Namespaceを跨げるかどうかです。 Cluster Roleは、Namespaceを跨いでCluster単位でリクエスト権限を与えることができま す。
Role / Cluster Role 設定フィールド rulesにリスト形式で指定。 基本は以下の3つを指定していく。 ・apiGroups リソースが含まれている APIのグループを指定
・resources このルールを適用するリソースを指定 ・verbs 指定したリソースに対して行う操作を指定 apiGroups resources create 作成 get / list 取得 / 一覧取得 delete 削除 update 更新 patch 一部変更 watch 変更の追跡 verbs
Role / Cluster Role manifest例 https://kubernetes.io/docs/reference/access-authn-authz/rbac/#command-line-utilities
Role Binding / Cluster Role Binding 03 RoleとService Account等を紐付けるリソース。 Role
BindingとCluster Role Bindingの違いは、 Roleと同様、Namespaceを跨げるかどうかです。
Role Binding / Cluster Role Binding manifest例
Practice
PodからAPIを叩くまでの準備 1 Service Account作成 2 Role / Cluster Role作成 3
Role Binding / Cluster Role Binding作成 4 Pod作成 5 Pod Setup
ちょっとその前に!! 今回のAPI 検証用のNamespaceを作成します。 # kubectl create ns apitest
Service Account作成 $ kubectl create sa admin-sa -n apitest $
kubectl get sa -n apitest NAME SECRETS AGE admin-sa 1 9s default 1 6m11s
Cluster Role作成 $ kubectl apply -f cluster-role.yaml -n apitest $
kubectl get clusterrole -n apitest \ |grep admin-role admin-role 98s
Cluster Role Binding作成 $ kubectl apply -f cluster-role.yaml -n apitest
$ kubectl get clusterrolebinding -n apitest \ |grep admin-rolebinding admin-rolebinding 63s
Pod作成 $ kubectl apply -f pod.yaml -n apitest $ kubectl
get pod -n apitest NAME READY STATUS RESTARTS AGE nginx 1/1 Running 0 2s
Podの中を見てみる Podに接続していきます。 $ kubectl exec -it nginx -- /bin/bash root@nginx:/#
環境変数 ・API アクセス先 KUBERNETES_PORT_443_TCP_ADDR KUBERNETES_PORT_443_TCP_PORT
Token Service AccountのTokenは /var/run/secrets/kubernetes.io/serviceaccount/token に格納されています。
ca.crt APIにアクセスする際に用いる証明書は /var/run/secrets/kubernetes.io/serviceaccount/ca.crt に格納されています。
Set up APIにアクセスする際に必要なパラメータを環境変数に仕込んでおきます。
Set up 必要なmoduleをダウンロードしておきます。 # apt update # apt install -y
curl # apt install -y vim APIへアクセスできるか確認してみましょう。 # curl -H "Authorization: Bearer $TOKEN" --cacert $CACERT https://$k8s/healthz ok
Deploymentの作成 APIに送るjsonファイルを作成しましょう。 # vi deployment.json
Deploymentの作成 APIにjsonファイルを送ります。 # curl -X POST -H "Authorization:Bearer $TOKEN" \
--cacert $CACERT -H 'Content-Type:application/json' \ -d @deployment.json https://$k8s/apis/apps/v1/namespaces/apitest/deployments apiGroup Namespace resoure
Deploymentの作成 適切なRBAC設定を行っていない場合、
Deploymentの確認 別terminalから確認します。 $ kubectl get pods -n apitest NAME READY
STATUS RESTARTS AGE apitest-nginx-78478c4bdc-27v7p 1/1 Running 0 50s apitest-nginx-78478c4bdc-v4fsl 1/1 Running 0 50s apitest-nginx-78478c4bdc-wjzn9 1/1 Running 0 50s nginx 1/1 Running 0 55m
Deploymentの確認 APIからも確認できます。 # curl -X GET -H "Authorization:Bearer $TOKEN" \
--cacert $CACERT \ https://$k8s/apis/apps/v1/namespaces/apitest/deployments/apitest-nginx
Deploymentの確認 APIでの確認結果 (長いので、途中まで)
Deploymentの削除 # curl -X DELETE -H "Authorization:Bearer $TOKEN" \ --cacert
$CACERT \ https://$k8s/apis/apps/v1/namespaces/apitest/deployments/apitest-nginx 成功時のstdout
まとめ
まとめ 1 RBACについては以下の3リソースを用いる。 Service Account, (Cluster)Role, (Cluster)Role Binding 2 Pod内からは、指定したService
Account の情報を使って Kubernetes APIを叩くことができる。
Thank you