ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Kubernetes pod outgoing connections
    2021. 6. 7. comments

    최근 API 서버의 DB Connection pool의 연결 개수 및 동작에 대해 검증을 했었다. 컨테이너로 접속하여 netstat 명령이 실행 가능하다면 너무나도 쉽게 외부로 연결하는 connection을 손쉽게 확인할 수 있지만, container image를 만들 때 보안도를 높이기 위해 시스템 명령어들은 설치하지 않거나 계정 권한을 제외시키는 방향을 취하기 때문에 다른 확인 방법이 필요하다. 

    nsenter

    1. kubernetes worker node에 ssh로 접속한다.
    2. docker psinspect 명령어를 통해서 연결 확인을 원하는 pod의 process id를 확인한다.
    3. 찾아낸 process id 정보를 기반으로 nsenter 명령을 내려서 pod의 outgoing connection을 확인한다.
    $ sudo docker ps
    CONTAINER ID   IMAGE            COMMAND                  CREATED       STATUS      PORTS                    NAMES
    1a4fb0a03166   postgres:10.10   "docker-entrypoint.s…"   5 weeks ago   Up 5 days   0.0.0.0:5432->5432/tcp  
    
    $ sudo docker inspect -f '{{.State.Pid}}'  1a4fb0a03166
    1748
    
    $ sudo nsenter -t 1748 -n netstat -antp 

    참고로 nsenter라는 명령어는 namespace enter의 약어이다. -t 옵션은 target으로써 pid 를 명시하는 것이고 -n은 network namespace에 진입한다는 의미이다. 그래서 -n과 netstat을 함께 적어야 우리가 원하는 결과를 얻어낼 수 있다.

    See also

    반응형

    댓글

Designed by Tistory.