KubeConfig
์ฌ๋ฌ Kubernetes ํด๋ฌ์คํฐ์ ์ ์ํ๊ธฐ ์ํด ์ ์ํ ํด๋ฌ์คํฐ ์ ๋ณด๋ฅผ KubeConfig์์ ๊ด๋ฆฌํ๋ค. Cluster์ User๋ฅผ ์ ์ํ๊ณ , ๋์ ์กฐํฉ์ธ Context๋ฅผ ๋ง๋ ๋ค.
KubeConfig ์์ฑ
KubeConfig ํ์ผ์ ๊ตฌ์ฑํ๋ค. clusters
, users
, contexts
๋ฅผ ์ฐจ๋ก๋ก ์ ์ํ๋ฉด ๋๋ค.
apiVersion: v1
kind: Config
clusters:
- name: development
cluster:
certificate-authority: fake-ca-file
server: https://1.2.3.4
- name: production
cluster:
certificate-authority: fake-ca-file
server: https://5.6.7.8
users:
- name: developer
user:
client-certificate: fake-cert-file
client-key: fake-key-file
- name: guest
user:
username: guest
password: password123
contexts:
- name: dev-frontend
context:
cluster: development
user: deveoper
namespace: frontend
- name: prod-guest
context:
cluster: production
user: guest
namespace: default
current-context: dev-frontend
kubectl config
ํฐ๋ฏธ๋์ ์ค์น๋ kubectl
์ .kube/config
๋ฅผ ๊ธฐ๋ณธ KubeConfig ํ์ผ๋ก ์ฌ์ฉํ๋ค. ์ฃผ์ํ ๋ช
๋ น์ด๋ฅผ ๋ช๊ฐ ์ดํด๋ณด์.
KubeConfig ํ์ธํ๊ธฐ
# ์ ์ฒด Config ํ์ธ
$ kubectl config view
# ํ์ฌ Config๋ง ํ์ธ
$ kubectl config view --minify
Context ๋ฐ๊พธ๊ธฐ
$ kubectl config use-context [context-name]
Context ๋ด์ฉ ๋ณ๊ฒฝ
์ฌ์ฉํ Namespace๋ฅผ ๋ฐ๊ฟ ๋ ์ฃผ๋ก ์ด๋ค.
# ํ์ฌ Context์ Namespace ๋ณ๊ฒฝ
$ kubectl config set-context --current --namespace=[NAMESPACE_NAME]
# ํน์ Context์ Namespace ๋ณ๊ฒฝ
$ kubectl config set-context [CONTEXT_NAME] --namespace=[NAMESPACE_NAME]
# Full Format
$ kubectl config set-context CONTEXT_NAME \
[--cluster=cluster_name] \
[--user=user_name] \
[--namespace=namespace_name]