성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] 그냥 RSS Reader 기능과 약간의 UI 편의성 때문에 사용...
[이종효] 오래된 소프트웨어는 보안 위협이 되기도 합니다. 혹시 어떤 기능...
[정성태] @Keystroke IEEE의 문서를 소개해 주시다니... +_...
[손민수 (Keystroke)] 괜히 듀얼채널 구성할 때 한번에 같은 제품 사라고 하는 것이 아...
[정성태] 전각(Full-width)/반각(Half-width) 기능을 토...
[정성태] Vector에 대한 내용은 없습니다. Vector가 닷넷 BCL...
[orion] 글 읽고 찾아보니 디자인 타임에는 InitializeCompon...
[orion] 연휴 전에 재현 프로젝트 올리자 생각해 놓고 여의치 않아서 못 ...
[정성태] 아래의 글에 정리했으니 참고하세요. C# - Typed D...
[정성태] 간단한 재현 프로젝트라도 있을까요? 저런 식으로 설명만 해...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>kubectl 수행 시 다른 k8s 클러스터로 접속하는 방법</h1> <p> docker의 경우 "-H" 옵션을 이용해,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Linux 운영체제의 docker를 위한 tcp 바인딩 추가 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12178'>https://www.sysnet.pe.kr/2/0/12178</a> Ubuntu 20.04 - docker를 위한 tcp 바인딩 추가 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12349'>https://www.sysnet.pe.kr/2/0/12349</a> </pre> <br /> 또 다른 docker 인스턴스에 접근하는 것이 가능했는데요, kubectl은 이것을 어떻게 할 수 있을까요? 이에 대한 방법을 다음의 글에서 잘 설명하고 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Mastering the KUBECONFIG file ; <a target='tab' href='https://ahmet.im/blog/mastering-kubeconfig/'>https://ahmet.im/blog/mastering-kubeconfig/</a> kubeconfig 파일을 사용하여 클러스터 접근 구성하기 ; <a target='tab' href='https://kubernetes.io/ko/docs/concepts/configuration/organize-cluster-access-kubeconfig/'>https://kubernetes.io/ko/docs/concepts/configuration/organize-cluster-access-kubeconfig/</a> </pre> <br /> 간단하게 정리해 볼까요? ^^<br /> <br /> <hr style='width: 50%' /><br /> <br /> <a target='tab' href='https://www.sysnet.pe.kr/2/0/12577'>지난 글</a>에, docker desktop for windows 환경에서 "Use the WSL 2 based engine" 옵션을 켜고 kind를 이용해 WSL 2와,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>kind create cluster --name cluster1</span> $ <span style='color: blue; font-weight: bold'>kubectl cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>45381</span> KubeDNS is running at https://127.0.0.1:45381/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy </pre> <br /> 윈도우 호스트 측에서 각각의 클러스터를 구성할 수 있다고 설명했습니다. (물론, --name의 값만 바꾸면 클러스터를 각각의 환경에서 원하는 대로 생성할 수 있습니다.)<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp\knd> <span style='color: blue; font-weight: bold'>kind create cluster --name cluster2</span> c:\temp\knd> <span style='color: blue; font-weight: bold'>kubectl cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>20971</span> KubeDNS is running at https://127.0.0.1:20971/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy </pre> <br /> 위와 같은 상황인 경우, WSL 2 측에서 kubectl을 이용해 (윈도우 측에서 생성한) cluster2를 대상으로 명령을 실행하고 싶다면 어떻게 해야 할까요?<br /> <br /> 간단한 방법이라면, cluster2에 대한 접근 정보를 가지고 있는 윈도우 측의 %USERPROFILE%\.kube\config 파일을 WSL 2 측에 (예를 들어 cluster2.config) 파일로 복사해,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > /* 윈도우: type "%USERPROFILE%\.kube\config" */ /* $HOME/.kube 디렉터리에 원래 있던 config 파일 */ $ <span style='color: blue; font-weight: bold'>cat $HOME/.kube/config</span> apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0tL...[생략]...tCg== server: https://127.0.0.1:45381 name: kind-cluster1 contexts: - context: cluster: kind-cluster1 user: kind-cluster1 name: kind-cluster1 current-context: kind-cluster1 kind: Config preferences: {} users: - name: kind-cluster1 user: client-certificate-data: LS0t...[생략]...Qo= client-key-data: LS0tLS...[생략]...tCg== /* 윈도우 측의 %USERPROFILE%\.kube\config을 WSL 2 측으로 복사해 온 파일 */ $ <span style='color: blue; font-weight: bold'>cat $HOME/.kube/cluster2.config</span> apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0t...[생략]...Cg== server: https://127.0.0.1:20971 name: kind-cluster2 contexts: - context: cluster: kind-cluster2 user: kind-cluster2 name: kind-cluster2 current-context: kind-cluster2 kind: Config preferences: {} users: - name: kind-cluster2 user: client-certificate-data: LS0t...[생략]...Qo= client-key-data: LS0tL...[생략]...o= </pre> <br /> 그 경로를 kubectl의 --kubeconfig 인자로 넘겨주면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>kubectl --kubeconfig=$HOME/.kube/cluster2.config cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>20971</span> KubeDNS is running at https://127.0.0.1:20971/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy </pre> <br /> 편의상, 명령을 자주 실행해야 한다면 KUBECONFIG 환경 변수를 이용해 지정해 두는 것도 가능합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // 기본 config 경로인 $HOME/.kube/config 정보로 k8s 클러스터 접근 $ <span style='color: blue; font-weight: bold'>kubectl cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>45381</span> KubeDNS is running at https://127.0.0.1:45381/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy // $HOME/.kube/cluster2.config 정보로 k8s 클러스터 접근 $ <span style='color: blue; font-weight: bold'>export KUBECONFIG=$HOME/.kube/cluster2.config</span> $ <span style='color: blue; font-weight: bold'>kubectl cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>20971</span> KubeDNS is running at https://127.0.0.1:20971/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy </pre> <br /> <hr style='width: 50%' /><br /> <br /> 또 다른 방법으로, 별도로 구성한 kubeconfig 파일을 마치 병합하는 듯한 효과를 줘서 kubectl 수행 시 --context 인자로 구분하는 것도 가능합니다. 이를 위해 KUBECONFIG 환경 변수를 다음과 같이 설정하고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>export KUBECONFIG=$HOME/.kube/config:$HOME/.kube/cluster2.config</span> </pre> <br /> 각각의 config 파일 내에 클러스터의 "name: " 항목에 지정하고 있는 이름을 --context 인자에 넘겨 사용할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > /* 어차피 기본 파일은 $HOME/.kube/config이 있으므로 아래의 명령어는 "kubectl cluster-info"로 대체 가능 */ $ <span style='color: blue; font-weight: bold'>kubectl --context=kind-cluster1 cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>45381</span> KubeDNS is running at https://127.0.0.1:45381/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy $ <span style='color: blue; font-weight: bold'>kubectl --context=kind-cluster2 cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>20971</span> KubeDNS is running at https://127.0.0.1:20971/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy </pre> <br /> 위와 같이 KUBECONFIG을 사용하면 매번 환경 변수를 지정해야 하는 불편함이 있는데, 이를 보완하기 위해 아예 하나의 config 파일로 합치는 방법도 있습니다. 수작업으로 kubeconfig yaml 문법에 맞게 병합할 수 있겠지만, 해당 기능을 kubectl 명령어의 옵션으로도 제공하므로 합쳐질 파일들의 목록을 KUBECONFIG 환경 변수로 전달해 다음과 같이 실행할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>export KUBECONFIG=$HOME/.kube/config:$HOME/.kube/cluster2.config</span> $ <span style='color: blue; font-weight: bold'>kubectl config view --merge --flatten > out.txt</span> $ <span style='color: blue; font-weight: bold'>cat out.txt</span> apiVersion: v1 <span style='color: blue; font-weight: bold'>clusters: - cluster:</span> certificate-authority-data: LS0t...[생략]...g== server: https://127.0.0.1:45381 <span style='color: blue; font-weight: bold'>name: kind-cluster1</span> <span style='color: blue; font-weight: bold'>- cluster:</span> certificate-authority-data: LS0...[생략]...== server: https://127.0.0.1:20971 <span style='color: blue; font-weight: bold'>name: kind-cluster2</span> contexts: - context: cluster: kind-cluster1 user: kind-cluster1 name: kind-cluster1 - context: cluster: kind-cluster2 user: kind-cluster2 name: kind-cluster2 <span style='color: blue; font-weight: bold'>current-context: kind-cluster1</span> kind: Config preferences: {} users: - name: kind-cluster1 user: client-certificate-data: LS...[생략]...Qo= client-key-data: LS0t...[생략]...g== - name: kind-cluster2 user: client-certificate-data: LS0...[생략]...tLQo= client-key-data: LS0t...[생략]...LQo= </pre> <br /> 이렇게 단일 kubeconfig 파일에 다수의 cluster 정보를 가진 경우 기본적으로는 "current-context"에 지정한 클러스터가 kubectl의 기본 명령어 대상이 됩니다. 실습을 위해 위와 같이 출력한 out.txt 파일을 <span class="tex2jax_ignore">$</span>HOME/.kube/config 파일로 복사해 놓고 다음의 명령어를 실행해 볼 수 있습니다. <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>kubectl cluster-info</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>45381</span> KubeDNS is running at https://127.0.0.1:45381/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy $ <span style='color: blue; font-weight: bold'>kubectl cluster-info --context=kind-cluster2</span> Kubernetes master is running at https://127.0.0.1:<span style='color: blue; font-weight: bold'>20971</span> KubeDNS is running at https://127.0.0.1:20971/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy /* <a target='tab' href='https://kubernetes.io/docs/reference/kubectl/cheatsheet/'>아울러 current-context를 명령어를 이용해 변경하는 것도 가능</a>하고! */ // kubeconfig 파일에 등록된 context 목록 $ <span style='color: blue; font-weight: bold'>kubectl config get-contexts</span> CURRENT NAME CLUSTER AUTHINFO NAMESPACE * kind-cluster1 kind-cluster1 kind-cluster1 kind-cluster2 kind-cluster2 kind-cluster2 // current-context의 값을 kind-clsuter2로 변경 $ <span style='color: blue; font-weight: bold'>kubectl config use-context kind-cluster2</span> $ <span style='color: blue; font-weight: bold'>kubectl config get-contexts</span> CURRENT NAME CLUSTER AUTHINFO NAMESPACE kind-cluster1 kind-cluster1 kind-cluster1 * kind-cluster2 kind-cluster2 kind-cluster2 </pre> <br /> 참고로 병합한 파일로부터 다시 특정 클러스터 설정만을 별도의 kubeconfig 파일로 뽑아내는 것도 가능합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>kubectl config view --minify --flatten --context=kind-cluster2 > cluster2.config</span> $ <span style='color: blue; font-weight: bold'>cat cluster2.config</span> apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0t...[생략]...Cg== server: https://127.0.0.1:20971 name: kind-cluster2 contexts: - context: cluster: kind-cluster2 user: kind-cluster2 name: kind-cluster2 current-context: kind-cluster2 kind: Config preferences: {} users: - name: kind-cluster2 user: client-certificate-data: LS0t...[생략]...LQo= client-key-data: LS0t...[생략]...LQo= </pre> <br /> <hr style='width: 50%' /><br /> <a name='create_config'></a> <br /> 원한다면, 자동 생성된 kubeconfig 파일을 kubectl 명령어를 이용해 직접 생성하는 것이 가능합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp\knd> <span style='color: blue; font-weight: bold'>kubectl config --kubeconfig=config-demo set-cluster kind-cluster3 --server=https://127.0.0.1:20971 --certificate-authority="ca-cert-in.crt"</span> c:\temp\knd> <span style='color: blue; font-weight: bold'>kubectl config --kubeconfig=config-demo set-credentials kind-cluster3 --client-certificate="cert-in.crt" --client-key="cert-in.key"</span> c:\temp\knd> <span style='color: blue; font-weight: bold'>kubectl config --kubeconfig=config-demo set-context kind-cluster3 --cluster=kind-cluster3 --user=kind-cluster3</span> c:\temp\knd> <span style='color: blue; font-weight: bold'>kubectl config --kubeconfig=config-demo use-context kind-cluster3</span> </pre> <br /> 그럼 다음과 같은 config-demo 파일이 생성됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > apiVersion: v1 clusters: - cluster: certificate-authority: ca-cert-in.crt server: https://127.0.0.1:20971 name: kind-cluster3 contexts: - context: cluster: kind-cluster3 user: kind-cluster3 name: kind-cluster3 current-context: kind-cluster3 kind: Config preferences: {} users: - name: kind-cluster3 user: client-certificate: cert-in.crt client-key: cert-in.key </pre> <br /> 인증서의 파일 경로는 kubectl을 실행한 경로에 대해 상대적으로 설정되는데요, 따라서 위의 경우에는 실행 시 해당 인증서를 현재의 디렉터리에서 찾을 수 있도록 인증서 및 키 파일을 복사하고 kubectl.exe를 실행해야 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // c:\temp\knd 디렉터리에 ca-cert-in.crt, cert-in.crt, cert-in.key 파일이 있다고 가정 c:\temp\knd> <span style='color: blue; font-weight: bold'>kubectl cluster-info --kubeconfig=config-demo</span> Kubernetes master is running at https://127.0.0.1:20971 KubeDNS is running at https://127.0.0.1:20971/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy </pre> <br /> 위의 내용을 실습하려면, config-demo 파일 내에 지정한 certificate-authority, client-certificate, client-key 인증서를 어떻게 구할 수 있느냐라는 문제가 남는데요, 이에 대해서는 다른 글을 통해 다뤄보도록 하겠습니다. ^^<br /> <br /> <hr style='width: 50%' /><br /> <br /> 그럴 경우가 많지 않겠지만, 이런 식으로 kind를 이용해 Windows 10에 k8s 클러스터를 구성한 경우 다른 컴퓨터에서 접속하고 싶다면 부가적인 작업을 더 해야 합니다. 우선, kind가 생성하는 기본 클러스터는 TCP 바인딩을 "127.0.0.1"로 고정하기 때문에,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp> <span style='color: blue; font-weight: bold'>kubectl cluster-info</span> Kubernetes master is running at https://<span style='color: blue; font-weight: bold'>127.0.0.1</span>:9272 KubeDNS is running at https://127.0.0.1:9272/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy c:\temp> <span style='color: blue; font-weight: bold'>netstat -ano | findstr 20971</span> TCP <span style='color: blue; font-weight: bold'>127.0.0.1</span>:20971 0.0.0.0:0 LISTENING 34208 </pre> <br /> 이것을 <a target='tab' href='https://kind.sigs.k8s.io/docs/user/configuration/#api-server'>"0.0.0.0"으로 바인딩을 바꾸기 위해 yml에 명시</a>하고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # cluster-config.yml kind: Cluster name: cluster3 apiVersion: kind.x-k8s.io/v1alpha4 networking: apiServerAddress: "0.0.0.0" </pre> <br /> 클러스터를 생성하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > c:\temp\wsl2> <span style='color: blue; font-weight: bold'>kind create cluster --config=cluster-config.yml</span> C:\temp\wsl2> <span style='color: blue; font-weight: bold'>docker ps</span> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 382ca15b6502 kindest/node:v1.20.2 "/usr/local/bin/entr…" 39 seconds ago Up 36 seconds <span style='color: blue; font-weight: bold'>0.0.0.0:16109->6443/tcp</span> cluster3-control-plane c:\temp\wsl2> <span style='color: blue; font-weight: bold'>netstat -ano | findstr 16109</span> TCP 0.0.0.0:16109 0.0.0.0:0 LISTENING 34208 TCP [::]:16109 [::]:0 LISTENING 34208 TCP [::1]:16109 [::]:0 LISTENING 25360 </pre> <br /> TCP 바인딩이 "0.0.0.0"으로 바뀌었습니다. 이제 %USERPROFILE\.kube\config 파일을 다른 컴퓨터에 복사하고, 아래의 "server" 주소만 "0.0.0.0"에서,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0tLS1...[생략]...Cg== server: https://<span style='color: blue; font-weight: bold'>0.0.0.0</span>:16109 name: kind-cluster3 ...[생략]... </pre> <br /> IP 주소(예를 들어, 이 글에서는 192.168.100.50이라고 가정)를 직접 기입한 후 kubectl.exe를 다음과 같이 실행해 볼 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>kubectl get pods</span> Unable to connect to the server: x509: certificate is valid for 10.96.0.1, 172.18.0.3, 0.0.0.0, not 192.168.100.50 </pre> <br /> 보는 바와 같이 <a target='tab' href='https://www.sysnet.pe.kr/2/0/12570#san'>허용된 DNS/IP가 인증서에 포함되어 있지 않기 때문에</a> 발생하는 오류입니다. 괜찮습니다, ^^ 이런 경우에도 "--insecure-skip-tls-verify" 옵션을 적용하면 되기 때문입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>kubectl cluster-info --insecure-skip-tls-verify</span> Kubernetes master is running at https://192.168.100.50:16109 KubeDNS is running at https://192.168.100.50:16109/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy C:\temp> <span style='color: blue; font-weight: bold'>kubectl run nginx-app --image nginx --port=80 --insecure-skip-tls-verify</span> pod/nginx-app created </pre> <br /> <hr style='width: 50%' /><br /> <br /> config 파일의 설정에서 특정 클러스터 정보를 삭제하려면 3번의 명령을 수행해야 합니다. 즉, 각 yaml 설정에서 users, contexts, clsuters에 추가된 항목의 이름을 알아내 개별 삭제합니다.<br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ kubectl config unset users.[지우려는 users의 name] $ kubectl config unset contexts.[지우려는 contexts의 name] $ kubectl config unset clusters.[지우려는 clusters의 name] </pre> <br /> 이후 만약 삭제한 클러스터가 current-context에 해당한다면 다음의 명령어로 다른 클러스터로 스위칭을 합니다.<br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ kubectl config use-context [...남아 있는 클러스터 이름...] </pre> <br /> <hr style='width: 50%' /><br /> <br /> 다음과 같이 kubeconfig 파일 변경 시 권한 오류가 발생한다면?<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > /* 사용자 명이 testusr인 경우 */ $ <span style='color: blue; font-weight: bold'>kubectl config set-context kindcluster2</span> error: open /home/testusr/.kube/config: permission denied </pre> <br /> 아마도 WSL 2의 config 파일을 윈도우 탐색기를 이용해 "\\wsl$\Ubuntu20.04\home\testusr\.kube" 디렉터리로 접근 후 직접 config 파일을 생성하는 등의 변경을 가해서 그런 경우일 수 있습니다. 실제로 권한을 확인해 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>ls -l /home/testusr/.kube</span> total 40 drwxr-x--- 4 testusr testusr 4096 Mar 21 16:25 cache -rw-r--r-- 1 <span style='color: blue; font-weight: bold'>root root</span> 10970 Mar 24 11:38 <span style='color: blue; font-weight: bold'>config</span> </pre> <br /> 라는 식으로 나올 텐데요, 다음과 같이 권한을 변경해 주면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>sudo chown $USER:$USER /home/testusr/.kube/config</span> </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
5745
(왼쪽의 숫자를 입력해야 합니다.)