-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add election controlled service endpoints
Manually setting the endpoints for a service ensures that only the elected pods receive traffic. This works around issues where controlling traffic via pod readiness works suboptimal (i.e. rolling deployments). In rolling deployments, readiness of a pod controls the further roll-out of new versions. This means using readiness to control the service proxy would lead to a deadlock: the new pods would never become "ready" as an old pod still holds the lease, but the old pod is never terminated, as the rolling update only continues if the new pods are ready.
- Loading branch information
1 parent
07580ae
commit ddeca69
Showing
5 changed files
with
225 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
### Added | ||
* Ability to update service endpoints based on current leader | ||
|
||
### Changed | ||
* health endpoint now reports error on expired lease | ||
|
||
## [v0.1.0] 2020-07-29 | ||
|
||
### Added | ||
* Running in elected mode in k8s cluster | ||
* Running without election outside of k8s cluster | ||
* Basic error handling |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: my-service | ||
spec: | ||
clusterIP: "" | ||
ports: | ||
- name: my-port | ||
port: 1024 | ||
protocol: TCP | ||
# NOTE: No selector here! A selector would automatically add all matching and ready pods to the endpoint | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: my-server-with-replicas | ||
spec: | ||
replicas: 5 | ||
selector: | ||
matchLabels: | ||
app: my-server | ||
template: | ||
metadata: | ||
labels: | ||
app: my-server | ||
spec: | ||
containers: | ||
- name: my-server | ||
image: my-server | ||
args: | ||
- my-singleton-server | ||
ports: | ||
- containerPort: 1024 | ||
name: my-port | ||
env: | ||
- name: K8S_AWAIT_ELECTION_ENABLED | ||
value: "1" | ||
- name: K8S_AWAIT_ELECTION_NAME | ||
value: my-server | ||
- name: K8S_AWAIT_ELECTION_LOCK_NAME | ||
value: my-server | ||
- name: K8S_AWAIT_ELECTION_LOCK_NAMESPACE | ||
value: default | ||
- name: K8S_AWAIT_ELECTION_IDENTITY | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
- name: K8S_AWAIT_ELECTION_STATUS_ENDPOINT | ||
value: :9999 | ||
- name: K8S_AWAIT_ELECTION_SERVICE_NAME | ||
value: my-service | ||
- name: K8S_AWAIT_ELECTION_SERVICE_NAMESPACE | ||
value: default | ||
- name: K8S_AWAIT_ELECTION_SERVICE_PORTS_JSON | ||
value: '[{"name":"my-port","port":1024}]' | ||
- name: K8S_AWAIT_ELECTION_SERVICE_IP | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: status.podIP | ||
--- |
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
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