-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Added mechanism to specify ip_hash in the upstream directive #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Any plans on merging this one into the master branch? |
1fd3ef0
to
388c18a
Compare
To make this more flexible, I changed the environment variable to be set at the individual container level. |
This is awesome. I have been globally inserting ip_hash, but this change makes it possible per service. Please merge. :) |
+1 |
Any update on whether this might be merged? |
+1 to merge tpcwang commit This is very useful. Sometimes I scale containers with Please, merge tpcwang commit. |
For Docker-Compose, I have worked around this by changing the command that is run at container startup: version: "2"
services:
nginx:
image: jwilder/nginx-proxy
container_name: nginx
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
ports:
- "8082:80"
command: >
bash -c "
sed -i -e 's/^\(upstream .*\)/\1 \n ip_hash;/g' nginx.tmpl ;
forego start -r
" The |
I need this feature too. Why this task still pending? we like tpcwang commit. please merge |
@nwinkler the solution is good but sometime I only want to stick one service not all. Your option is hash all services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of issues:
- Needs a rebase
- Needs documentation added to the README about how to enable this, what it actually does and why someone might need it.
- bats tests were removed in favor of a python testing framework. We'll need to switch to those test since the bats ones do not run anymore.
I need this feature please resolve the conflicts :( |
Hi, as I needed this feature right here and now, but didn't have the time to make it a propert PR, I took @nwinkler's composer file and combined it with the informations provided by @tpcwang's pullrequest. command: >
bash -c "
sed -i -e 's/^\(upstream .*\)/{{ $$ip_hash := or (first (groupByKeys $$containers \"Env.USE_IP_HASH\")) \"0\" }}\n\n\1 \n{{ if ne $$ip_hash \"0\" }} \n ip_hash;\n{{ end }}/g' nginx.tmpl ;
forego start -r
" With this change in place, you can now select the ip affinity per service/container by setting the USE_IP_ENV variable to 1. It's not the most elegant solution, but it should survive future updates to the nginx.tmpl. If I find the time, I'll probably try to takle the PR in the coming days/weeks, but I can't make any promises on that. |
I think you meant |
+1 for this feature... |
What is needed to merge this? |
I managed to get this configured with a modifications on the script provided by @ricktap Here is the script I used as entrypoint in the docker-compose file #!/bin/bash
set -e
main() {
template_file="/app/nginx.tmpl"
if ! grep -q "ip_hash;" "$template_file"; then
echo "Changing config..."
sed -i -e 's/^\(upstream .*\)/{{ $ip_hash := or (first (groupByKeys .Containers \"Env.USE_IP_HASH\")) \"0\" }}\n\n\1 \n{{ if ne $ip_hash \"0\" }} \n ip_hash;\n{{ end }}/g' $template_file
echo "Change done. Starting..."
else
echo "File is already adapted. Starting..."
fi
forego start -r
}
main "$@" |
This should address #221