Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)
(시리즈 글이 3개 있습니다.)
개발 환경 구성: 553. Docker Desktop for Windows를 위한 k8s 대시보드 활성화
; https://www.sysnet.pe.kr/2/0/12567

개발 환경 구성: 566. Docker Desktop for Windows - k8s dashboard의 Kubeconfig 로그인 및 Skip 방법
; https://www.sysnet.pe.kr/2/0/12592

개발 환경 구성: 567. Docker Desktop for Windows - kubectl proxy 없이 k8s 대시보드 접근 방법
; https://www.sysnet.pe.kr/2/0/12593




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

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  [84]  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11836정성태3/5/201923206오류 유형: 525. Visual Studio 2019 Preview 4/RC - C# 8.0 Missing compiler required member 'System.Range..ctor' [1]
11835정성태3/5/201921728.NET Framework: 810. C# 8.0의 Index/Range 연산자를 .NET Framework에서 사용하는 방법 및 비동기 스트림의 컴파일 방법 [3]파일 다운로드1
11834정성태3/4/201920568개발 환경 구성: 432. Visual Studio 없이 최신 C# (8.0) 컴파일러를 사용하는 방법
11833정성태3/4/201921070개발 환경 구성: 431. Visual Studio 2019 - CMake를 이용한 공유/실행(so/out) 리눅스 프로젝트 설정파일 다운로드1
11832정성태3/4/201917004오류 유형: 524. Visual Studio CMake - rsync: connection unexpectedly closed
11831정성태3/4/201916816오류 유형: 523. Visual Studio 2019 - 새 창으로 뜬 윈도우를 닫을 때 비정상 종료
11830정성태2/26/201916511오류 유형: 522. 이벤트 로그 - Error opening event log file State. Log will not be processed. Return code from OpenEventLog is 87.
11829정성태2/26/201918257개발 환경 구성: 430. 마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법 - 리눅스 환경 [1]
11828정성태2/26/201926134개발 환경 구성: 429. Component Services 관리자의 RuntimeBroker 설정이 2개 있는 경우 [8]
11827정성태2/26/201919058오류 유형: 521. Visual Studio - Could not start the 'rsync' command on the remote host, please install it using your system package manager.
11826정성태2/26/201919246오류 유형: 520. 우분투에 .NET Core SDK 설치 시 패키지 의존성 오류
11825정성태2/25/201924458개발 환경 구성: 428. Visual Studio 2019 - CMake를 이용한 리눅스 빌드 환경 설정 [1]
11824정성태2/25/201918903오류 유형: 519. The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration. [1]
11823정성태2/21/201920616오류 유형: 518. IIS 관리 콘솔이 뜨지 않는 문제
11822정성태2/20/201918914오류 유형: 517. docker에 설치한 MongoDB 서버로 연결이 안 되는 경우
11821정성태2/20/201919680오류 유형: 516. Visual Studio 2019 - This extension uses deprecated APIs and is at risk of not functioning in a future VS update. [1]
11820정성태2/20/201922748오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201922030Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
11818정성태2/20/201920075VS.NET IDE: 131. Visual Studio 2019 Preview의 닷넷 프로젝트 빌드가 20초 이상 걸리는 경우 [2]
11817정성태2/17/201916446오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201919867Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201918107오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201916968오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201918314.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/201915616오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201920816오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
... 76  77  78  79  80  81  82  83  [84]  85  86  87  88  89  90  ...