Created
July 14, 2019 07:23
-
-
Save hareeshpc/c7d883a65859f84c8c4f8b07baf1927a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Dockerfile | |
| ---------- | |
| FROM python:3-alpine | |
| #FROM fedora:latest | |
| ADD ipvs.py / | |
| RUN pip install gnlpy six | |
| CMD [ "python", "./ipvs.py" ] | |
| ------- | |
| ipvs.py | |
| ------- | |
| from gnlpy import ipvs | |
| from gnlpy.ipvs import IpvsClient | |
| service_d ={ 'proto': socket.IPPROTO_TCP, | |
| 'vip': '192.168.0.100', | |
| 'port': 8080, | |
| 'sched': 'rr' } | |
| VIP = '1.2.3.4' | |
| RIPs = ['10.0.0.1','10.0.0.2','10.0.0.3' ] | |
| PORT = 8080 | |
| client = IpvsClient() | |
| try: | |
| client.add_service(vip=VIP, port=PORT) | |
| for rip in RIPs: | |
| client.add_dest(VIP, PORT, rip=rip, rport=PORT ) | |
| print ("everything completed") | |
| except Exception as e: | |
| print(e) | |
| ----- | |
| commands | |
| ------ | |
| docker rm $(docker ps -q -f status=exited) | |
| docker run --name=ipvs-py-ct --net=host --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /lib/modules:/lib/modules ipvs-py | |
| sudo ipvsadm -L | |
| docker rm $(docker ps -q -f status=exited) | |
| docker run --name=ipvs-py-ct --net=host --privileged -v /lib/modules:/lib/modules ipvs-py | |
| sudo ipvsadm -D -t 1.2.3.4:8080 | |
| sudo ipvsadm -L | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment