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

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...
NoWriterDateCnt.TitleFile(s)
12197정성태3/17/202011236VS.NET IDE: 144. .NET Core 콘솔 응용 프로그램을 배포(publish) 시 docker image 자동 생성 - 두 번째 이야기 [1]
12196정성태3/17/20209131오류 유형: 608. The ServicedComponent being invoked is not correctly configured (Use regsvcs to re-register).
12195정성태3/16/202010901.NET Framework: 902. C# - 프로세스의 모든 핸들을 열람 - 세 번째 이야기
12194정성태3/16/202013183오류 유형: 607. PostgreSQL - Npgsql.NpgsqlException: sorry, too many clients already
12193정성태3/16/20209912개발 환경 구성: 485. docker - SAP Adaptive Server Enterprise 컨테이너 실행 [1]
12192정성태3/14/202012352개발 환경 구성: 484. docker - Sybase Anywhere 16 컨테이너 실행
12191정성태3/14/202012721개발 환경 구성: 483. docker - OracleXE 컨테이너 실행 [1]
12190정성태3/14/20208799오류 유형: 606. Docker Desktop 업그레이드 시 "The process cannot access the file 'C:\Program Files\Docker\Docker\resources\dockerd.exe' because it is being used by another process."
12189정성태3/13/202013712개발 환경 구성: 482. Facebook OAuth 처리 시 상태 정보 전달 방법과 "유효한 OAuth 리디렉션 URI" 설정 규칙
12188정성태3/13/202016269Windows: 169. 부팅 시점에 실행되는 chkdsk 결과를 확인하는 방법
12187정성태3/12/20208595오류 유형: 605. NtpClient was unable to set a manual peer to use as a time source because of duplicate error on '...'.
12186정성태3/12/20209735오류 유형: 604. The SysVol Permissions for one or more GPOs on this domain controller and not in sync with the permissions for the GPOs on the Baseline domain controller.
12185정성태3/11/202010462오류 유형: 603. The browser service was unable to retrieve a list of servers from the browser master...
12184정성태3/11/202011825오류 유형: 602. Automatic certificate enrollment for local system failed (0x800706ba) The RPC server is unavailable. [3]
12183정성태3/11/202010217오류 유형: 601. Warning: DsGetDcName returned information for \\[...], when we were trying to reach [...].
12182정성태3/11/202011389.NET Framework: 901. C# Windows Forms - Vista/7 이후의 Progress Bar 업데이트가 느린 문제파일 다운로드1
12181정성태3/11/202012148기타: 76. 재현 가능한 최소한의 예제 프로젝트란? - 두 번째 예제파일 다운로드1
12180정성태3/10/20208773오류 유형: 600. "Docker Desktop for Windows" - EXPOSE 포트가 LISTENING 되지 않는 문제
12179정성태3/10/202020237개발 환경 구성: 481. docker - PostgreSQL 컨테이너 실행
12178정성태3/10/202011767개발 환경 구성: 480. Linux 운영체제의 docker를 위한 tcp 바인딩 추가 [1]
12177정성태3/9/202011340개발 환경 구성: 479. docker - MySQL 컨테이너 실행
12176정성태3/9/202010769개발 환경 구성: 478. 파일의 (sha256 등의) 해시 값(checksum) 확인하는 방법
12175정성태3/8/202010881개발 환경 구성: 477. "Docker Desktop for Windows"의 "Linux Container" 모드를 위한 tcp 바인딩 추가
12174정성태3/7/202010453개발 환경 구성: 476. DockerDesktopVM의 파일 시스템 접근 [3]
12173정성태3/7/202011454개발 환경 구성: 475. docker - SQL Server 2019 컨테이너 실행 [1]
12172정성태3/7/202016293개발 환경 구성: 474. docker - container에서 root 권한 명령어 실행(sudo)
... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...