본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

/status 엔드포인트 다운 상태로 만들기

원문 보기 위키 갱신

/status 엔드포인트 다운 상태로 만들기 (How to fake down /status endpoint)

단독(standalone) Kong 노드에서 /status 엔드포인트를 일시적으로 끄거나 다운된 것처럼 보이게 만드는 방법을 알려 드릴게요. /status를 upstream으로 루프백 연결한 뒤 Admin API에서 해당 타겟을 unhealthy로 표시하면 /status가 503을 반환하고, healthy로 다시 표시하면 원래대로 돌아와요. LB 헬스 체크 사이 공백 없이 노드를 점검하거나 업그레이드할 때 유용하게 쓸 수 있는 팁이에요. 다만 하이브리드 모드 컨트롤 플레인의 Admin API에서는 404가 반환되어 이 방법이 동작하지 않으니 참고하세요

출처: 문서

본문

TL;DR

단독(standalone) Kong 노드에서 /status 엔드포인트를 일시적으로 비활성화하거나 다운된 것처럼 보이게 하려면 어떻게 해야 하나요? 단독/전통(traditional) 방식의 Kong 노드에서는 /status 엔드포인트를 upstream으로 루프백시킨 다음, Admin API(PUT /upstreams/{id}/targets/{id}/unhealthy)로 해당 target을 unhealthy로 표시하세요. 그러면 /status가 503을 반환해요. 다시 healthy로 표시하면 원래대로 복구돼요. 이 방법은 하이브리드 Control Plane의 Admin API에는 동작하지 않아요. 하이브리드 모드에서는 해당 엔드포인트가 404를 반환하거든요.

개요

현재 LB가 n초 간격으로 /status 엔드포인트에 대해 헬스 체크를 수행하고 있어요. Kong 노드를 업그레이드하려면 Admin API를 내리게 되는데, 그 구간 동안 노드가 다운되어 있을 때 LB가 요청을 라우팅하지 않길 원해요. /status 엔드포인트를 끌 수 있는 방법이 있을까요?

단계

/status 엔드포인트는 kong.conf의 status_listen 설정으로 제어할 수 있어요.

이 엔드포인트를 끄려면 Kong을 재시작해야 해요. 하지만 재시작이 불가능한 경우라면 Kong에서 /status 엔드포인트를 루프백으로 연결하고, Kong upstream 헬스 체크의 Mark Healthy/Unhealthy를 사용해서 엔드포인트를 끄고 켤 수 있어요.

이 기법은 단독/전통(traditional) 방식의 Kong 노드에만 적용돼요. 하이브리드 모드의 Admin API에서는 PUT /upstreams/{id}/targets/{id}/unhealthy가 404를 반환하기 때문에, 이 접근 방식은 하이브리드 Control Plane의 Admin API에는 동작하지 않아요.

단독 노드에서는 헬스 체커가 "lazy"하다는 점에 유의하세요. 새로 생성한 upstream/target에 대한 첫 번째 헬스 체크 관련 요청은, 실제 요청이 최소 한 번 프록시되기 전까지는 400을 반환할 수 있어요. target을 healthy/unhealthy로 표시하기 전에 upstream을 통해 워밍업 요청을 한 번 보내세요. 그다음부터는 아래에서 설명하는 대로 엔드포인트가 동작해요.

설정 방법은 다음과 같아요:

  1. Admin API를 루프백하기 위한 upstream을 생성해요

http :8001/upstreams name=status_check -f
  1. Admin API 호스트를 upstream status_check의 target으로 설정해요

http :8001/upstreams/status_check/targets target=<KongAdminAPI hostname>:8001 -f
  1. 경로가 /status인 service와 해당 upstream을 위한 route를 생성해요

http :8001/services name=status_health host=status_check path=/status -f 
http :8001/services/status_health/routes name=status_route paths=/status -f
  1. 지금 이 시점에서는 Kong이 프록시 포트에서 /status를 서빙하고 있어요

http :8000/status
HTTP/1.1 200 OK

{
    "database": {
        "reachable": true
    },
    "memory": {
        "lua_shared_dicts": {
            "kong": {
                "allocated_slabs": "0.04 MiB",
                "capacity": "5.00 MiB"
            },
            "kong_healthchecks": {
                "allocated_slabs": "0.04 MiB",
                "capacity": "5.00 MiB"
            },
            ...
        },
        "workers_lua_vms": [
            {
                "http_allocated_gc": "182.51 MiB",
                "pid": 2914
            },
            ...
        ]
    },
    "server": {
        "connections_accepted": 137,
        "connections_active": 7,
        "connections_handled": 137,
        "connections_reading": 0,
        "connections_waiting": 0,
        "connections_writing": 7,
        "total_requests": 137
    }
}
  1. target을 unhealthy로 표시해서 /status 엔드포인트가 다운된 것처럼 만들어요

# the template  
# :8001/upstreams/<upstream_id>/targets/<targets-id>/[healthy/unhealthy]

http :8001/upstreams/f3fa8cc2-003a-49fe-8734-c3f433281a46/targets/7355da4e-6684-4d3d-9890-863e2e444510/unhealthy
HTTP/1.1 204 No Content 
Access-Control-Allow-Origin: * 
Connection: keep-alive
  1. status 엔드포인트를 다시 curl로 호출해 보세요

http :8000/status                                                                                                                                                                                                                                        
HTTP/1.1 503 Service Temporarily Unavailable
Connection: keep-alive
Content-Length: 58

upstream으로서 현재 unhealthy 상태이기 때문에 엔드포인트가 503을 반환하는 걸 확인할 수 있어요. healthy로 설정하려면 5번 단계에서 사용한 엔드포인트를 사용하세요.


http :8001/upstreams/f3fa8cc2-003a-49fe-8734-c3f433281a46/targets/7355da4e-6684-4d3d-9890-863e2e444510/healthy
HTTP/1.1 204 No Content 
Access-Control-Allow-Origin: * 
Connection: keep-alive

http :8000/status 
HTTP/1.1 200 OK

관련 리소스

더 알아보기 (Learn more)

이 문서에는 원문에서 추출한 별도의 관련 문서 링크가 없어요.