Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Docker Desktop for Windows - k8s dashboard의 Kubeconfig 로그인 및 Skip 방법

Kubernetes 대시보드를 사용하는 경우,

Docker Desktop for Windows를 위한 k8s 대시보드 활성화
; https://www.sysnet.pe.kr/2/0/12567

로그인 방법이 "Token"과 "Kubeconfig" 2가지로 나뉩니다. 우선 Token의 경우 "Kubernetes - kube-apiserver와 REST API 통신하는 방법 (Docker Desktop for Windows 환경)" 글에서 설명했고, 매우 긴 token으로 매번 로그인 시 불편하다는 점이 있습니다. (사실, 웹 브라우저가 비밀번호를 저장해 주므로 다시 입력할 필요가 없어 현실적으로 딱히 불편하지는 않습니다. ^^)

그리고 Kubeconfig은 당연히 "%USERPROFILE%\.kube\config" 파일을 지정해 로그인하는 건데요, 일단 기본적으로는 아무 설정을 하지 않은 경우 해당 파일을 선택하면 다음과 같이 오류가 발생합니다.

k8s_dashboard_kubeconfig_1.png

Internal error (500): Not enough data to create auth info structuure.

왜냐하면 이것 역시 같은 토큰이 kubeconfig 파일에 등록되어 있어야 하기 때문입니다. 이를 위해, "Kubernetes - kube-apiserver와 REST API 통신하는 방법 (Docker Desktop for Windows 환경)"에서 설명한 방법에 따라 토큰을 구하거나,

c:\temp> kubectl get secrets
NAME                  TYPE                                  DATA   AGE
default-token-qnwbl   kubernetes.io/service-account-token   3      50d

c:\temp> kubectl describe secret default-token-qnwbl
Name:         default-token-qnwbl
Namespace:    default
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: default
              kubernetes.io/service-account.uid: 6a8f5d0c-db54-4018-b060-f311583546c0

Type:  kubernetes.io/service-account-token

Data
====
namespace:  7 bytes
token:      eyJhbGciOiJSUzI...[생략]...lzn1lGmAh1w
ca.crt:     1025 bytes

kube-system의 default 토큰 값을 간단하게 다음의 명령으로 구해,

c:\temp> kubectl -n kube-system describe secret default | findstr token:
token:      eyJhbGciOiJSUzI...[생략]...k89OlpNbpww

저 값을 아래의 명령어에 --token 인자로 전달, 실행하면 %USERPROFILE%\.kube\config 파일에 설정됩니다.

c:\temp> kubectl config set-credentials docker-desktop --token="eyJhbGciOiJSUzI...[생략]...lzn1lGmAh1w"
User "docker-desktop" set.

위에서 "set-credentials"의 인자로 전달된 "docker-desktop"은 docker desktop for windows가 구성한 "%USERPROFILE%\.kube\config" 파일에 있는 사용자 이름이 그렇게 설정되어 있기 때문에 그에 맞춘 것입니다.

c:\temp> type "%USERPROFILE%\.kube\config" | findstr /C:"\- name"
- name: docker-desktop

실행 후 %USERPROFILE%\.kube\config 파일을 확인해 보면 다음과 같이 users의 docker-desktop 항목에 "token: eyJhbG...[생략]...bpww" 필드가 나옵니다.

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0t...[생략]...tLQo=
    server: https://kubernetes.docker.internal:6443
  name: docker-desktop
contexts:
- context:
    cluster: docker-desktop
    user: docker-desktop
  name: docker-desktop
current-context: docker-desktop
kind: Config
preferences: {}
users:
- name: docker-desktop
  user:
    client-certificate-data: LS0tL...[생략]...0tLS0K
    client-key-data: LS0...[생략]...LQo=
    token: eyJhbG...[생략]...bpww

(그러니까, 그냥 단순하게 %USERPROFILE%\.kube\config 파일을 메모장으로 열어 "token: eyJhbG...[생략]...bpww" 문자열을 추가하고 저장해도 됩니다.)

이렇게 바뀐 %USERPROFILE%\.kube\config 파일을 다시 대시보드 로그인 화면에서 선택하고 "Sign in" 버튼을 누르면 로그인이 잘 됩니다. ^^

(참고로, 위에서 설정한 복잡한 방법을 "ukubectl.exe --set-default-token" 명령어를 사용하면 간단하게 kubeconfig 파일에 token 값이 설정됩니다.)




그런데, docker desktop의 특성상 로컬에서 개발 목적으로 테스트하는 환경이라면 로그인을 매번 하는 것이 귀찮습니다. 그리고 이걸 생략하는 방법을 제공하는데요,

Bypassing authentication for the local Kubernetes Cluster Dashboard
; https://devblogs.microsoft.com/premier-developer/bypassing-authentication-for-the-local-kubernetes-cluster-dashboard/

위의 글을 정리해 보면, 지난 글에서 설치한 대시보드 명령어 파일을,

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml

내려받아,

Invoke-WebRequest -Uri https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml -OutFile kubernetes-dashboard.yaml

편집기로 열어 "name: kubernetes-dashboard" 값을 갖는 "kind: Deployment" 섹션의 containers.args에 다음의 2 가지 옵션을 추가합니다. (yaml 파일의 195 라인)

--enable-skip-login
--disable-settings-authorizer

...[생략]...

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: kubernetes-dashboard
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
    spec:
      containers:
        - name: kubernetes-dashboard
          image: kubernetesui/dashboard:v2.2.0
          imagePullPolicy: Always
          ports:
            - containerPort: 8443
              protocol: TCP
          args:
            - --auto-generate-certificates
            - --namespace=kubernetes-dashboard
            - --enable-skip-login
            - --disable-settings-authorizer
            # Uncomment the following line to manually specify Kubernetes API server Host
            # If not specified, Dashboard will attempt to auto discover the API server and connect
            # to it. Uncomment only if the default does not work.

...[생략]...

저장 후, 다시 변경 사항을 반영해 주면,

c:\temp> kubectl apply -f .\kubernetes-dashboard.yaml
namespace/kubernetes-dashboard unchanged
serviceaccount/kubernetes-dashboard unchanged
service/kubernetes-dashboard unchanged
secret/kubernetes-dashboard-certs unchanged
secret/kubernetes-dashboard-csrf configured
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
secret/kubernetes-dashboard-key-holder configured
configmap/kubernetes-dashboard-settings unchanged
role.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
deployment.apps/kubernetes-dashboard configured
service/dashboard-metrics-scraper unchanged
deployment.apps/dashboard-metrics-scraper unchanged

이후 로그인 화면에 다음과 같이 "Skip" 버튼이 생기고,

k8s_dashboard_kubeconfig_2.png

Token, kubeconfig에 상관없이 그냥 skip 버튼을 누르면 dashboard 사용이 가능합니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 4/15/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13432정성태10/31/20232452오류 유형: 878. 탐색기의 WSL 디렉터리 접근 시 "Attempt to access invalid address." 오류 발생
13431정성태10/31/20232788스크립트: 60. 파이썬 - 비동기 FastAPI 앱을 gunicorn으로 호스팅
13430정성태10/30/20232675닷넷: 2153. C# - 사용자가 빌드한 ICU dll 파일을 사용하는 방법
13429정성태10/27/20232958닷넷: 2152. Win32 Interop - C/C++ DLL로부터 이중 포인터 버퍼를 C#으로 받는 예제파일 다운로드1
13428정성태10/25/20233033닷넷: 2151. C# 12 - ref readonly 매개변수
13427정성태10/18/20233246닷넷: 2150. C# 12 - 정적 문맥에서 인스턴스 멤버에 대한 nameof 접근 허용(Allow nameof to always access instance members from static context)
13426정성태10/13/20233407스크립트: 59. 파이썬 - 비동기 호출 함수(run_until_complete, run_in_executor, create_task, run_in_threadpool)
13425정성태10/11/20233193닷넷: 2149. C# - PLinq의 Partitioner<T>를 이용한 사용자 정의 분할파일 다운로드1
13423정성태10/6/20233171스크립트: 58. 파이썬 - async/await 기본 사용법
13422정성태10/5/20233314닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리
13421정성태10/4/20233393닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/20235579스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/20233218스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/20233922닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/20233451닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/20233256오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/20233754닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions)
13414정성태9/16/20233510디버깅 기술: 193. Windbg - ThreadStatic 필드 값을 조사하는 방법
13413정성태9/14/20233708닷넷: 2143. C# - 시스템 Time Zone 변경 시 이벤트 알림을 받는 방법
13412정성태9/14/20236987닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233489Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20235027닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233885닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233837Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233584닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233552VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...