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)
13475정성태12/7/20232279닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232133개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232326닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232155C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232183Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232484닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232193닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232176닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232171오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232377닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232111개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232233닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232144오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232210오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
13461정성태11/26/20232258닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법파일 다운로드1
13460정성태11/26/20232225닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법파일 다운로드1
13459정성태11/26/20232207닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법파일 다운로드1
13458정성태11/26/20232212닷넷: 2170. .NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
13457정성태11/25/20232164VS.NET IDE: 187. Visual Studio - 16.9 버전부터 추가된 "Display inline type hints" 옵션
13456정성태11/25/20232459닷넷: 2169. C# - OpenAI를 사용해 PDF 데이터를 대상으로 OpenAI 챗봇 작성 [1]파일 다운로드1
13455정성태11/25/20232339닷넷: 2168. C# - Azure.AI.OpenAI 패키지로 OpenAI 사용파일 다운로드1
13454정성태11/23/20232683닷넷: 2167. C# - Qdrant Vector DB를 이용한 Embedding 벡터 값 보관/조회 (Azure OpenAI) [1]파일 다운로드1
13453정성태11/23/20232218오류 유형: 879. docker desktop 설치 시 "Invalid JSON string. (Exception from HRESULT: 0x83750007)"
13452정성태11/22/20232296닷넷: 2166. C# - Azure OpenAI API를 이용해 사용자가 제공하는 정보를 대상으로 검색하는 방법파일 다운로드1
13451정성태11/21/20232431닷넷: 2165. C# - Azure OpenAI API를 이용해 ChatGPT처럼 동작하는 콘솔 응용 프로그램 제작파일 다운로드1
13450정성태11/21/20232254닷넷: 2164. C# - Octokit을 이용한 GitHub Issue 검색파일 다운로드1
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...