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

Docker Desktop for Windows - kubectl proxy 없이 k8s 대시보드 접근 방법

k8s 대시보드를 설치하고 인증도 편리하게 했으니,

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

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

이제 남은 작업이라면 접속을 편하게 하는 방법입니다. 즉, 매번 "kubectl proxy" 명령어를 실행하는 게 귀찮다는 것인데요, 찾아 보니까 kube-apiserver를 이용하는 방법이 나옵니다.

Kubernetes Dashboard 설치
    - b) Node Port를 활용하는 방법
    - c) API Server를 활용하는 방법 
; https://waspro.tistory.com/516

위의 글을 docker desktop for windows 버전으로 정리해 볼까요? ^^

우선 "b) Node Port를 활용하는 방법"은 다음의 명령을 입력했을 때,

c:\temp> kubectl -n kubernetes-dashboard edit service kubernetes-dashboard

편집기가 실행되면서 아래의 내용을 보여주는데,

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard","namespace":"kubernetes-dashboard"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"}}}
  creationTimestamp: "2021-03-16T23:43:20Z"
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
  resourceVersion: "2074977"
  selfLink: /api/v1/namespaces/kubernetes-dashboard/services/kubernetes-dashboard
  uid: 1d0bae1f-e9e9-4b79-9490-79fe381753e3
spec:
  clusterIP: 10.96.4.48
  ports:
  - port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

위의 내용에서 "type: ClusterIP"를 "type: NodePort"로 변경해 저장하면 된다고 합니다. 변경은 바로 반영이 되고,

c:\temp> kubectl -n kubernetes-dashboard get service kubernetes-dashboard
NAME                   TYPE       CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
kubernetes-dashboard   NodePort   10.96.4.48   <none>        443:32459/TCP   23d

이제부터 https://127.0.0.1:32459/ URL로 (kubectl proxy 없이) 접속할 수 있습니다. 단지 이 방법의 단점은 "Kubernetes Dashboard 설치" 글에서도 언급하고 있지만 Port가 변경될 수 있다는 것입니다.




그래서 가장 현실적인 방법은 "c) API Server를 활용하는 방법"인데요, 단지 사전 작업이 좀 필요하다는 귀찮음이 있습니다.

일단, kubeconfig 파일("%USERPROFILE%\.kube\config")에 있는 client-certificate-data와 client-key-data를 이용해 각각 crt, key 파일을 생성한 후,

// base64 도구
// https://github.com/stjeong/Utilities/releases/tag/v1.1.3

c:\temp> type "%USERPROFILE%\.kube\config" | for /f "tokens=2 delims=:" %f in ('findstr client-certificate-data') do base64 -d %f > user.crt
c:\temp> type "%USERPROFILE%\.kube\config" | for /f "tokens=2 delims=:" %f in ('findstr client-key-data') do base64 -d %f > user.key

이를 합쳐 p12 파일을 만듭니다. (p12 파일은 pfx의 다른 확장자라고 보면 됩니다. 참고: https://www.sysnet.pe.kr/2/0/863)

c:\temp> openssl pkcs12 -export -clcerts -inkey user.key -in user.crt -out user.p12 -name "docker-for-desktop"

그다음 해당 사용자 인증서를 서명한 루트 인증 기관의 인증서를 찾아야 하는데요, 일단 여기서는 kind 환경이 아니라는 가정으로 단순하게 "%LOCALAPPDATA%\Docker\pki" 디렉터리에 있는 ca.crt 인증서로 하겠습니다.

이제 이 2개의 인증서를 시스템에 등록하면 되는데, ca.crt는 Root에, user.p12를 My에 각각 등록해 줍니다.

c:\temp> certutil.exe -addstore "Root" ca.crt

c:\temp> certutil.exe -p tester -user -importPFX desktop.p12
Certificate "docker-for-desktop" added to store.

CertUtil: -importPFX command completed successfully.

/* 인증서 관리자를 이용해도 됩니다. */

휴~~~ 여기까지 모든 준비는 끝났습니다. 이후 서비스 URL로 접속하면 끝!

https://kubernetes.docker.internal:6443/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login
(또는)
https://127.0.0.1:6443/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

즉, 이제부터는 "kubectl proxy"도 필요 없고 인증 토큰도 필요 없이 언제든 접속해 k8s 대시보드를 들어갈 수 있습니다.

(참고로, 위에서 설정한 복잡한 방법을 "ukubectl.exe --register-cert" 명령어를 사용하면 간단하게 kubeconfig 파일의 인증서를 윈도우에 모두 등록해 줍니다.)




참고로, "https://kubernetes.docker.internal:6443/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login" 경로를 접근했을 때 인증서 선택 창이 안 뜨고 다음과 같은 오류 메시지만 보이는 경우가 있습니다.

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "services \"https:kubernetes-dashboard:\" is forbidden: User \"system:anonymous\" cannot get resource \"services/proxy\" in API group \"\" in the namespace \"kubernetes-dashboard\"",
  "reason": "Forbidden",
  "details": {
    "name": "https:kubernetes-dashboard:",
    "kind": "services"
  },
  "code": 403
}

아마도 cache의 영향으로 보이는데요, 테스트를 위해 "New InPrivte Window"로 띄운 Edge 브라우저에서 방문해 보면 정상적으로 인증서 선택 창(Select a certificate)이 뜨는 것을 확인할 수 있습니다. Cache의 레벨이 어떻게 되는지 모르겠으나, "Ctrl + Shift + R"을 이용해도 안 되는데 일단 제 경우에는 "Clear browsing data"의 대상으로 "Brwosing history", "Download history", "Cookies and other site data", "Cached images and files", "Site permissions"를 선택하고 삭제한 다음 모든 브라우저를 종료 후 다시 시작했을 때 인증서 선택 창이 뜨기 시작했습니다. (다음에 재현될 때는 대상 범위를 좁혀 봐야겠습니다. ^^)




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 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)
13301정성태3/29/20234379Windows: 239. C/C++ - Windows 10 Version 1607부터 지원하는 /DEPENDENTLOADFLAG 옵션파일 다운로드1
13300정성태3/28/20234020Windows: 238. Win32 - Modal UI 창에 올바른 Owner(HWND)를 설정해야 하는 이유
13299정성태3/27/20233788Windows: 237. Win32 - 모든 메시지 루프를 탈출하는 WM_QUIT 메시지
13298정성태3/27/20233746Windows: 236. Win32 - MessageBeep 소리가 안 들린다면?
13297정성태3/26/20234408Windows: 235. Win32 - Code Modal과 UI Modal
13296정성태3/25/20233761Windows: 234. IsDialogMessage와 협업하는 WM_GETDLGCODE Win32 메시지 [1]파일 다운로드1
13295정성태3/24/20234035Windows: 233. Win32 - modeless 대화창을 modal처럼 동작하게 만드는 방법파일 다운로드1
13294정성태3/22/20234197.NET Framework: 2105. LargeAddressAware 옵션이 적용된 닷넷 32비트 프로세스의 가용 메모리 - 두 번째
13293정성태3/22/20234248오류 유형: 853. dumpbin - warning LNK4048: Invalid format file; ignored
13292정성태3/21/20234382Windows: 232. C/C++ - 일반 창에도 사용 가능한 IsDialogMessage파일 다운로드1
13291정성태3/20/20234792.NET Framework: 2104. C# Windows Forms - WndProc 재정의와 IMessageFilter 사용 시의 차이점
13290정성태3/19/20234292.NET Framework: 2103. C# - 윈도우에서 기본 제공하는 FindText 대화창 사용법파일 다운로드1
13289정성태3/18/20233472Windows: 231. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 자식 윈도우를 생성하는 방법파일 다운로드1
13288정성태3/17/20233592Windows: 230. Win32 - 대화창의 DLU 단위를 pixel로 변경하는 방법파일 다운로드1
13287정성태3/16/20233752Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/20234194Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/20233787Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법파일 다운로드1
13284정성태3/13/20234010Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/20233543오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/20233883Linux: 58. WSL - nohup 옵션이 필요한 경우
13281정성태3/12/20233799Windows: 225. 윈도우 바탕화면의 아이콘들이 넓게 퍼지는 경우 [2]
13280정성태3/9/20234554개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
13279정성태3/9/20234072오류 유형: 851. 파이썬 ModuleNotFoundError: No module named '_cffi_backend'
13278정성태3/8/20234088개발 환경 구성: 669. WSL 2의 (init이 아닌) systemd 지원 [1]
13277정성태3/6/20234721개발 환경 구성: 668. 코드 사인용 인증서 신청 및 적용 방법(예: Digicert)
13276정성태3/5/20234403.NET Framework: 2102. C# 11 - ref struct/ref field를 위해 새롭게 도입된 scoped 예약어
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...