12.4. API를 사용하여 호스트 추가
지원 설치 관리자 REST API를 사용하여 클러스터에 호스트를 추가할 수 있습니다.
사전 요구 사항
-
OpenShift Cluster Manager CLI(
ocm
)를 설치합니다. - 클러스터 생성 권한이 있는 사용자로 OpenShift Cluster Manager 에 로그인합니다.
-
jq
를 설치합니다. - 확장하려는 클러스터에 필요한 모든 DNS 레코드가 있는지 확인합니다.
절차
- 지원 설치 관리자 REST API에 대해 인증하고 세션에 대한 API 토큰을 생성합니다. 생성된 토큰은 15분 동안만 유효합니다.
다음 명령을 실행하여
$API_URL
변수를 설정합니다.$ export API_URL=<api_url> 1
다음 명령을 실행하여 클러스터를 가져옵니다.
$CLUSTER_ID
변수를 설정합니다. 클러스터에 로그인하고 다음 명령을 실행합니다.$ export CLUSTER_ID=$(oc get clusterversion -o jsonpath='{.items[].spec.clusterID}')
클러스터를 가져오는 데 사용되는
$CLUSTER_REQUEST
변수를 설정합니다.$ export CLUSTER_REQUEST=$(jq --null-input --arg openshift_cluster_id "$CLUSTER_ID" '{ "api_vip_dnsname": "<api_vip>", 1 "openshift_cluster_id": $CLUSTER_ID, "name": "<openshift_cluster_name>" 2 }')
클러스터를 가져와서
$CLUSTER_ID
변수를 설정합니다. 다음 명령을 실행합니다.$ CLUSTER_ID=$(curl "$API_URL/api/assisted-install/v2/clusters/import" -H "Authorization: Bearer ${API_TOKEN}" -H 'accept: application/json' -H 'Content-Type: application/json' \ -d "$CLUSTER_REQUEST" | tee /dev/stderr | jq -r '.id')
클러스터에 대한
InfraEnv
리소스를 생성하고 다음 명령을 실행하여$INFRA_ENV_ID
변수를 설정합니다.- console.redhat.com 의 Red Hat OpenShift Cluster Manager에서 풀 시크릿 파일을 다운로드합니다.
$INFRA_ENV_REQUEST
변수를 설정합니다.export INFRA_ENV_REQUEST=$(jq --null-input \ --slurpfile pull_secret <path_to_pull_secret_file> \1 --arg ssh_pub_key "$(cat <path_to_ssh_pub_key>)" \2 --arg cluster_id "$CLUSTER_ID" '{ "name": "<infraenv_name>", 3 "pull_secret": $pull_secret[0] | tojson, "cluster_id": $cluster_id, "ssh_authorized_key": $ssh_pub_key, "image_type": "<iso_image_type>" 4 }')
- 1
- <
path_to_pull_secret_file
>을 console.redhat.com 의 Red Hat OpenShift Cluster Manager에서 다운로드한 풀 시크릿이 포함된 로컬 파일의 경로로 바꿉니다. - 2
- &
lt;path_to_ssh_pub_key
>를 호스트에 액세스하는 데 필요한 공용 SSH 키의 경로로 바꿉니다. 이 값을 설정하지 않으면 검색 모드에서 호스트에 액세스할 수 없습니다. - 3
- &
lt;infraenv_name&
gt;을InfraEnv
리소스의 일반 텍스트 이름으로 바꿉니다. - 4
- &
lt;iso_image_type
>을full-iso
또는minimal-iso
이미지 유형으로 바꿉니다.
$INFRA_ENV_REQUEST
를 /v2/infra-envs API에 게시하고$INFRA_ENV_ID
변수를 설정합니다.$ INFRA_ENV_ID=$(curl "$API_URL/api/assisted-install/v2/infra-envs" -H "Authorization: Bearer ${API_TOKEN}" -H 'accept: application/json' -H 'Content-Type: application/json' -d "$INFRA_ENV_REQUEST" | tee /dev/stderr | jq -r '.id')
다음 명령을 실행하여 클러스터 호스트에 대한 검색 ISO의 URL을 가져옵니다.
$ curl -s "$API_URL/api/assisted-install/v2/infra-envs/$INFRA_ENV_ID" -H "Authorization: Bearer ${API_TOKEN}" | jq -r '.download_url'
출력 예
https://api.openshift.com/api/assisted-images/images/41b91e72-c33e-42ee-b80f-b5c5bbf6431a?arch=x86_64&image_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTYwMjYzNzEsInN1YiI6IjQxYjkxZTcyLWMzM2UtNDJlZS1iODBmLWI1YzViYmY2NDMxYSJ9.1EX_VGaMNejMhrAvVRBS7PDPIQtbOOc8LtG8OukE1a4&type=minimal-iso&version=4.12
ISO를 다운로드합니다.
$ curl -L -s '<iso_url>' --output rhcos-live-minimal.iso 1
- 1
- &
lt;iso_url
>을 이전 단계의 ISO URL로 바꿉니다.
-
다운로드한
rhcos-live-minimal.iso
에서 새 작업자 호스트를 부팅합니다. 설치되지 않은 클러스터에서 호스트 목록을 가져옵니다. 새 호스트가 표시될 때까지 다음 명령을 계속 실행하십시오.
$ curl -s "$API_URL/api/assisted-install/v2/clusters/$CLUSTER_ID" -H "Authorization: Bearer ${API_TOKEN}" | jq -r '.hosts[] | select(.status != "installed").id'
출력 예
2294ba03-c264-4f11-ac08-2f1bb2f8c296
새 호스트의
$HOST_ID
변수를 설정합니다. 예를 들면 다음과 같습니다.$ HOST_ID=<host_id> 1
- 1
- &
lt;host_id&
gt;를 이전 단계의 호스트 ID로 바꿉니다.
다음 명령을 실행하여 호스트를 설치할 준비가 되었는지 확인합니다.
참고전체
jq
표현식을 포함하여 전체 명령을 복사해야 합니다.$ curl -s $API_URL/api/assisted-install/v2/clusters/$CLUSTER_ID -H "Authorization: Bearer ${API_TOKEN}" | jq ' def host_name($host): if (.suggested_hostname // "") == "" then if (.inventory // "") == "" then "Unknown hostname, please wait" else .inventory | fromjson | .hostname end else .suggested_hostname end; def is_notable($validation): ["failure", "pending", "error"] | any(. == $validation.status); def notable_validations($validations_info): [ $validations_info // "{}" | fromjson | to_entries[].value[] | select(is_notable(.)) ]; { "Hosts validations": { "Hosts": [ .hosts[] | select(.status != "installed") | { "id": .id, "name": host_name(.), "status": .status, "notable_validations": notable_validations(.validations_info) } ] }, "Cluster validations info": { "notable_validations": notable_validations(.validations_info) } } ' -r
출력 예
{ "Hosts validations": { "Hosts": [ { "id": "97ec378c-3568-460c-bc22-df54534ff08f", "name": "localhost.localdomain", "status": "insufficient", "notable_validations": [ { "id": "ntp-synced", "status": "failure", "message": "Host couldn't synchronize with any NTP server" }, { "id": "api-domain-name-resolved-correctly", "status": "error", "message": "Parse error for domain name resolutions result" }, { "id": "api-int-domain-name-resolved-correctly", "status": "error", "message": "Parse error for domain name resolutions result" }, { "id": "apps-domain-name-resolved-correctly", "status": "error", "message": "Parse error for domain name resolutions result" } ] } ] }, "Cluster validations info": { "notable_validations": [] } }
이전 명령에서 호스트가 준비되었다고 표시되면 다음 명령을 실행하여 /v2/infra-envs/{infra_env_id}/hosts/{host_id}/actions/install API를 사용하여 설치를 시작합니다.
$ curl -X POST -s "$API_URL/api/assisted-install/v2/infra-envs/$INFRA_ENV_ID/hosts/$HOST_ID/actions/install" -H "Authorization: Bearer ${API_TOKEN}"
설치가 진행되면 설치에 호스트에 대한 보류 중인 인증서 서명 요청(CSR)이 생성됩니다.
중요설치를 완료하려면 CSR을 승인해야 합니다.
다음 API 호출을 실행하여 클러스터 설치를 모니터링합니다.
$ curl -s "$API_URL/api/assisted-install/v2/clusters/$CLUSTER_ID" -H "Authorization: Bearer ${API_TOKEN}" | jq '{ "Cluster day-2 hosts": [ .hosts[] | select(.status != "installed") | {id, requested_hostname, status, status_info, progress, status_updated_at, updated_at, infra_env_id, cluster_id, created_at} ] }'
출력 예
{ "Cluster day-2 hosts": [ { "id": "a1c52dde-3432-4f59-b2ae-0a530c851480", "requested_hostname": "control-plane-1", "status": "added-to-existing-cluster", "status_info": "Host has rebooted and no further updates will be posted. Please check console for progress and to possibly approve pending CSRs", "progress": { "current_stage": "Done", "installation_percentage": 100, "stage_started_at": "2022-07-08T10:56:20.476Z", "stage_updated_at": "2022-07-08T10:56:20.476Z" }, "status_updated_at": "2022-07-08T10:56:20.476Z", "updated_at": "2022-07-08T10:57:15.306369Z", "infra_env_id": "b74ec0c3-d5b5-4717-a866-5b6854791bd3", "cluster_id": "8f721322-419d-4eed-aa5b-61b50ea586ae", "created_at": "2022-07-06T22:54:57.161614Z" } ] }
선택 사항: 다음 명령을 실행하여 클러스터의 모든 이벤트를 확인합니다.
$ curl -s "$API_URL/api/assisted-install/v2/events?cluster_id=$CLUSTER_ID" -H "Authorization: Bearer ${API_TOKEN}" | jq -c '.[] | {severity, message, event_time, host_id}'
출력 예
{"severity":"info","message":"Host compute-0: updated status from insufficient to known (Host is ready to be installed)","event_time":"2022-07-08T11:21:46.346Z","host_id":"9d7b3b44-1125-4ad0-9b14-76550087b445"} {"severity":"info","message":"Host compute-0: updated status from known to installing (Installation is in progress)","event_time":"2022-07-08T11:28:28.647Z","host_id":"9d7b3b44-1125-4ad0-9b14-76550087b445"} {"severity":"info","message":"Host compute-0: updated status from installing to installing-in-progress (Starting installation)","event_time":"2022-07-08T11:28:52.068Z","host_id":"9d7b3b44-1125-4ad0-9b14-76550087b445"} {"severity":"info","message":"Uploaded logs for host compute-0 cluster 8f721322-419d-4eed-aa5b-61b50ea586ae","event_time":"2022-07-08T11:29:47.802Z","host_id":"9d7b3b44-1125-4ad0-9b14-76550087b445"} {"severity":"info","message":"Host compute-0: updated status from installing-in-progress to added-to-existing-cluster (Host has rebooted and no further updates will be posted. Please check console for progress and to possibly approve pending CSRs)","event_time":"2022-07-08T11:29:48.259Z","host_id":"9d7b3b44-1125-4ad0-9b14-76550087b445"} {"severity":"info","message":"Host: compute-0, reached installation stage Rebooting","event_time":"2022-07-08T11:29:48.261Z","host_id":"9d7b3b44-1125-4ad0-9b14-76550087b445"}
- 클러스터에 로그인하고 보류 중인 CSR을 승인하여 설치를 완료합니다.
검증
새 호스트가
Ready
: 상태의 클러스터에 성공적으로 추가되었는지 확인합니다.$ oc get nodes
출력 예
NAME STATUS ROLES AGE VERSION control-plane-1.example.com Ready master,worker 56m v1.25.0 compute-1.example.com Ready worker 11m v1.25.0