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

비밀번호

댓글 작성자
 




... 121  122  123  124  125  126  127  128  129  130  [131]  132  133  134  135  ...
NoWriterDateCnt.TitleFile(s)
1780정성태10/15/201424178오류 유형: 249. The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
1779정성태10/15/201419706오류 유형: 248. Active Directory에서 OU가 지워지지 않는 경우
1778정성태10/10/201418156오류 유형: 247. The Netlogon service could not create server share C:\Windows\SYSVOL\sysvol\[도메인명]\SCRIPTS.
1777정성태10/10/201421260오류 유형: 246. The processing of Group Policy failed. Windows attempted to read the file \\[도메인]\sysvol\[도메인]\Policies\{...GUID...}\gpt.ini
1776정성태10/10/201418304오류 유형: 245. 이벤트 로그 - Name resolution for the name _ldap._tcp.dc._msdcs.[도메인명]. timed out after none of the configured DNS servers responded.
1775정성태10/9/201419429오류 유형: 244. Visual Studio 디버깅 (2) - Unable to break execution. This process is not currently executing the type of code that you selected to debug.
1774정성태10/9/201426624개발 환경 구성: 246. IIS 작업자 프로세스의 20분 자동 재생(Recycle)을 끄는 방법
1773정성태10/8/201429781.NET Framework: 471. 웹 브라우저로 다운로드가 되는 파일을 왜 C# 코드로 하면 안되는 걸까요? [1]
1772정성태10/3/201418569.NET Framework: 470. C# 3.0의 기본 인자(default parameter)가 .NET 1.1/2.0에서도 실행될까? [3]
1771정성태10/2/201428082개발 환경 구성: 245. 실행된 프로세스(EXE)의 명령행 인자를 확인하고 싶다면 - Sysmon [4]
1770정성태10/2/201421689개발 환경 구성: 244. 매크로 정의를 이용해 파일 하나로 C++과 C#에서 공유하는 방법 [1]파일 다운로드1
1769정성태10/1/201424108개발 환경 구성: 243. Scala 개발 환경 구성(JVM, 닷넷) [1]
1768정성태10/1/201419531개발 환경 구성: 242. 배치 파일에서 Thread.Sleep 효과를 주는 방법 [5]
1767정성태10/1/201424632VS.NET IDE: 94. Visual Studio 2012/2013에서의 매크로 구현 - Visual Commander [2]
1766정성태10/1/201422488개발 환경 구성: 241. 책 "프로그래밍 클로저: Lisp"을 읽고 나서. [1]
1765정성태9/30/201426054.NET Framework: 469. Unity3d에서 transform을 변수에 할당해 사용하는 특별한 이유가 있을까요?
1764정성태9/30/201422288오류 유형: 243. 파일 삭제가 안 되는 경우 - The action can't be comleted because the file is open in System
1763정성태9/30/201423856.NET Framework: 468. PDB 파일을 연동해 소스 코드 라인 정보를 알아내는 방법파일 다운로드1
1762정성태9/30/201424550.NET Framework: 467. 닷넷에서 EIP/RIP 레지스터 값을 구하는 방법 [1]파일 다운로드1
1761정성태9/29/201421577.NET Framework: 466. 윈도우 운영체제의 보안 그룹 이름 및 설명 문자열을 바꾸는 방법파일 다운로드1
1760정성태9/28/201419842.NET Framework: 465. ICorProfilerInfo::GetILToNativeMapping 메서드가 0x80131358을 반환하는 경우
1759정성태9/27/201430977개발 환경 구성: 240. Visual C++ / x64 환경에서 inline-assembly를 매크로 어셈블리로 대체하는 방법파일 다운로드1
1758정성태9/23/201437885개발 환경 구성: 239. 원격 데스크톱 접속(RDP)을 기존의 콘솔 모드처럼 사용하는 방법 [1]
1757정성태9/23/201418411오류 유형: 242. Lync로 모임 참여 시 소리만 들리지 않는 경우 - 두 번째 이야기
1756정성태9/23/201427413기타: 48. NVidia 제품의 과다한 디스크 사용 [2]
1755정성태9/22/201434202오류 유형: 241. Unity Web Player를 설치해도 여전히 설치하라는 화면이 나오는 경우 [4]
... 121  122  123  124  125  126  127  128  129  130  [131]  132  133  134  135  ...