1. 사전 준비
1-1 API 인증 토큰 발급
사용자 로컬 머신의 터미널에 접속합니다. 아래 명령에서 ACCESS_KEY와 ACCESS_SECRET_KEY를 각각 '액세스 키'와 '보안 액세스 키' 값으로 수정합니다. 그 다음 아래 API 인증 토큰을 발급받는 명령을 실행합니다.
API 사용 준비 문서를 참고하여 API 인증 토큰을 발급하시기 바랍니다.
export API_TOKEN=$(curl -s -X POST -i https://iam.kakaocloud.com/identity/v3/auth/tokens -H "Content-Type: application/json" -d \
'{
"auth": {
"identity": {
"methods": [
"application_credential"
],
"application_credential": {
"id": "{ACCESS_KEY}",
"secret": "{ACCESS_SECRET_KEY}"
}
}
}
}' | grep x-subject-token | awk -v RS='\r\n' '{print $2}')
1-2 발급받은 API 인증 토큰을 확인합니다.
echo $API_TOKEN
2. API 명령어 사용 예시(Container Pack)
1. 클러스터 조회
curl -s -X GET 'https://kubernetes-engine.kr-central-2.kakaocloud.com/api/v1/clusters' \
-H 'Accept: application/json' \
-H 'X-Auth-Token: [토큰 값]' | \
jq -r '.clusters[] |
"Name: \(.name)\nID: \(.id)\nStatus: \(.status.phase)\nVersion: \(.version.minor_version).\(.version.patch_version)\nVPC: \(.vpc_info.id)\nSubnets: \(.vpc_info.subnets[] | "\(.id) (\(.availability_zone))")\n---"'
2. 클러스터 생성
curl -L 'https://kubernetes-engine.kr-central-2.kakaocloud.com/api/v1/clusters' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Token: {{X-Auth-Token}}' \
-d '{
"cluster": {
"name": "string", # 클러스터 이름
"description": "string", # 클러스터 설명
"version": "string", # Kubernetes 버전 (예: "1.31")
"vpc_info": {
"id": "string", # 클러스터가 속할 VPC ID
"subnets": [
"string" # VPC 서브넷 ID 목록
]
},
"is_allocate_fip": true, # 퍼블릭 IP를 자동 할당할지 여부
"network": {
"cni": "cilium", # 네트워크 플러그인 (예: "cilium", "calico")
"service_cidr": "string", # 서비스 CIDR (예: "10.96.0.0/12")
"pod_cidr": "string" # Pod CIDR (예: "192.168.0.0/16")
}
}
}'
명령어 예시)
curl -L 'https://kubernetes-engine.kr-central-2.kakaocloud.com/api/v1/clusters' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Token: [너의 토큰]' \
-d '{
"cluster": {
"name": "ke-felix-test",
"description": "test",
"version": "1.31",
"vpc_info": {
"id": "4cb561ee-33fe-4952-abd0-9b8cdad0502f",
"subnets": [
"520a3bd6-b9cf-4ded-aa26-112d5a29463f",
"723fe1ec-745f-470d-a43a-736e90f0757d"
]
},
"is_allocate_fip": true,
"network": {
"cni": "calico"
}
}
}'
3. 노드풀 이미지 목록 조회
curl -s -X GET 'https://kubernetes-engine.kr-central-2.kakaocloud.com/api/v1/images' \
-H 'Accept: application/json' \
-H 'X-Auth-Token: {{X-Auth-Token}}' | \
jq -r '.images[] | "\(.name) \(.id)"' | sort
4. 노드풀 생성
curl -L 'https://kubernetes-engine.kr-central-2.kakaocloud.com/api/v1/clusters/:cluster_name/node-pools' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Token: {{X-Auth-Token}}' \
-d '{
"node_pool": {
"name": "string",
"description": "string",
"flavor_id": "string",
"volume_size": 0,
"node_count": 0,
"ssh_key_name": "string",
"labels": [
{
"key": "string",
"value": "string"
}
],
"taints": [
{
"key": "string",
"value": "string",
"effect": "NoExecute"
}
],
"user_data": "string",
"vpc_info": {
"id": "string",
"subnets": [
"string"
]
},
"image_id": "string",
"is_hyper_threading": true,
"security_groups": [
"string"
]
}
}'
5. 보안 그룹 조회
curl -s -X GET 'https://network.kr-central-2.kakaocloud.com/api/v1/security-groups' \
-H 'Accept: application/json' \
-H 'X-Auth-Token: [너의 토큰]' | jq -r '.security_groups[] | "\(.name) \(.id)"' | sort