본문 바로가기

리눅스

[kubernetes] 쿠버네티스 kubectl config 설정

728x90

쿠버네티스 kubectl config 설정

쿠버네티스 컨트롤러 서버(linux)

kubectl config view
$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://127.0.0.1:6443
  name: cluster.local
contexts:
- context:
    cluster: cluster.local
    user: kubernetes-admin
  name: kubernetes-admin@cluster.local
current-context: kubernetes-admin@cluster.local
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
ls -l /etc/kubernetes/admin.conf

외부 kubectl 피씨(mac)

mkdir -pv ~/.kube
cd ~/.kube
scp root@kube-control1:/etc/kubernetes/admin.conf ~/.kube/.
cp ~/.kube/admin.conf ~/.kube/config

config 편집

- server: https://127.0.0.1:6443

+ server: https://192.168.0.51:6443

vim ~/.kube/config
> vim ~/.kube/config
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0F...S0tLS0tCg==
    server: https://192.168.0.51:6443
  name: cluster.local
contexts:
...
kubectl config view
> kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://192.168.0.51:6443
  name: cluster.local
contexts:
- context:
    cluster: cluster.local
    user: kubernetes-admin
  name: kubernetes-admin@cluster.local
current-context: kubernetes-admin@cluster.local
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED

kubectl(client) 버전 및 kubernetes cluster(server) 버전 확인

kubectl version --output json | jq
> kubectl version --output json | jq

{
  "clientVersion": {
    "major": "1",
    "minor": "25",
    "gitVersion": "v1.25.2",
    "gitCommit": "5835544ca568b757a8ecae5c153f317e5736700e",
    "gitTreeState": "clean",
    "buildDate": "2022-09-21T14:25:45Z",
    "goVersion": "go1.19.1",
    "compiler": "gc",
    "platform": "darwin/arm64"
  },
  "kustomizeVersion": "v4.5.7",
  "serverVersion": {
    "major": "1",
    "minor": "24",
    "gitVersion": "v1.24.7",
    "gitCommit": "e6f35974b08862a23e7f4aad8e5d7f7f2de26c15",
    "gitTreeState": "clean",
    "buildDate": "2022-10-12T10:50:21Z",
    "goVersion": "go1.18.7",
    "compiler": "gc",
    "platform": "linux/amd64"
  }
}

컨텍스트 확인

kubectl config get-contexts
> kubectl config get-contexts
CURRENT   NAME                             CLUSTER         AUTHINFO           NAMESPACE
*         kubernetes-admin@cluster.local   cluster.local   kubernetes-admin

노드 확인

kubectl get nodes
> kubectl get nodes
NAME            STATUS     ROLES           AGE   VERSION
kube-control1   Ready      control-plane   32h   v1.24.7
kube-node1      Ready      <none>          32h   v1.24.7
kube-node2      Ready      <none>          32h   v1.24.7
kube-node3      Ready      <none>          32h   v1.24.7
kube-node4      NotReady   <none>          32h   v1.24.7
kube-node5      NotReady   <none>          32h   v1.24.7
kube-node6      NotReady   <none>          32h   v1.24.7

현재 네임스페이스 설정

kubectl config set-context --current --namespace=default
> kubectl config set-context --current --namespace=default
Context "kubernetes-admin@cluster.local" modified.

현재 네임스페이스 확인

kubectl config view | grep namespace
> kubectl config view | grep namespace
namespace: default

kubens 명령으로 현재 네임스페이스 확인

kubens

 

참고URL

- kubectx + kubens: Power tools for kubectl : https://github.com/ahmetb/kubectx

- [kubernetes] 쿠버네티스 워크로드 - 네임스페이스(namespaces) : https://scbyun.com/1347

 

728x90