forked from 31z4/zookeeper-docker
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a mechanism for Kubernetes StatefulSet, guess id from hostname
- Loading branch information
Showing
1 changed file
with
6 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
df9474f
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.
You really should submit this as a Pull Request for the official zookeeper repo, maybe with a variable flag such as
EXTRACT_ID_FROM_ORDINAL
(or something with a better name)df9474f
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.
@deitch What is your use case for this fix? I thought that maybe there are more generic ways to do this, but that I just didn't know enough about zk.
df9474f
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.
Trying to think it through.
zk requires a unique ID for each server that starts up. When running three individual servers, it is easy to just set them. But doing it the right way, with a StatefulSet, means you state one spec with however many replicas you want. If the spec is identical, the
ZOO_MY_ID
will be too, and all three (or however many replicas you have) will have same ID, and zk will fail.StatefulSets attach an ordinal to each replica (0, 1, 2...). It also gives each container a unique hostname by appending
-
ordinal. So you can get the sequential ID by extracting it out of the hostname.The right thing to do, of course, is to have an env var set dynamically for the ordinal. k8s 1.5 does not support it, but I think they are targeting 1.6. See kubernetes/kubernetes#40651
df9474f
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.
Yep, that was my understanding too. If I remember correctly, the first zookeeper ID must be 1. That means we still need some entrypoint work with
valueFrom
fieldRef
fieldPath
, don't we?df9474f
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.
df9474f
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.
Once they have the sets in place, we don't need the above patch. We can set the ordinal to an env var. I would do something like this:
df9474f
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.
Perhaps. They still need an image that behaves nicely when run in the k8s environment. Those are just config packaging, but they still reference the image itself.
df9474f
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.
But you'd get ZOO_MY_ID=0 which is invalid.
df9474f
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.
Oh yeah. Nice catch.