mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-19 09:57:45 +08:00

Tested with `kind` and GKE. Note: "nodes" shown in `docker buildx ls` are unrelated to Kubernetes "nodes". Probably buildx should come up with an alternative term. Usage: $ kind create cluster $ export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" $ docker buildx create --driver kubernetes --driver-opt replicas=3 --use $ docker buildx build -t foo --load . `--load` loads the image into the local Docker. Driver opts: - `image=IMAGE` - Sets the container image to be used for running buildkit. - `namespace=NS` - Sets the Kubernetes namespace. Defaults to the current namespace. - `replicas=N` - Sets the number of `Pod` replicas. Defaults to 1. - `rootless=(true|false)` - Run the container as a non-root user without `securityContext.privileged`. Defaults to false. - `loadbalance=(sticky|random)` - Load-balancing strategy. If set to "sticky", the pod is chosen using the hash of the context path. Defaults to "sticky" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
71 lines
1.9 KiB
Markdown
71 lines
1.9 KiB
Markdown
hashring
|
|
============================
|
|
|
|
Implements consistent hashing that can be used when
|
|
the number of server nodes can increase or decrease (like in memcached).
|
|
The hashing ring is built using the same algorithm as libketama.
|
|
|
|
This is a port of Python hash_ring library <https://pypi.python.org/pypi/hash_ring/>
|
|
in Go with the extra methods to add and remove nodes.
|
|
|
|
|
|
Using
|
|
============================
|
|
|
|
Importing ::
|
|
|
|
```go
|
|
import "github.com/serialx/hashring"
|
|
```
|
|
|
|
Basic example usage ::
|
|
|
|
```go
|
|
memcacheServers := []string{"192.168.0.246:11212",
|
|
"192.168.0.247:11212",
|
|
"192.168.0.249:11212"}
|
|
|
|
ring := hashring.New(memcacheServers)
|
|
server, _ := ring.GetNode("my_key")
|
|
```
|
|
|
|
To fulfill replication requirements, you can also get a list of servers that should store your key.
|
|
```go
|
|
serversInRing := []string{"192.168.0.246:11212",
|
|
"192.168.0.247:11212",
|
|
"192.168.0.248:11212",
|
|
"192.168.0.249:11212",
|
|
"192.168.0.250:11212",
|
|
"192.168.0.251:11212",
|
|
"192.168.0.252:11212"}
|
|
|
|
replicaCount := 3
|
|
ring := hashring.New(serversInRing)
|
|
server, _ := ring.GetNodes("my_key", replicaCount)
|
|
```
|
|
|
|
Using weights example ::
|
|
|
|
```go
|
|
weights := make(map[string]int)
|
|
weights["192.168.0.246:11212"] = 1
|
|
weights["192.168.0.247:11212"] = 2
|
|
weights["192.168.0.249:11212"] = 1
|
|
|
|
ring := hashring.NewWithWeights(weights)
|
|
server, _ := ring.GetNode("my_key")
|
|
```
|
|
|
|
Adding and removing nodes example ::
|
|
|
|
```go
|
|
memcacheServers := []string{"192.168.0.246:11212",
|
|
"192.168.0.247:11212",
|
|
"192.168.0.249:11212"}
|
|
|
|
ring := hashring.New(memcacheServers)
|
|
ring = ring.RemoveNode("192.168.0.246:11212")
|
|
ring = ring.AddNode("192.168.0.250:11212")
|
|
server, _ := ring.GetNode("my_key")
|
|
```
|