Kwoo'S Blog - IT는 어렵다.
k8s 환경에 Harbor Helm으로 배포하기 본문
저는 harbor/harbor Helm Chart를 사용하겠습니다.
helm repo add harbor https://helm.goharbor.io
helm search repo harbor
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/harbor 16.0.0 2.6.1 Harbor is an open source trusted cloud-native r...
harbor/harbor 1.10.2 2.6.2 An open source trusted cloud native registry th...
공식 Git은 여길 참고하세요
https://github.com/goharbor/harbor-helm
GitHub - goharbor/harbor-helm: The helm chart to deploy Harbor
The helm chart to deploy Harbor. Contribute to goharbor/harbor-helm development by creating an account on GitHub.
github.com
저는 TLS 인증서 없는 버전으로 배포해볼 겁니다. 추후 인증서 버전으로 추가 예정
(참고로 인증서 없으면 설치 후 이미지 사용을 위한 조금 번거로운 과정이 필요함)
Harbor 차트를 설치하기 전에 values 값 확인 및 설정
helm show values harbor/harbor > values.yaml
해당 values.yaml 파일을 들어가서 일단 확인해야 할 부분은 이부분입니다.
expose:
# Set how to expose the service. Set the type as "ingress", "clusterIP", "nodePort" or "loadBalancer"
# and fill the information in the corresponding section
type: ingress
tls:
# Enable TLS or not.
# Delete the "ssl-redirect" annotations in "expose.ingress.annotations" when TLS is disabled and "expose.type" is "ingress"
# Note: if the "expose.type" is "ingress" and TLS is disabled,
# the port must be included in the command when pulling/pushing images.
# Refer to https://github.com/goharbor/harbor/issues/5291 for details.
enabled: true
expose.type 부분에 내가 어떤 유형을 통해 외부로 expose 할 것인지 선택해야한다.
조금 아래에 보면 ingress, ClusterIP, NodePort, LoadBalancer 형식이 존재함 여기서 내가 선택한 Type의 설정값이 들어가게 된다.
ingress:
hosts:
core: core.192.168.155.69.nip.io
notary: notary.harbor.domain
...
clusterIP:
# The name of ClusterIP service
name: harbor
...
nodePort:
# The name of NodePort service
name: harbor
...
loadBalancer:
# The name of LoadBalancer service
name: harbor
저는 일단 ingress Type을 사용할 것이고 tls 인증을 하지 않고 배포할것이기 때문에(http:// 형식) tls는 false로 해주겠습니다.
expose:
# Set how to expose the service. Set the type as "ingress", "clusterIP", "nodePort" or "loadBalancer"
# and fill the information in the corresponding section
type: ingress
tls:
# Enable TLS or not.
# Delete the "ssl-redirect" annotations in "expose.ingress.annotations" when TLS is disabled and "expose.type" is "ingress"
# Note: if the "expose.type" is "ingress" and TLS is disabled,
# the port must be included in the command when pulling/pushing images.
# Refer to https://github.com/goharbor/harbor/issues/5291 for details.
enabled: false
ingress 를 사용하기 위해서 expose.ingress 부분의 설정값을 살펴봅니다.
ingress:
hosts:
core: core.harbor.domain
notary: notary.harbor.domain
# set to the type of ingress controller if it has specific requirements.
# leave as `default` for most ingress controllers.
# set to `gce` if using the GCE ingress controller
# set to `ncp` if using the NCP (NSX-T Container Plugin) ingress controller
# set to `alb` if using the ALB ingress controller
controller: default
## Allow .Capabilities.KubeVersion.Version to be overridden while creating ingress
kubeVersionOverride: ""
className: ""
annotations:
# note different ingress controllers may require a different ssl-redirect annotation
# for Envoy, use ingress.kubernetes.io/force-ssl-redirect: "true" and remove the nginx lines below
ingress.kubernetes.io/ssl-redirect: "true"
ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
기본적으로 이런 상태일텐데. 저는 다음과 같이 수정했습니다.
ingress:
hosts:
core: core.192.168.155.69.nip.io
notary: notary.harbor.domain
# set to the type of ingress controller if it has specific requirements.
# leave as `default` for most ingress controllers.
# set to `gce` if using the GCE ingress controller
# set to `ncp` if using the NCP (NSX-T Container Plugin) ingress controller
# set to `alb` if using the ALB ingress controller
controller: default
## Allow .Capabilities.KubeVersion.Version to be overridden while creating ingress
kubeVersionOverride: ""
className: "nginx"
annotations:
# note different ingress controllers may require a different ssl-redirect annotation
# for Envoy, use ingress.kubernetes.io/force-ssl-redirect: "true" and remove the nginx lines below
ingress.kubernetes.io/ssl-redirect: "false"
ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
ingress의 hosts에 ip형식으로 사용할려고 빈칸 및 *을 사용해서 설치해봤는데 형식에러가 발생하네요
그래서 nip.io 를 사용해서 host를 설정해주었습니다.
또한 notary는 그대로 둔 이유는 그냥 단순한데 테스트용이라 안쓸거 같아서입니다.
필요하시다면 비슷하게 설정해주시면 될듯합니다.
구분을 위해 core.마스터 노드IP.nip.io 을 설정해주었고, 마스터 노드 IP를 준 이유는 Ingress를 사용하기 위해 Nginx Controller 를 배포해두었는데 온프레미스 환경이며, 따로 추가 IP를 할당할 여유가 없었습니다. 때문에 메탈LB등 설치해도 크게 변하는 환경이 아니기 때문에 Nginx Controller 서비스를 노드포트로 개방하고 노드아이피:NodePort로 접속하기 위해 아래와 같이 지정해주었습니다.
core: core.192.168.155.69.nip.io
( ingress의 다른 글을 보면 hosts를 설정하고 Nginx Controller 서비스에 Loadbaclcer의 External IP를 통해 접속하기 때문에 자체 호스트에 DNS를 등록해서 접속한다는 글을 많이 보았는데 저는 External IP가 없으니 테스트를 따로 못해보아 생략하겠습니다.)
Ingress Controller의 ClassName은 nginx이니 해당 값을 입력해주고
저는 http://형식으로 들어갈것이기 때문에 ssl-redirect 를 전부 false로 해주었습니다.
annotations:
# note different ingress controllers may require a different ssl-redirect annotation
# for Envoy, use ingress.kubernetes.io/force-ssl-redirect: "true" and remove the nginx lines below
ingress.kubernetes.io/ssl-redirect: "false"
ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
다음 중요한 설정 값은 externalURL 인데 일단 결과부터 보자면 다음과 같이 설정합니다.
http인 이유는 harbor의 tls인증서 관련 로그인 문제 때문에 혹시나해서 입니다.
externalURL: http://core.192.168.155.69.nip.io:30765
internalTLS 또한 원래 true였는지 기억은 안나지만 저는 false로 설정했습니다.
internalTLS:
# If internal TLS enabled
enabled: false
persistence 설정은 저는 NFS 를 통한 StorageClass를 사용하기 때문에
persistence:
enabled: true
# Setting it to "keep" to avoid removing PVCs during a helm delete
...
registry:
# Use the existing PVC which must be created manually before bound,
# and specify the "subPath" if the PVC is shared with other components
existingClaim: ""
# Specify the "storageClass" used to provision the volume. Or the default
# StorageClass will be used (the default).
# Set it to "-" to disable dynamic provisioning
storageClass: "nfs-client"
이런식으로 모든 storageClass에 사용하고 있는 StorageClass 이름을 설정했습니다.
모든 설정값을 바꾸셨으면 배포합니다.
helm install harbor -n harbor harbor/harbor -f values.yaml
모든 파드가 전부 running 상태가 되기 까지 기다립니다.
NAME READY STATUS RESTARTS AGE
harbor-chartmuseum-6f9499f887-kjdgs 1/1 Running 0 125m
harbor-core-6d4c79b6b9-jhgmf 1/1 Running 0 125m
harbor-database-0 1/1 Running 0 6h2m
harbor-jobservice-867fc47984-g54rw 1/1 Running 2 (125m ago) 125m
harbor-notary-server-8696c8cbb8-x4wlx 1/1 Running 1 (119m ago) 125m
harbor-notary-signer-85984885d7-d2dq7 1/1 Running 0 125m
harbor-portal-8d5b66f98-9s2gg 1/1 Running 0 6h2m
harbor-redis-0 1/1 Running 0 6h2m
harbor-registry-549798f59d-fql4b 2/2 Running 0 125m
harbor-trivy-0 1/1 Running 0 6h2m
전부 배포가 되었으면 ingress도 조회해봅니다.
kubectl get ing -n harbor
NAME CLASS HOSTS ADDRESS PORTS AGE
harbor-ingress nginx core.192.168.155.69.nip.io 192.168.155.68 80 6h3m
harbor-ingress-notary nginx notary.harbor.domain 192.168.155.68 80 6h3m
원래 Hosts에 바로 접근하는 것은 외부 DNS에 등록되어 있거나 자체 DNS에 등록해야 사용할 수 있지만 저는 테스트로 nip.io를 사용하였기 때문에 그대로 저 hosts명대로 인터넷에서 들어갈수 있을겁니다.
+ 추가
IP 형식으로 접속하고 뒤에 URL이 겹치는게 없는 상황이라면 edit로 들어가서 host를 제거하면 사용할 수 있습니다.
kubectl edit ing -n harbor harbor-ingress
hosts 항목을 지우고 저장하고 나온 후 ingress를 조회해보면 host가 *로 변하는걸 볼수 있습니다.
http://core.192.168.155.69.nip.io:30765 접속
(30765는 제 Nginx Controller 서비스의 노드포트)
ingress-nginx ingress-nginx-controller NodePort 10.111.152.146 <none> 80:30765/TCP,443:30977/TCP 18d
기본 User 이름은 admin 이고 패스워드는 Harbor12345 입니다.
패스워드는 초기 values에서도 수정가능하며 값 변경후 아래와 같이 적용해도 됩니다.
helm upgrade harbor -n harbor harbor/harbor -f values.yaml
참고로 admin / Harbor12345 로 로그인시도를 했는데 접속이 되지 않는다면 대개 tls 문제일겁니다. 만약 tls 인증서를 쓴다면 모든 설정을 전부 tls설정을 해주어야 하고, 아니라면 전부 빼주는게 확실한거 같습니다.
많이들 고생하시는거 같습니다.
https://github.com/goharbor/harbor-helm/issues/589
Default password and username · Issue #589 · goharbor/harbor-helm
Hello everyone. Unable to log in with standard credentials. Which pod should I describe? Where can I find error information?
github.com
Harbor 사용
docker login core.192.168.155.69.nip.io:30765
Error response from daemon: Get "https://core.192.168.155.69.nip.io:30765/v2/": http: server gave HTTP response to HTTPS client
다음과 같은 에러가 발생합니다.
인증서를 사용하지 않았을 때 로컬에서 생기는 문제라고 하네요
/etc/docker/daemon.json 수정 아래 내용 추가합니다.
{
"insecure-registries": ["http://core.192.168.155.69.nip.io:30765"]
}
그리고 다시 로그인 시도하면 성공합니다.
만약 아래 에러가 나오면 위에서 ExternalURL에 포트를 안넣어줘서 그렇습니다.
Get https://core.192.168.155.69.nip.io:30765/v2/: Get https://core.192.168.155.69.nip.io:80/service/token?account=harbor_registry_user&client_id=docker&offline_token=true&service=harbor-registry: connect: connection refused
externalURL: http://core.192.168.155.69.nip.io:30765
https://jwher.github.io/posts/install-harbor/ 이분의 블로그를 참고하니
harbor-core에서 발생하는 문제라네요
/v2/에서 externalURL로 /service/ api를 호출하는데, port가 지정되어 있지 않으면 https 프로토콜의 기본값 443번으로 연결된다고 합니다. 저는 http라 80으로 나왔네요.
포스팅 맨 아래 글을 보면 여러 트러블슈팅 경우를 적어두셨습니다.
로그인 후 push를 해보겠습니다.
docker tag jenkins:0.1.0-SNAPSHOT core.192.168.155.69.nip.io:30765/library/jenkins:0.1
docker push core.192.168.155.69.nip.io:30765/library/jenkins:0.1
'Devops > 쿠버네티스' 카테고리의 다른 글
CKA - Networking -2 (0) | 2022.11.09 |
---|---|
CKA - Networking -1 (0) | 2022.11.08 |
CKA - Storage (0) | 2022.11.08 |
k8s에서 NFS Provisioning 사용 (0) | 2022.10.26 |