Session Persistence using Traefik on Docker Swarm Replicas
up vote
1
down vote
favorite
I trying to implement sticky session on dockers-swarm with traefik, but I could not achieve session persistence over two replicas on same machine.
In my docker-compose.yml, I have added labels for traefik and added the loadbalancer as well. Below is my docker-compose.yml, (Although the indentation might not look proper here, but it correct in actual project)
version: '3'
services:
web:
image: php:7.2.11-apache-stretch
ports:
- "8080:80"
volumes:
- ./code/:/var/www/html/hello/
stdin_open: true
tty: true
deploy:
mode: replicated
replicas: 2
restart_policy:
condition: any
update_config:
delay: 2s
labels:
- "traefik.docker.network=docker-test_privnet"
- "traefik.port=80"
- "traefik.backend.loadbalancer.sticky=true"
- "traefik.frontend.rule=PathPrefix:/hello"
networks:
- privnet
loadbalancer:
image: traefik
command:
--docker
--docker.swarmmode
--docker.watch
--web
--loglevel=DEBUG
ports:
- 80:80
- 9090:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
restart_policy:
condition: any
mode: replicated
replicas: 1
update_config:
delay: 2s
placement:
constraints: [node.role == manager]
networks:
- privnet
networks:
privnet:
external: true
Am I missing anything?
docker docker-compose docker-swarm traefik docker-swarm-mode
add a comment |
up vote
1
down vote
favorite
I trying to implement sticky session on dockers-swarm with traefik, but I could not achieve session persistence over two replicas on same machine.
In my docker-compose.yml, I have added labels for traefik and added the loadbalancer as well. Below is my docker-compose.yml, (Although the indentation might not look proper here, but it correct in actual project)
version: '3'
services:
web:
image: php:7.2.11-apache-stretch
ports:
- "8080:80"
volumes:
- ./code/:/var/www/html/hello/
stdin_open: true
tty: true
deploy:
mode: replicated
replicas: 2
restart_policy:
condition: any
update_config:
delay: 2s
labels:
- "traefik.docker.network=docker-test_privnet"
- "traefik.port=80"
- "traefik.backend.loadbalancer.sticky=true"
- "traefik.frontend.rule=PathPrefix:/hello"
networks:
- privnet
loadbalancer:
image: traefik
command:
--docker
--docker.swarmmode
--docker.watch
--web
--loglevel=DEBUG
ports:
- 80:80
- 9090:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
restart_policy:
condition: any
mode: replicated
replicas: 1
update_config:
delay: 2s
placement:
constraints: [node.role == manager]
networks:
- privnet
networks:
privnet:
external: true
Am I missing anything?
docker docker-compose docker-swarm traefik docker-swarm-mode
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I trying to implement sticky session on dockers-swarm with traefik, but I could not achieve session persistence over two replicas on same machine.
In my docker-compose.yml, I have added labels for traefik and added the loadbalancer as well. Below is my docker-compose.yml, (Although the indentation might not look proper here, but it correct in actual project)
version: '3'
services:
web:
image: php:7.2.11-apache-stretch
ports:
- "8080:80"
volumes:
- ./code/:/var/www/html/hello/
stdin_open: true
tty: true
deploy:
mode: replicated
replicas: 2
restart_policy:
condition: any
update_config:
delay: 2s
labels:
- "traefik.docker.network=docker-test_privnet"
- "traefik.port=80"
- "traefik.backend.loadbalancer.sticky=true"
- "traefik.frontend.rule=PathPrefix:/hello"
networks:
- privnet
loadbalancer:
image: traefik
command:
--docker
--docker.swarmmode
--docker.watch
--web
--loglevel=DEBUG
ports:
- 80:80
- 9090:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
restart_policy:
condition: any
mode: replicated
replicas: 1
update_config:
delay: 2s
placement:
constraints: [node.role == manager]
networks:
- privnet
networks:
privnet:
external: true
Am I missing anything?
docker docker-compose docker-swarm traefik docker-swarm-mode
I trying to implement sticky session on dockers-swarm with traefik, but I could not achieve session persistence over two replicas on same machine.
In my docker-compose.yml, I have added labels for traefik and added the loadbalancer as well. Below is my docker-compose.yml, (Although the indentation might not look proper here, but it correct in actual project)
version: '3'
services:
web:
image: php:7.2.11-apache-stretch
ports:
- "8080:80"
volumes:
- ./code/:/var/www/html/hello/
stdin_open: true
tty: true
deploy:
mode: replicated
replicas: 2
restart_policy:
condition: any
update_config:
delay: 2s
labels:
- "traefik.docker.network=docker-test_privnet"
- "traefik.port=80"
- "traefik.backend.loadbalancer.sticky=true"
- "traefik.frontend.rule=PathPrefix:/hello"
networks:
- privnet
loadbalancer:
image: traefik
command:
--docker
--docker.swarmmode
--docker.watch
--web
--loglevel=DEBUG
ports:
- 80:80
- 9090:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
restart_policy:
condition: any
mode: replicated
replicas: 1
update_config:
delay: 2s
placement:
constraints: [node.role == manager]
networks:
- privnet
networks:
privnet:
external: true
Am I missing anything?
docker docker-compose docker-swarm traefik docker-swarm-mode
docker docker-compose docker-swarm traefik docker-swarm-mode
asked Nov 9 at 17:22
Swastik Roy
749
749
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
A few things.
.sticky
is deprecated in favor oftraefik.backend.loadbalancer.stickiness=true
- I don't think you need to set the network with
traefik.docker.network
when you only have a single network connected to that service. - Make sure you're testing with a tool that uses cookies, which is how sticky sessions stay sticky. If using curl, be sure to use
-c
and-b
as in this example. - I used the voting app sample from my test Swarm setup and added sticky sessions to the "vote" service and it worked for me on a single node. If using a multi-node swarm you'll need the LB in front of multiple swarm nodes to also enable sticky.
1
Hi, Seems like we need to set traefik.docker.network if we need to have the traefik dashboard in a subdomain like traefik.domain.com. Then, the issue was solved after I fixed my front end rules and defined Host rule for each service.
– Swastik Roy
Nov 18 at 4:27
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230548%2fsession-persistence-using-traefik-on-docker-swarm-replicas%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
A few things.
.sticky
is deprecated in favor oftraefik.backend.loadbalancer.stickiness=true
- I don't think you need to set the network with
traefik.docker.network
when you only have a single network connected to that service. - Make sure you're testing with a tool that uses cookies, which is how sticky sessions stay sticky. If using curl, be sure to use
-c
and-b
as in this example. - I used the voting app sample from my test Swarm setup and added sticky sessions to the "vote" service and it worked for me on a single node. If using a multi-node swarm you'll need the LB in front of multiple swarm nodes to also enable sticky.
1
Hi, Seems like we need to set traefik.docker.network if we need to have the traefik dashboard in a subdomain like traefik.domain.com. Then, the issue was solved after I fixed my front end rules and defined Host rule for each service.
– Swastik Roy
Nov 18 at 4:27
add a comment |
up vote
1
down vote
A few things.
.sticky
is deprecated in favor oftraefik.backend.loadbalancer.stickiness=true
- I don't think you need to set the network with
traefik.docker.network
when you only have a single network connected to that service. - Make sure you're testing with a tool that uses cookies, which is how sticky sessions stay sticky. If using curl, be sure to use
-c
and-b
as in this example. - I used the voting app sample from my test Swarm setup and added sticky sessions to the "vote" service and it worked for me on a single node. If using a multi-node swarm you'll need the LB in front of multiple swarm nodes to also enable sticky.
1
Hi, Seems like we need to set traefik.docker.network if we need to have the traefik dashboard in a subdomain like traefik.domain.com. Then, the issue was solved after I fixed my front end rules and defined Host rule for each service.
– Swastik Roy
Nov 18 at 4:27
add a comment |
up vote
1
down vote
up vote
1
down vote
A few things.
.sticky
is deprecated in favor oftraefik.backend.loadbalancer.stickiness=true
- I don't think you need to set the network with
traefik.docker.network
when you only have a single network connected to that service. - Make sure you're testing with a tool that uses cookies, which is how sticky sessions stay sticky. If using curl, be sure to use
-c
and-b
as in this example. - I used the voting app sample from my test Swarm setup and added sticky sessions to the "vote" service and it worked for me on a single node. If using a multi-node swarm you'll need the LB in front of multiple swarm nodes to also enable sticky.
A few things.
.sticky
is deprecated in favor oftraefik.backend.loadbalancer.stickiness=true
- I don't think you need to set the network with
traefik.docker.network
when you only have a single network connected to that service. - Make sure you're testing with a tool that uses cookies, which is how sticky sessions stay sticky. If using curl, be sure to use
-c
and-b
as in this example. - I used the voting app sample from my test Swarm setup and added sticky sessions to the "vote" service and it worked for me on a single node. If using a multi-node swarm you'll need the LB in front of multiple swarm nodes to also enable sticky.
answered Nov 11 at 19:46
Bret Fisher
3,24111321
3,24111321
1
Hi, Seems like we need to set traefik.docker.network if we need to have the traefik dashboard in a subdomain like traefik.domain.com. Then, the issue was solved after I fixed my front end rules and defined Host rule for each service.
– Swastik Roy
Nov 18 at 4:27
add a comment |
1
Hi, Seems like we need to set traefik.docker.network if we need to have the traefik dashboard in a subdomain like traefik.domain.com. Then, the issue was solved after I fixed my front end rules and defined Host rule for each service.
– Swastik Roy
Nov 18 at 4:27
1
1
Hi, Seems like we need to set traefik.docker.network if we need to have the traefik dashboard in a subdomain like traefik.domain.com. Then, the issue was solved after I fixed my front end rules and defined Host rule for each service.
– Swastik Roy
Nov 18 at 4:27
Hi, Seems like we need to set traefik.docker.network if we need to have the traefik dashboard in a subdomain like traefik.domain.com. Then, the issue was solved after I fixed my front end rules and defined Host rule for each service.
– Swastik Roy
Nov 18 at 4:27
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230548%2fsession-persistence-using-traefik-on-docker-swarm-replicas%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown