서비스 IP
서비스 IP (Service IPs)
Calico Open Source OpenStack VM에 서비스 IP를 할당하는 방법을 설명해 드릴게요. Neutron 플로팅 IP를 붙이거나, VM 포트에 추가 고정 IP를 붙이는 두 가지 방식이 있어요. 두 방식의 의미 차이와, 추가 고정 IP 방식을 실제로 설정하고 옮기는 과정을 명령어와 함께 차근차근 살펴볼게요.
출처: 문서
본문
Calico 네트워킹을 사용하는 VM에 서비스 IP를 할당하는 방법은 두 가지예요:
-
플로팅 IP 사용
-
해당 Neutron 포트에 추가 고정 IP(fixed IP) 사용
둘 다 표준적인 Neutron 사용 방식이에요. 다시 말해 Neutron API에서 오래전부터 지원해 온 작업들이에요. 기대하는 의미 체계(semantics)가 동작하도록 하는 저수준 작업 일부를 Calico 드라이버가 구현해야 한다는 점만 빼면, Calico 고유의 방식은 아니에요.
두 방식의 핵심적인 의미 차이는 이래요:
-
플로팅 IP를 쓰면 대상 VM 자신은 서비스 IP를 알지 못해요. 대신 플로팅 IP로 보낸 데이터는 대상 VM에 도달하기 전에 대상 VM의 고정 IP로 DNAT돼요. 그래서 대상 VM은 자신의 고정 IP로 향한 데이터만 보게 돼요.
-
서비스 IP를 추가 고정 IP로 쓰면 대상 VM은 서비스 IP를 알고 있어야 하고, 실제로 알고 있어야 해요. 서비스 IP로 향한 데이터가 DNAT 없이 그대로 VM에 도달하기 때문이에요.
플로팅 IP 사용법은 이미 잘 알려져 있으니 여기서 자세히 다루지는 않을게요. Calico가 플로팅 IP를 지원하는 방식에 대한 추가 정보는 플로팅 IP 문서를 참고하세요.
반면 추가 고정 IP의 사용과 관리는 그렇게 잘 알려져 있지 않아서, 이어지는 실습 과정에서 Calico 네트워킹 VM에 서비스 IP를 할당하는 이 방식을 직접 보여 드릴게요.
먼저 서비스 IP의 대상이 될 테스트 VM을 만들어 볼게요.
테스트 VM 만들기
-
사용 가능한 CirrOS 이미지의 이름을 확인해요.
nova image-list이미지 목록과 이름이 반환돼요.
WARNING: Command image-list is deprecated and will be removed after Nova 15.0.0 is released. Use python-glanceclient or openstackclient instead. +--------------------------------------+---------------------+--------+--------+ | ID | Name | Status | Server | +--------------------------------------+---------------------+--------+--------+ | b69ab3bd-2bbc-4086-b4ae-f01d9f6b5078 | cirros-0.3.2-x86_64 | ACTIVE | | | 866879b9-532b-44c6-a547-ac59de68df2d | ipv6_enabled_image | ACTIVE | | +--------------------------------------+---------------------+--------+--------+ -
VM을 부팅해요.
nova boot --flavor m1.tiny --image cirros-0.3.2-x86_64 --nic net-name=demo-net testvm1응답은 다음과 비슷하게 보여요.
+--------------------------------------+------------------------------------------------------------+ | Property | Value | +--------------------------------------+------------------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-SRV-ATTR:host | - | | OS-EXT-SRV-ATTR:hypervisor_hostname | - | | OS-EXT-SRV-ATTR:instance_name | instance-0000000d | | OS-EXT-STS:power_state | 0 | | OS-EXT-STS:task_state | scheduling | | OS-EXT-STS:vm_state | building | | OS-SRV-USG:launched_at | - | | OS-SRV-USG:terminated_at | - | | accessIPv4 | | | accessIPv6 | | | adminPass | HKLzcUT5L52B | | config_drive | | | created | 2017-01-13T13:50:32Z | | flavor | m1.tiny (1) | | hostId | | | id | b6d8a3c4-9674-4972-9151-11107b60d622 | | image | cirros-0.3.2-x86_64 (b69ab3bd-2bbc-4086-b4ae-f01d9f6b5078) | | key_name | - | | metadata | {} | | name | testvm1 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | security_groups | default | | status | BUILD | | tenant_id | 26778b0f745143c5a9b0c7e1a621bb80 | | updated | 2017-01-13T13:50:32Z | | user_id | 7efbea74c20a4eeabc00b7740aa4d353 | +--------------------------------------+------------------------------------------------------------+ -
VM이 부팅됐는지 확인해요:
nova list다음과 같은 상태의 VM이 보여야 해요.
+--------------------------------------+---------+--------+------------+-------------+----------------------------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+---------+--------+------------+-------------+----------------------------------------------+ | b6d8a3c4-9674-4972-9151-11107b60d622 | testvm1 | ACTIVE | - | Running | demo-net=10.28.0.13, fd5f:5d21:845:1c2e:2::d | +--------------------------------------+---------+--------+------------+-------------+----------------------------------------------+ -
다음 명령으로 VM의 상태를 확인해요.
nova show testvm1다음과 비슷한 결과가 반환돼요.
+--------------------------------------+------------------------------------------------------------+ | Property | Value | +--------------------------------------+------------------------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | neil-fv-0-ubuntu-kilo-compute-node01 | | OS-EXT-SRV-ATTR:host | neil-fv-0-ubuntu-kilo-compute-node01 | | OS-EXT-SRV-ATTR:hypervisor_hostname | neil-fv-0-ubuntu-kilo-compute-node01 | | OS-EXT-SRV-ATTR:instance_name | instance-0000000d | | OS-EXT-STS:power_state | 1 | | OS-EXT-STS:task_state | - | | OS-EXT-STS:vm_state | active | | OS-SRV-USG:launched_at | 2017-01-13T13:50:39.000000 | | OS-SRV-USG:terminated_at | - | | accessIPv4 | | | accessIPv6 | | | config_drive | | | created | 2017-01-13T13:50:32Z | | demo-net network | 10.28.0.13, fd5f:5d21:845:1c2e:2::d | | flavor | m1.tiny (1) | | hostId | bf3ce3c7146ba6cafd43be03886de8755e2b5c8e9f71aa9bfafde9a0 | | id | b6d8a3c4-9674-4972-9151-11107b60d622 | | image | cirros-0.3.2-x86_64 (b69ab3bd-2bbc-4086-b4ae-f01d9f6b5078) | | key_name | - | | metadata | {} | | name | testvm1 | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | security_groups | default | | status | ACTIVE | | tenant_id | 26778b0f745143c5a9b0c7e1a621bb80 | | updated | 2017-01-13T13:50:39Z | | user_id | 7efbea74c20a4eeabc00b7740aa4d353 | +--------------------------------------+------------------------------------------------------------+이 예제에서 VM의 고정 IP는 10.28.0.13이에요.
-
이제 대응하는 Neutron 포트를 살펴볼게요.
neutron port-list다음과 비슷하게 보여요.
+--------------------------------------+------+-------------------+------------------------------------------------------------------------------------------------+ | id | name | mac_address | fixed_ips | +--------------------------------------+------+-------------------+------------------------------------------------------------------------------------------------+ | 656b3617-570d-473e-a5dd-90b61cb0c49f | | fa:16:3e:4d:d5:25 | | | 9a7e0868-da7a-419e-a7ad-9d37e11091b8 | | fa:16:3e:28:a9:a4 | {"subnet_id": "0a1221f2-e6ed-413d-a040-62a266bd0d8f", "ip_address": "10.28.0.13"} | | | | | {"subnet_id": "345fec2e-6493-44de-a489-97b755c16dd4", "ip_address": "fd5f:5d21:845:1c2e:2::d"} | | a4b26bcc-ba94-4033-a9fc-edaf151c0c20 | | fa:16:3e:74:46:bd | | | a772a5e1-2f13-4fc3-96d5-fa1c29717637 | | fa:16:3e:c9:c6:8f | | +--------------------------------------+------+-------------------+------------------------------------------------------------------------------------------------+
Neutron 포트에 추가 고정 IP로 서비스 IP 붙이기
이제 처음에는 testvm1을 가리키도록 서비스 IP(여기서는 10.28.0.23으로 하죠)를 준비해 볼게요.
-
한 가지 방법은 서비스 IP를 Neutron 포트의 두 번째 '고정 IP'로 추가하는 거예요.
neutron port-update --fixed-ip subnet_id=0a1221f2-e6ed-413d-a040-62a266bd0d8f,ip_address=10.28.0.13 \ --fixed-ip subnet_id=0a1221f2-e6ed-413d-a040-62a266bd0d8f,ip_address=10.28.0.23 9a7e0868-da7a-419e-a7ad-9d37e11091b8 -
확인 메시지가 반환돼요.
Updated port: 9a7e0868-da7a-419e-a7ad-9d37e11091b8 -
다음 명령으로 포트에 대한 더 자세한 정보를 확인해요.
neutron port-show 9a7e0868-da7a-419e-a7ad-9d37e11091b8다음과 같은 표가 반환돼요.
+-----------------------+-----------------------------------------------------------------------------------+ | Field | Value | +-----------------------+-----------------------------------------------------------------------------------+ | admin_state_up | True | | allowed_address_pairs | | | binding:host_id | neil-fv-0-ubuntu-kilo-compute-node01 | | binding:profile | {} | | binding:vif_details | {"port_filter": true, "mac_address": "00:61:fe:ed:ca:fe"} | | binding:vif_type | tap | | binding:vnic_type | normal | | device_id | b6d8a3c4-9674-4972-9151-11107b60d622 | | device_owner | compute:None | | extra_dhcp_opts | | | fixed_ips | {"subnet_id": "0a1221f2-e6ed-413d-a040-62a266bd0d8f", "ip_address": "10.28.0.13"} | | | {"subnet_id": "0a1221f2-e6ed-413d-a040-62a266bd0d8f", "ip_address": "10.28.0.23"} | | id | 9a7e0868-da7a-419e-a7ad-9d37e11091b8 | | mac_address | fa:16:3e:28:a9:a4 | | name | | | network_id | 60651076-af2a-4c6d-8d64-500b53a4e547 | | security_groups | 75fccd0a-ef3d-44cd-91ec-ef22941f50f5 | | status | ACTIVE | | tenant_id | 26778b0f745143c5a9b0c7e1a621bb80 | +-----------------------+-----------------------------------------------------------------------------------+ -
이제 로컬 IP 라우트를 살펴봐요.
ip r10.28.0.23으로 가는 라우트가 보여요.default via 10.240.0.1 dev eth0 proto static metric 100 10.28.0.13 via 192.168.8.3 dev l2tpeth8-1 proto bird 10.28.0.23 via 192.168.8.3 dev l2tpeth8-1 proto bird [...]이 명령을 실행하는 머신에서는 다음을 참고하세요:
-
BIRD가 실행 중이고, Calico가 각 컴퓨트 노드에서 실행하는 BIRD들과 피어링되어 있어요. 덕분에 VM 라우트(
10.28.0.23포함)가 여기에 나타나는 거예요. -
192.168.8.3은
testvm1을 호스팅하는 컴퓨트 노드의 IP예요.
-
-
10.28.0.23이 해당 컴퓨트 노드에서 로컬 디바이스 라우트로 나타났는지 다시 확인할 수도 있어요.ip r다음과 비슷한 결과가 반환돼요.
default via 10.240.0.1 dev eth0 10.28.0.13 dev tap9a7e0868-da scope link 10.28.0.23 dev tap9a7e0868-da scope link 10.240.0.1 dev eth0 scope link 192.168.8.0/24 dev l2tpeth8-3 proto kernel scope link src 192.168.8.3 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1이 방식에서는
10.28.0.23으로 향한 데이터가 NAT 없이 VM으로 라우팅되기 때문에, VM 자신에게 추가10.28.0.23주소가 있다는 걸 알려 줘야 해요. -
VM에 SSH로 접속해요.
core@access-node$ ssh cirros@10.28.0.13 cirros@10.28.0.13's password: -
VM 안에서 다음 명령을 실행해 인터페이스 목록을 확인해요.
ip a다음과 비슷한 결과가 반환돼요.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether fa:16:3e:28:a9:a4 brd ff:ff:ff:ff:ff:ff inet 10.28.0.13/16 brd 10.28.255.255 scope global eth0 inet6 fe80::f816:3eff:fe28:a9a4/64 scope link valid_lft forever preferred_lft forever -
다음으로 아래 명령을 실행해요.
sudo ip a a 10.28.0.23/16 dev eth0 -
인터페이스 목록을 다시 확인해요.
ip a인터페이스가 이제 다음과 비슷하게 보여요.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether fa:16:3e:28:a9:a4 brd ff:ff:ff:ff:ff:ff inet 10.28.0.13/16 brd 10.28.255.255 scope global eth0 inet 10.28.0.23/16 scope global secondary eth0 inet6 fe80::f816:3eff:fe28:a9a4/64 scope link valid_lft forever preferred_lft forever -
SSH 세션을 종료해요.
Connection to 10.28.0.13 closed. -
이제 아래처럼 서비스 IP로 VM에 접근할 수 있어요.
core@access-node$ ssh cirros@10.28.0.23 The authenticity of host '10.28.0.23 (10.28.0.23)' can't be established. RSA key fingerprint is 65:a5:b0:0c:e2:c4:ac:94:2a:0c:64:b8:bc:5a:aa:66. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.28.0.23' (RSA) to the list of known hosts. cirros@10.28.0.23's password: $접속 머신(
192.168.8.1)에서 인스턴스로 SSH를 허용하는 보안 설정이 이미 되어 있다는 점을 참고하세요. -
보안 그룹 목록을 확인해서 이를 검증할 수 있어요.
neutron security-group-list다음과 비슷한 결과가 반환돼요.
+--------------------------------------+---------+----------------------------------------------------------------------+ | id | name | security_group_rules | +--------------------------------------+---------+----------------------------------------------------------------------+ | 75fccd0a-ef3d-44cd-91ec-ef22941f50f5 | default | egress, IPv4 | | | | egress, IPv6 | | | | ingress, IPv4, 22/tcp, remote_ip_prefix: 192.168.8.1/32 | | | | ingress, IPv4, remote_group_id: 75fccd0a-ef3d-44cd-91ec-ef22941f50f5 | | | | ingress, IPv6, remote_group_id: 75fccd0a-ef3d-44cd-91ec-ef22941f50f5 | | 903d9936-ce72-4756-a2cc-7c95a846e7e5 | default | egress, IPv4 | | | | egress, IPv6 | | | | ingress, IPv4, 22/tcp, remote_ip_prefix: 192.168.8.1/32 | | | | ingress, IPv4, remote_group_id: 903d9936-ce72-4756-a2cc-7c95a846e7e5 | | | | ingress, IPv6, remote_group_id: 903d9936-ce72-4756-a2cc-7c95a846e7e5 | +--------------------------------------+---------+----------------------------------------------------------------------+
서비스 IP를 다른 VM으로 옮기기
서비스 IP는 HA(고가용성)에 자주 쓰여요. 그래서 첫 번째 VM이 어떤 이유로 실패하면(또는 HA 시스템이 활성 VM을 순환하기로 하면) 다른 VM을 대상으로 옮겨야 해요.
-
이를 시연하기 위해 두 번째 테스트 VM을 만들어요.
nova boot --flavor m1.tiny --image cirros-0.3.2-x86_64 --nic net-name=demo-net testvm2 -
VM 목록을 확인해요.
nova list목록에서 새 VM을 볼 수 있어요.
+--------------------------------------+---------+--------+------------+-------------+----------------------------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+---------+--------+------------+-------------+----------------------------------------------+ | b6d8a3c4-9674-4972-9151-11107b60d622 | testvm1 | ACTIVE | - | Running | demo-net=10.28.0.13, 10.28.0.23 | | bb4ef5e3-dc77-472e-af6f-3f0d8c3e5a6d | testvm2 | ACTIVE | - | Running | demo-net=10.28.0.14, fd5f:5d21:845:1c2e:2::e | +--------------------------------------+---------+--------+------------+-------------+----------------------------------------------+ -
포트를 확인해요.
neutron port-list다음과 비슷한 결과가 반환돼요.
+--------------------------------------+------+-------------------+------------------------------------------------------------------------------------------------+ | id | name | mac_address | fixed_ips | +--------------------------------------+------+-------------------+------------------------------------------------------------------------------------------------+ | 656b3617-570d-473e-a5dd-90b61cb0c49f | | fa:16:3e:4d:d5:25 | | | 7627a298-a2db-4a1a-bc07-9f0f10f58363 | | fa:16:3e:8e:dc:33 | {"subnet_id": "0a1221f2-e6ed-413d-a040-62a266bd0d8f", "ip_address": "10.28.0.14"} | | | | | {"subnet_id": "345fec2e-6493-44de-a489-97b755c16dd4", "ip_address": "fd5f:5d21:845:1c2e:2::e"} | | 9a7e0868-da7a-419e-a7ad-9d37e11091b8 | | fa:16:3e:28:a9:a4 | {"subnet_id": "0a1221f2-e6ed-413d-a040-62a266bd0d8f", "ip_address": "10.28.0.13"} | | | | | {"subnet_id": "0a1221f2-e6ed-413d-a040-62a266bd0d8f", "ip_address": "10.28.0.23"} | | a4b26bcc-ba94-4033-a9fc-edaf151c0c20 | | fa:16:3e:74:46:bd | | | a772a5e1-2f13-4fc3-96d5-fa1c29717637 | | fa:16:3e:c9:c6:8f | | +--------------------------------------+------+-------------------+------------------------------------------------------------------------------------------------+ -
첫 번째 VM에서 서비스 IP를 제거해요.
neutron port-update --fixed-ip subnet_id=0a1221f2-e6ed-413d-a040-62a266bd0d8f,ip_address=10.28.0.13 9a7e0868-da7a-419e-a7ad-9d37e11091b8 -
그리고 두 번째 VM에 추가해요.
neutron port-update --fixed-ip subnet_id=0a1221f2-e6ed-413d-a040-62a266bd0d8f,ip_address=10.28.0.14 \ --fixed-ip subnet_id=0a1221f2-e6ed-413d-a040-62a266bd0d8f,ip_address=10.28.0.23 7627a298-a2db-4a1a-bc07-9f0f10f58363 -
testvm2에 SSH로 접속해요.core@access-node$ ssh cirros@10.28.0.14 The authenticity of host '10.28.0.14 (10.28.0.14)' can't be established. RSA key fingerprint is 6a:02:7f:3a:bf:0c:91:de:c4:d6:e7:f6:81:3f:6a:85. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.28.0.14' (RSA) to the list of known hosts. cirros@10.28.0.14's password: -
testvm2에게 이제 서비스 IP10.28.0.23을 갖고 있다고 알려 줘요.sudo ip a a 10.28.0.23/16 dev eth0 -
이제
10.28.0.23으로의 연결은testvm2로 향해요.core@access-node$ ssh cirros@10.28.0.23 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the RSA key sent by the remote host is 6a:02:7f:3a:bf:0c:91:de:c4:d6:e7:f6:81:3f:6a:85. Please contact your system administrator. Add correct host key in /home/core/.ssh/known_hosts to get rid of this message. Offending RSA key in /home/core/.ssh/known_hosts:4 RSA host key for 10.28.0.23 has changed and you have requested strict checking. Host key verification failed. -
known_hosts파일을 제거해요.rm ~/.ssh/known_hosts -
다시 VM에 SSH로 접속해 보세요.
core@access-node$ ssh cirros@10.28.0.23 The authenticity of host '10.28.0.23 (10.28.0.23)' can't be established. RSA key fingerprint is 6a:02:7f:3a:bf:0c:91:de:c4:d6:e7:f6:81:3f:6a:85. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.28.0.23' (RSA) to the list of known hosts. cirros@10.28.0.23's password: -
호스트 이름을 확인해요.
hostname다음이 반환돼요:
testvm2 -
인터페이스를 확인해요.
ip a다음과 비슷하게 보여요.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether fa:16:3e:8e:dc:33 brd ff:ff:ff:ff:ff:ff inet 10.28.0.14/16 brd 10.28.255.255 scope global eth0 inet 10.28.0.23/16 scope global secondary eth0 inet6 fe80::f816:3eff:fe8e:dc33/64 scope link valid_lft forever preferred_lft forever $
더 알아보기 (Learn more)
플로팅 IP 방식과 추가 고정 IP 방식의 차이는 DNAT 여부에 있어요. HA 구성에서 서비스 IP를 옮길 때는 포트 업데이트와 VM 내부의 ip a a 명령을 항상 함께 기억해 두세요.