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)
13503정성태12/27/20232191Linux: 67. WSL 환경 + mlocate(locate) 도구의 /mnt 디렉터리 검색 문제
13502정성태12/26/20232298닷넷: 2187. C# - 다른 프로세스의 환경변수 읽는 예제파일 다운로드1
13501정성태12/25/20232098개발 환경 구성: 700. WSL + uwsgi - IPv6로 바인딩하는 방법
13500정성태12/24/20232179디버깅 기술: 194. Windbg - x64 가상 주소를 물리 주소로 변환
13498정성태12/23/20232856닷넷: 2186. 한국투자증권 KIS Developers OpenAPI의 C# 래퍼 버전 - eFriendOpenAPI NuGet 패키지
13497정성태12/22/20232296오류 유형: 885. Visual Studiio - error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
13496정성태12/21/20232311Linux: 66. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (gdb)
13495정성태12/20/20232322Linux: 65. clang++로 공유 라이브러리의 -static 옵션 빌드가 가능할까요?
13494정성태12/20/20232502Linux: 64. Linux 응용 프로그램의 (C++) so 의존성 줄이기(ReleaseMinDependency) - 두 번째 이야기
13493정성태12/19/20232562닷넷: 2185. C# - object를 QueryString으로 직렬화하는 방법
13492정성태12/19/20232265개발 환경 구성: 699. WSL에 nopCommerce 예제 구성
13491정성태12/19/20232233Linux: 63. 리눅스 - 다중 그룹 또는 사용자를 리소스에 권한 부여
13490정성태12/19/20232349개발 환경 구성: 698. Golang - GLIBC 의존을 없애는 정적 빌드 방법
13489정성태12/19/20232136개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
13488정성태12/18/20232069오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/20232381개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20232195개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20232088오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232162개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232301닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20232877닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232271개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20232611개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232308개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232484닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232211닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...