edit-icon download-icon

Custom routing - supports TCP

Last Updated: Jan 02, 2018

When Alibaba Cloud Container Service is in use, the following problem might occur to TCP Server Load Balancer: when the client image and server image of an application are deployed on the same Elastic Compute Service (ECS) instance, the application client cannot access the local server by using Server Load Balancer due to the limitation of Server Load Balancer. In this document, take the common TCP-based Redis as an example to describe how to solve the problem by using the custom routing acs/proxy.

Solution 1: Deploy client and server containers on different nodes by scheduling containers

The following is a sample application template (the lb label and swarm filter function are used):

  1. redis-master:
  2. ports:
  3. - 6379:6379/tcp
  4. image: 'redis:alpine'
  5. labels:
  6. aliyun.lb.port_6379: tcp://proxy_test:6379
  7. redis-client:
  8. image: 'redis:alpine'
  9. links:
  10. - redis-master
  11. environment:
  12. - 'affinity:aliyun.lb.port_6379!=tcp://proxy_test:6379'
  13. command: redis-cli -h 120.25.131.64
  14. stdin_open: true
  15. tty: true

Note:

  • Follow these steps if the scheduling does not take effect:
    1. Log on to the Container Service console.
    2. Click Services in the left-side navigation pane.
    3. Select the cluster in which the service you want to reschedule resides from the Cluster list.
    4. Click Reschedule at the right of the service you want to reschedule.
    5. Select the Force Reschedule check box in the displayed dialog box and then click OK.
  • The volumes of existing containers will be lost if you select the Force Reschedule check box. Backup and migrate the data in advance.

The following is a sample application template (the lb label is used):

  1. redis-master:
  2. ports:
  3. - 6379:6379/tcp
  4. image: 'redis:alpine'
  5. labels:
  6. aliyun.lb.port_6379: tcp://proxy_test:6379
  7. redis-client:
  8. image: 'redis:alpine'
  9. links:
  10. - redis-master
  11. command: redis-cli -h redis-master
  12. stdin_open: true
  13. tty: true

Solution 3: Clients inside the container cluster access the server by using Custom routing (which is based on HAProxy and serves as a proxy server), while clients outside access the server by using Server Load Balancer

The following is a sample application template (the lb label and Custom routing image are used):

  1. lb:
  2. image: registry.aliyuncs.com/acs/proxy:0.5
  3. ports:
  4. - '6379:6379/tcp'
  5. restart: always
  6. labels:
  7. # Addon allows the proxy image to function as a subscription registry center and dynamically load the service route.
  8. aliyun.custom_addon: "proxy"
  9. # A proxy image container is deployed on each virtual machine (VM).
  10. aliyun.global: "true"
  11. # A Server Load Balancer instance is bound to the frontend, and the lb label is used.
  12. aliyun.lb.port_6379: tcp://proxy_test:6379
  13. # Indicates that the custom routing must be started after the master Redis and slave Redis are started, and the custom routing depends on the master Redis and slave Redis.
  14. aliyun.depends: redis-master,redis-slave
  15. environment:
  16. # Indicates the range of backend containers that support route loading. "*" indicates the whole cluster. By default, it indicates the services in applications.
  17. ADDITIONAL_SERVICES: "*"
  18. EXTRA_DEFAULT_SETTINGS: "log rsyslog local0,log global,option httplog"
  19. # Configures HAProxy to work in TCP mode.
  20. MODE: "tcp"
  21. links:
  22. - rsyslog:rsyslog
  23. rsyslog:
  24. image: registry.cn-hangzhou.aliyuncs.com/linhuatest/rsyslog:latest
  25. redis-master:
  26. ports:
  27. - 6379/tcp
  28. image: 'redis:alpine'
  29. labels:
  30. # Indicates that the custom routing is to expose the port 6379.
  31. aliyun.proxy.TCP_PORTS: "6379"
  32. # Indicates that the service route is to be added to the custom routing.
  33. aliyun.proxy.required: "true"
  34. redis-slave:
  35. ports:
  36. - 6379/tcp
  37. image: 'redis:alpine'
  38. links:
  39. - redis-master
  40. labels:
  41. # Indicates that the custom routing is to expose the port 6379.
  42. aliyun.proxy.TCP_PORTS: "6379"
  43. # Indicates that the service route is to be added to the custom routing.
  44. aliyun.proxy.required: "true"
  45. # Indicates that the slave Redis depends on the master Redis and must be started after the master Redis is started.
  46. aliyun.depends: redis-master
  47. command: redis-server --slaveof redis-master 6379
  48. redis-client:
  49. image: 'redis:alpine'
  50. links:
  51. - lb:www.example.com
  52. labels:
  53. aliyun.depends: lb
  54. command: redis-cli -h www.example.com
  55. stdin_open: true
  56. tty: true

This solution provides a master-slave Redis architecture and balances load by using the Custom routing image so as to make Container Server become highly available.

Thank you! We've received your feedback.