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

비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13223정성태1/20/20234288오류 유형: 838. RDP 연결 오류 - The two computers couldn't connect in the amount of time allotted
13222정성태1/20/20233944개발 환경 구성: 657. WSL - DockerDesktop.vhdx 파일 위치를 옮기는 방법
13221정성태1/19/20234169Linux: 57. C# - 리눅스 프로세스 메모리 정보파일 다운로드1
13220정성태1/19/20234320오류 유형: 837. NETSDK1045 The current .NET SDK does not support targeting .NET ...
13219정성태1/18/20233887Windows: 220. 네트워크의 인터넷 접속 가능 여부에 대한 판단 기준
13218정성태1/17/20233824VS.NET IDE: 178. Visual Studio 17.5 (Preview 2) - 포트 터널링을 이용한 웹 응용 프로그램의 외부 접근 허용
13217정성태1/13/20234422디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
13216정성태1/12/20234673디버깅 기술: 184. windbg - 32비트 프로세스의 메모리 덤프인 경우 !peb 명령어로 나타나지 않는 환경 변수
13215정성태1/11/20236187Linux: 56. 리눅스 - /proc/pid/stat 정보를 이용해 프로세스의 CPU 사용량 구하는 방법 [1]
13214정성태1/10/20235757.NET Framework: 2087. .NET 6부터 SourceGenerator와 통합된 System.Text.Json [1]파일 다운로드1
13213정성태1/9/20235289오류 유형: 836. docker 이미지 빌드 시 "RUN apt install ..." 명령어가 실패하는 이유
13212정성태1/8/20235053기타: 85. 단정도/배정도 부동 소수점의 정밀도(Precision)에 따른 형변환 손실
13211정성태1/6/20235114웹: 42. (https가 아닌) http 다운로드를 막는 웹 브라우저
13210정성태1/5/20234139Windows: 219. 윈도우 x64의 경우 0x00000000`7ffe0000 아래의 주소는 왜 사용하지 않을까요?
13209정성태1/4/20234042Windows: 218. 왜 윈도우에서 가상 메모리 공간은 64KB 정렬이 된 걸까요?
13208정성태1/3/20233990.NET Framework: 2086. C# - Windows 운영체제의 2MB Large 페이지 크기 할당 방법파일 다운로드1
13207정성태12/26/20224291.NET Framework: 2085. C# - gpedit.msc의 "User Rights Assignment" 특권을 코드로 설정/해제하는 방법파일 다운로드1
13206정성태12/24/20224505.NET Framework: 2084. C# - GetTokenInformation으로 사용자 SID(Security identifiers) 구하는 방법 [3]파일 다운로드1
13205정성태12/24/20224889.NET Framework: 2083. C# - C++과의 연동을 위한 구조체의 fixed 배열 필드 사용 (2)파일 다운로드1
13204정성태12/22/20224173.NET Framework: 2082. C# - (LSA_UNICODE_STRING 예제로) CustomMarshaler 사용법파일 다운로드1
13203정성태12/22/20224329.NET Framework: 2081. C# Interop 예제 - (LSA_UNICODE_STRING 예제로) 구조체를 C++에 전달하는 방법파일 다운로드1
13202정성태12/21/20224727기타: 84. 직렬화로 설명하는 Little/Big Endian파일 다운로드1
13201정성태12/20/20225350오류 유형: 835. PyCharm 사용 시 C 드라이브 용량 부족
13200정성태12/19/20224210오류 유형: 834. 이벤트 로그 - SSL Certificate Settings created by an admin process for endpoint
13199정성태12/19/20224495개발 환경 구성: 656. Internal Network 유형의 스위치로 공유한 Hyper-V의 VM과 호스트가 통신이 안 되는 경우
13198정성태12/18/20224376.NET Framework: 2080. C# - Microsoft.XmlSerializer.Generator 처리 없이 XmlSerializer 생성자를 예외 없이 사용하고 싶다면?파일 다운로드1
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...