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

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  [112]  113  114  115  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11125정성태1/7/201724395개발 환경 구성: 310. IIS - appcmd.exe를 이용해 특정 페이지에 클라이언트 측 인증서를 제출하도록 설정하는 방법
11124정성태1/4/201727830개발 환경 구성: 309. 3년짜리 유효 기간을 제공하는 StartSSL [2]
11123정성태1/3/201723335.NET Framework: 629. .NET Core의 dotnet.exe CLI 명령어 확장 방법 [1]
11122정성태1/3/201722804.NET Framework: 628. TransactionScope에 사용자 정의 트랜잭션을 참여시키는 방법 [2]파일 다운로드1
11121정성태1/1/201720698개발 환경 구성: 308. "ASP.NET Core Web Application (.NET Core)"와 "ASP.NET Core Web Application (.NET Framework)" 차이점
11120정성태12/25/201626565개발 환경 구성: 307. ASP.NET Core Web Application을 IIS에서 호스팅하는 방법
11119정성태12/23/201649227개발 환경 구성: 306. Visual Studio Code에서 Python 개발 환경 구성 [2]
11118정성태12/22/201635992오류 유형: 374. Python 64비트 설치 시 0x80070659 오류 발생 [3]
11117정성태12/21/201622312웹: 35. nopCommerce 예제 사이트 구성 방법
11116정성태12/21/201624260디버깅 기술: 84. NopCommerce의 Autofac 부하(CPU, Memory) [2]
11115정성태12/21/201627236Windows: 133. 윈도우 서버 2016에서 플래시가 동작하지 않는 경우 [2]
11114정성태12/19/201637245Windows: 132. 역슬래시(backslash) 문자가 왜 통화 표기 문자(한글인 경우 "\")로 보일까요? [2]
11113정성태12/6/201621127오류 유형: 373. ICOMAdminCatalog::GetCollection에서 CO_E_ISOLEVELMISMATCH(0x8004E02F) 오류 발생파일 다운로드1
11112정성태11/23/201626307오류 유형: 372. MySQL 서비스가 올라오지 않는 경우 - Error 1067
11111정성태11/23/201634785.NET Framework: 627. C++로 만든 DLL을 C#에서 사용하기 [2]
11110정성태11/17/201621459.NET Framework: 626. Commit 메모리가 낮은 상황에서도 메모리 부족(Out-of-memory) 예외 발생 [2]
11109정성태11/17/201621445.NET Framework: 625. ASP.NET에서 System.Web.HttpApplication 인스턴스는 다중으로 생성됩니다.
11108정성태11/13/201621260.NET Framework: 624. WPF - Line 요소를 Canvas에 위치시켰을 때 흐림(blur) 현상파일 다운로드1
11107정성태11/9/201625152오류 유형: 371. Post cache substitution is not compatible with modules in the IIS integrated pipeline that modify the response buffers.파일 다운로드1
11106정성태11/8/201625321.NET Framework: 623. C# - PeerFinder를 이용한 Wi-Fi Direct 데이터 통신 예제 [2]파일 다운로드1
11105정성태11/8/201619720.NET Framework: 622. PeerFinder Wi-Fi Direct 통신 시 Read/Write/Dispose 문제
11104정성태11/8/201619203개발 환경 구성: 305. PeerFinder로 Wi-Fi Direct 연결 시 방화벽 문제
11103정성태11/8/201619147오류 유형: 370. PeerFinder.ConnectAsync의 결과 값인 Task.Result를 호출할 때 System.AggregateException 예외 발생
11102정성태11/8/201619253오류 유형: 369. PeerFinder.FindAllPeersAsync 호출 시 System.UnauthorizedAccessException 예외 발생
11101정성태11/8/201622022.NET Framework: 621. 닷넷 프로파일러의 오류 코드 - 0x80131363
11100정성태11/7/201628820개발 환경 구성: 304. Wi-Fi Direct 지원 여부 확인 방법 [1]
... 106  107  108  109  110  111  [112]  113  114  115  116  117  118  119  120  ...