1.4.1.4 Image Credential Provider for OKE 사용하기
Image Credential Provider for OKE는 OCIR Private Registry에서 암호 없이 이미지를 가져오기 위한 Kubelet CredentialProvider(v1) API의 구현체입니다. OKE는 일반적으로 매니페스트 파일상의 imagePullSecrets에서 참조되는 저장된 Secret을 사용하여 비공개 OCIR 이미지를 가져옵니다. Image Credential Provider for OKE를 사용하면 Kubelet은 Worker Node의 Instance Principal 인증을 통해 OCIR 이미지를 가져올 수 있게 되어, 기존에 암호로 사용하던 Auth Token에 대한 관리 부담이 없어집니다. 또한 namespace 별로 Secret을 생성하고, 배포 매니페스트마다 imagePullSecrets를 설정해야 하는 부담이 없습니다.
다만, OCIR에서 공식 서포트 하는 것은 아니며, Oracle Devrel에서 오픈소스로 제공하고 있습니다. OCIR API 중 AccessToken API을 기반으로 하고 있어, 사용에는 문제가 없어 보입니다.
OCIR 인증 방식
Authentication Mechanisms for OCI Container Registry (OCIR) 블로그에 설명처럼, 기존 OCI User Auth Token 방식에 추가하여, Bearer Token을 사용하는 방식이 추가되었습니다.
이중 Option 2: Short-Lived Bearer Token Using API Key–Based Authentication을 테스트 해봅니다.
-
OCI 인증이 이미 설정되어 있어야 합니다. 여기서는 Instance Principal이 설정된 경우를 가정합니다.
export OCI_CLI_AUTH=instance_principal -
Step 1: Generate Bearer Token - 사용할 Region OCIR 주소로 토큰 생성을 요청합니다.
export TOKEN=`oci raw-request --http-method GET --target-uri "https://yny.ocir.io/20180419/docker/token" | jq -r ".data.token"`-
예시
$ export TOKEN=`oci raw-request --http-method GET --target-uri "https://yny.ocir.io/20180419/docker/token" | jq -r ".data.token"` $ echo $TOKEN eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiO......
-
-
Step 2: Authenticate Docker Using Bearer Token - 생성된 토큰을 이용해 로그인합니다.
docker login -u BEARER_TOKEN -p $TOKEN yny.ocir.io-
예시
$ docker login -u BEARER_TOKEN -p $TOKEN yny.ocir.io Login Succeeded!
-
-
Step 3: Use Docker Normally - 이미지 Push, Pull을 확인합니다.
docker push yny.ocir.io/{namespace}/sandbox/nginx:latest
Image Credential Provider for OKE 설치하기
-
OKE Worker Nodes를 위한 Dynamic Group을 만듭니다.
-
이름:
oke-worker-nodes-dynamic-group -
규칙
All {instance.compartment.id = '<REPLACE_WITH_YOUR_COMPARTMENT_OCID>'}
-
-
OCIR 이미지를 가져오기 위한 IAM Policy를 만듭니다.
-
이름:
oke-ocir-image-pull-policy -
규칙
Allow dynamic-group <REPLACE_WITH_YOUR_IAM_DOMAIN>/oke-worker-nodes-dynamic-group to read repos in compartment <REPLACE_WITH_YOUR_COMPARTMENT_NAME>
-
-
OKE Node Pool의 cloud-init을 설정합니다. 이미 cloud-init을 사용하고 있는 경우
# download binaries on the worker node아래 내용을 기존 cloud-init 설정에 추가합니다.-
원 파일: cloud-init.sh
-
내용
#!/bin/bash curl --fail -H "Authorization: Bearer Oracle" -L0 http://169.254.169.254/opc/v2/instance/metadata/oke_init_script | base64 --decode >/var/run/oke-init.sh # download binaries on the worker node wget https://github.com/oracle-devrel/oke-credential-provider-for-ocir/releases/latest/download/oke-credential-provider-for-ocir-linux-amd64 -O /usr/local/bin/credential-provider-oke wget https://github.com/oracle-devrel/oke-credential-provider-for-ocir/releases/latest/download/credential-provider-config.yaml -P /etc/kubernetes/ # add permission to execute sudo chmod 755 /usr/local/bin/credential-provider-oke # configure kubelet with image credential provider bash /var/run/oke-init.sh --kubelet-extra-args "--image-credential-provider-bin-dir=/usr/local/bin/ --image-credential-provider-config=/etc/kubernetes/credential-provider-config.yaml"
-
테스트
-
imagepullsecret 설정 없이 OCIR Private Repo에 있는 이미지를 가져오려고 하면 다음과 같이 오류가 발생합니다.
$ kubectl get pod NAME READY STATUS RESTARTS AGE pod/nginx-ocir-78bd5ff4f8-5f824 0/1 ImagePullBackOff 0 5m33s $ kubectl describe pod nginx-ocir-78bd5ff4f8-5f824 ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- ... Warning Failed 2m44s (x5 over 5m45s) kubelet Failed to pull image ....denied: Anonymous users are only allowed read access on public repos Warning Failed 2m44s (x5 over 5m45s) kubelet Error: ErrImagePull Warning Failed 43s (x20 over 5m44s) kubelet Error: ImagePullBackOff -
Image Credential Provider for OKE 설치후, Node Pool에 기존 노드가 있다면, 재생성합니다.
-
노드가 Ready가 된 이후 다시 Pod의 상태를 확인합니다. OCIR Private Repo에 있는 이미지를 정상적으로 가져오는 것을 알 수 있습니다.
$ kubectl get pod NAME READY STATUS RESTARTS AGE nginx-ocir-78bd5ff4f8-rfgxm 1/1 Running 0 5m31s $ kubectl describe pod nginx-ocir-78bd5ff4f8-rfgxm ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 5m22s (x13 over 7m9s) default-scheduler no nodes available to schedule pods Warning FailedScheduling 5m11s default-scheduler 0/2 nodes are available: 2 node(s) had untolerated taint(s). no new claims to deallocate, preemption: 0/2 nodes are available: 2 Preemption is not helpful for scheduling. Normal Scheduled 4m16s default-scheduler Successfully assigned default/nginx-ocir-78bd5ff4f8-rfgxm to 10.0.10.102 Normal Pulling 3m57s kubelet Pulling image "icn.ocir.io/xxxxx/sandbox/nginx" Normal Pulled 2m34s kubelet Successfully pulled image "icn.ocir.io/xxxxx/sandbox/nginx" in 1m23.148s (1m23.148s including waiting). Image size: 196533470 bytes. Normal Created 2m32s kubelet Container created Normal Started 2m32s kubelet Container started
이 글은 개인으로서, 개인의 시간을 할애하여 작성된 글입니다. 글의 내용에 오류가 있을 수 있으며, 글 속의 의견은 개인적인 의견입니다.