Mikrotik Rotuer Port Forward Setting

미크로틱 라우터에서 k3s 클러스터를 위한 포트 포워딩 설정하기 🌐

안녕하세요! 오늘은 물뮤(MoolMeow) 프로젝트 구축을 위한 첫 단계로, 미크로틱 라우터(MikroTik Router)에서 k3s 쿠버네티스 클러스터로의 포트 포워딩을 설정하는 방법을 알아보겠습니다. 이 설정은 외부에서 우리의 클러스터에 접근하기 위한 중요한 첫 단계입니다! 🚀

필요한 포트 포워딩 설정 📋

k3s 클러스터를 운영하기 위해 다음 포트들을 외부에서 접근할 수 있도록 포워딩해야 합니다:

  • SSH 접속: 외부 포트 2222 → 내부 포트 22
  • 쿠버네티스 API: 외부 포트 6443 → 내부 포트 6443
  • HTTP 트래픽: 외부 포트 8080 → 내부 포트 80
  • HTTPS 트래픽: 외부 포트 8443 → 내부 포트 443

설정 방법 ⚙️

미크로틱 라우터에서 포트 포워딩을 설정하는 두 가지 방법을 알아보겠습니다.

1. WebFig(웹 인터페이스)를 통한 설정

  1. 미크로틱 라우터 관리 페이지에 접속합니다 (일반적으로 192.168.88.1)
  2. IP → Firewall 메뉴로 이동합니다
  3. NAT 탭을 선택합니다
  4. “New” 버튼을 클릭하여 새 규칙을 추가합니다

각 포트 포워딩 규칙마다 다음 정보를 입력합니다:

  • Chain: dstnat
  • Protocol: tcp
  • Dst. Port: 외부 포트 번호 (2222, 6443, 8080, 8443)
  • Action: dst-nat
  • To Addresses: 192.168.100.10 (k3s 마스터 노드 IP)
  • To Ports: 내부 포트 번호 (22, 6443, 80, 443)

2. 터미널(CLI)을 통한 설정

SSH로 미크로틱 라우터에 접속한 후 다음 명령어를 실행합니다:

/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=2222 to-addresses=192.168.100.10 to-ports=22
/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=6443 to-addresses=192.168.100.10 to-ports=6443
/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=8080 to-addresses=192.168.100.10 to-ports=80
/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=8443 to-addresses=192.168.100.10 to-ports=443

설정 확인 ✅

설정이 완료되면 NAT 규칙 목록에서 다음과 같이 확인할 수 있습니다: 

ChainProtocol외부 포트(Dst. Port)내부 IP 주소내부 포트(To Ports)용도
nattcp2222192.168.100.1022SSH 접속
nattcp6443192.168.100.106443쿠버네티스 API
nattcp8080192.168.100.1080HTTP 웹 서비스
nattcp8443192.168.100.10443HTTPS 웹 서비스

이렇게 설정된 포트 포워딩 규칙을 통해 외부에서 내부 k3s 클러스터의 서비스에 접근할 수 있게 됩니다.

외부에서 접속하기 🔗

포트 포워딩 설정이 완료되면 외부에서 다음과 같이 접속할 수 있습니다:

  1. SSH 접속:

    ssh -p 2222 사용자명@라우터_외부_IP주소
    
  2. 쿠버네티스 API 접속:

    curl https://라우터_외부_IP주소:6443/version
    
  3. 웹 서비스 접속:

    • HTTP: http://라우터_외부_IP주소:8080
    • HTTPS: https://라우터_외부_IP주소:8443

주의사항 ⚠️

  1. 보안: 포트 포워딩은 외부에서 내부 네트워크로의 접근 경로를 열어주므로, 꼭 필요한 포트만 개방하고 적절한 인증 메커니즘을 사용하세요.

  2. IP 주소: 예제에서는 k3s 마스터 노드 IP를 192.168.100.10으로 사용했습니다. 실제 환경에 맞게 IP 주소를 변경하세요.

  3. 방화벽 설정: 미크로틱 라우터의 방화벽 규칙이 포트 포워딩을 허용하는지 확인하세요.

다음 단계 👣

포트 포워딩 설정이 완료되었으니, 이제 k3s 클러스터에 필요한 서비스들을 설치할 준비가 되었습니다. 다음 글에서는 클러스터에 Calico, cert-manager, Vault 등의 기본 인프라를 구축하는 방법을 알아보겠습니다.

결론 🎯

미크로틱 라우터에서 포트 포워딩을 설정하는 것은 물뮤(MoolMeow) 프로젝트의 k3s 쿠버네티스 클러스터를 외부에서 접근 가능하게 만드는 중요한 첫 단계입니다. 이 설정을 통해 외부에서 SSH 접속, 쿠버네티스 API 사용, 그리고 HTTP/HTTPS 서비스 접근이 가능해집니다.

다음 글에서 만나요! 👋


참고: 이 글은 MikroTik hAP ac3 라우터와 k3s 쿠버네티스 클러스터를 사용한 물뮤(MoolMeow) 프로젝트 구축 시리즈의 일부입니다.

Setting Up Port Forwarding on MikroTik Router for k3s Cluster 🌐

Hello there! Today we’re going to explore the first step in building our MoolMeow project: setting up port forwarding on a MikroTik Router to access our k3s Kubernetes cluster. This configuration is a crucial first step to allow external access to our cluster! 🚀

Required Port Forwarding Rules 📋

To operate a k3s cluster, we need to forward the following ports to make them accessible from outside:

  • SSH Access: External port 2222 → Internal port 22
  • Kubernetes API: External port 6443 → Internal port 6443
  • HTTP Traffic: External port 8080 → Internal port 80
  • HTTPS Traffic: External port 8443 → Internal port 443

Configuration Methods ⚙️

Let’s look at two ways to set up port forwarding on a MikroTik router.

1. Using WebFig (Web Interface)

  1. Access your MikroTik router management page (typically 192.168.88.1)
  2. Navigate to IP → Firewall menu
  3. Select the NAT tab
  4. Click the “New” button to add a new rule

For each port forwarding rule, enter the following information:

  • Chain: dstnat
  • Protocol: tcp
  • Dst. Port: External port number (2222, 6443, 8080, 8443)
  • Action: dst-nat
  • To Addresses: 192.168.100.10 (k3s master node IP)
  • To Ports: Internal port number (22, 6443, 80, 443)

2. Using Terminal (CLI)

Connect to your MikroTik router via SSH and run the following commands:

/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=2222 to-addresses=192.168.100.10 to-ports=22
/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=6443 to-addresses=192.168.100.10 to-ports=6443
/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=8080 to-addresses=192.168.100.10 to-ports=80
/ip firewall nat add chain=dstnat action=dst-nat protocol=tcp dst-port=8443 to-addresses=192.168.100.10 to-ports=443

Verifying Configuration ✅

Once completed, you can verify your NAT rules in the rule list:

ChainProtocolExternal Port (Dst. Port)Internal IPInternal Port (To Ports)Purpose
nattcp2222192.168.100.1022SSH Access
nattcp6443192.168.100.106443Kubernetes API
nattcp8080192.168.100.1080HTTP Web Services
nattcp8443192.168.100.10443HTTPS Web Services

These port forwarding rules allow external access to the internal k3s cluster services.

Accessing from Outside 🔗

After setting up port forwarding, you can access your services from outside as follows:

  1. SSH Access:

    ssh -p 2222 username@router_external_IP
    
  2. Kubernetes API Access:

    curl https://router_external_IP:6443/version
    
  3. Web Services Access:

    • HTTP: http://router_external_IP:8080
    • HTTPS: https://router_external_IP:8443

Important Considerations ⚠️

  1. Security: Port forwarding opens paths from the outside to your internal network, so only open necessary ports and use appropriate authentication mechanisms.

  2. IP Addresses: In our example, we used 192.168.100.10 as the k3s master node IP. Make sure to change the IP address to match your actual environment.

  3. Firewall Rules: Verify that your MikroTik router’s firewall rules allow the port forwarding you’ve set up.

Next Steps 👣

Now that we’ve set up port forwarding, we’re ready to install the necessary services on our k3s cluster. In the next post, we’ll explore how to set up the basic infrastructure including Calico, cert-manager, Vault, and more.

Conclusion 🎯

Setting up port forwarding on a MikroTik router is an important first step in making our MoolMeow project’s k3s Kubernetes cluster accessible from the outside. This configuration enables SSH access, Kubernetes API usage, and HTTP/HTTPS service access from external networks.

See you in the next post! 👋


Note: This article is part of the MoolMeow project deployment series using a MikroTik hAP ac3 router and a k3s Kubernetes cluster.

답글 남기기