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)
13528정성태1/14/20242033Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20241960오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242051닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242021오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242066오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20241889오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/20242030닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/20242110닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20241858오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....'
13519정성태1/10/20241939닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/20242174닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20242017스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20242104닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
13515정성태1/6/20242376닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242065개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
13513정성태1/5/20242006닷넷: 2194. C# - WebActivatorEx / System.Web의 PreApplicationStartMethod 특성
13512정성태1/4/20241979개발 환경 구성: 701. IIS - w3wp.exe 프로세스의 ASP.NET 런타임을 항상 Warmup 모드로 유지하는 preload Enabled 설정
13511정성태1/4/20241997닷넷: 2193. C# - ASP.NET Web Application + OpenAPI(Swashbuckle) 스펙 제공
13510정성태1/3/20241937닷넷: 2192. C# - 특정 실행 파일이 있는지 확인하는 방법 (Linux)
13509정성태1/3/20241966오류 유형: 887. .NET Core 2 이하의 프로젝트에서 System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0.
13508정성태1/3/20242016오류 유형: 886. ORA-28000: the account is locked
13507정성태1/2/20242701닷넷: 2191. C# - IPGlobalProperties를 이용해 netstat처럼 사용 중인 Socket 목록 구하는 방법파일 다운로드1
13506정성태12/29/20232191닷넷: 2190. C# - 닷넷 코어/5+에서 달라지는 System.Text.Encoding 지원
13505정성태12/27/20232707닷넷: 2189. C# - WebSocket 클라이언트를 닷넷으로 구현하는 예제 (System.Net.WebSockets)파일 다운로드1
13504정성태12/27/20232322닷넷: 2188. C# - ASP.NET Core SignalR로 구현하는 채팅 서비스 예제파일 다운로드1
13503정성태12/27/20232191Linux: 67. WSL 환경 + mlocate(locate) 도구의 /mnt 디렉터리 검색 문제
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...