Last active
August 29, 2020 19:05
-
-
Save olix0r/a4961282b273db3ea31540143c418cd4 to your computer and use it in GitHub Desktop.
traffic split rotator
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
--- | |
kind: Namespace | |
apiVersion: v1 | |
metadata: | |
name: strest | |
labels: | |
app: strest | |
# target.strest.svc.cluster.local receives all strest traffic. | |
--- | |
kind: Service | |
apiVersion: v1 | |
metadata: | |
name: target | |
namespace: strest | |
labels: | |
app: strest | |
strest-role: server | |
spec: | |
type: ClusterIP | |
selector: | |
app: strest | |
strest-role: server | |
ports: | |
- name: strest-grpc | |
port: 8888 | |
targetPort: 8888 | |
# blue.strest.svc.cluster.local sends traffic to blue pods | |
--- | |
kind: Service | |
apiVersion: v1 | |
metadata: | |
name: blue | |
namespace: strest | |
labels: | |
app: strest | |
strest-role: server | |
strest-color: blue | |
spec: | |
type: ClusterIP | |
selector: | |
app: strest | |
strest-role: server | |
strest-color: blue | |
ports: | |
- name: strest-grpc | |
port: 8888 | |
targetPort: 8888 | |
# green.strest.svc.cluster.local sends traffic to green pods | |
--- | |
kind: Service | |
apiVersion: v1 | |
metadata: | |
name: green | |
namespace: strest | |
labels: | |
app: strest | |
strest-role: server | |
strest-color: green | |
spec: | |
type: ClusterIP | |
selector: | |
app: strest | |
strest-role: server | |
strest-color: green | |
ports: | |
- name: strest-grpc | |
port: 8888 | |
targetPort: 8888 | |
--- | |
kind: Deployment | |
apiVersion: apps/v1 | |
metadata: | |
name: strest-server-blue | |
namespace: strest | |
labels: | |
app: strest | |
strest-role: server | |
strest-color: blue | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: strest | |
strest-role: server | |
strest-color: blue | |
template: | |
metadata: | |
labels: | |
app: strest | |
strest-role: server | |
strest-color: blue | |
spec: | |
containers: | |
- name: main | |
image: buoyantio/strest-grpc:0.0.6 | |
imagePullPolicy: IfNotPresent | |
ports: | |
- name: strest-grpc | |
containerPort: 8888 | |
- name: admin-http | |
containerPort: 9999 | |
args: ["server", "--address=:8888", "--metricAddr=:9999"] | |
--- | |
kind: Deployment | |
apiVersion: apps/v1 | |
metadata: | |
name: strest-server-green | |
namespace: strest | |
labels: | |
app: strest | |
strest-role: server | |
strest-color: green | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: strest | |
strest-role: server | |
strest-color: green | |
template: | |
metadata: | |
labels: | |
app: strest | |
strest-role: server | |
strest-color: green | |
spec: | |
containers: | |
- name: main | |
image: buoyantio/strest-grpc:0.0.6 | |
imagePullPolicy: IfNotPresent | |
ports: | |
- name: strest-grpc | |
containerPort: 8888 | |
- name: admin-http | |
containerPort: 9999 | |
args: ["server", "--address=:8888", "--metricAddr=:9999"] | |
--- | |
kind: Deployment | |
apiVersion: apps/v1 | |
metadata: | |
name: strest-client | |
namespace: strest | |
labels: | |
app: strest | |
strest-role: client | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: strest | |
strest-role: client | |
template: | |
metadata: | |
labels: | |
app: strest | |
strest-role: client | |
spec: | |
containers: | |
- name: main | |
image: buoyantio/strest-grpc:0.0.6 | |
imagePullPolicy: IfNotPresent | |
ports: | |
- name: admin-http | |
containerPort: 9999 | |
args: | |
[ | |
"client", | |
"--address", | |
"target:8888", | |
"--metricAddr", | |
":9999", | |
"--streams", | |
"1", | |
] | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
labels: | |
app: split-updater | |
name: split-updater | |
namespace: strest | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: split-updater | |
template: | |
metadata: | |
labels: | |
app: split-updater | |
annotations: | |
linkerd.io/inject: disabled | |
spec: | |
serviceAccount: split-updater | |
volumes: | |
- name: ts | |
configMap: | |
name: trafficsplits | |
containers: | |
- image: lachlanevenson/k8s-kubectl:v1.18.0 | |
name: split-updater | |
env: | |
- name: NS | |
valueFrom: | |
fieldRef: | |
fieldPath: metadata.namespace | |
volumeMounts: | |
- name: ts | |
mountPath: /ts | |
command: | |
- /bin/sh | |
args: | |
- -c | |
- |- | |
set -x | |
echo "namespace=$NS" | |
while true; do | |
sleep 10 | |
kubectl -n "$NS" apply -f /ts/blue-green.yml | |
sleep 120 | |
kubectl -n "$NS" apply -f /ts/green-blue.yml | |
sleep 120 | |
kubectl -n "$NS" delete -f /ts/green-blue.yml | |
sleep 110 | |
done | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
namespace: strest | |
name: trafficsplits | |
data: | |
blue-green.yml: |- | |
apiVersion: split.smi-spec.io/v1alpha1 | |
kind: TrafficSplit | |
metadata: | |
namespace: strest | |
name: blue-green | |
spec: | |
service: target | |
backends: | |
- service: blue | |
weight: 90m | |
- service: green | |
weight: 10m | |
green-blue.yml: |- | |
apiVersion: split.smi-spec.io/v1alpha1 | |
kind: TrafficSplit | |
metadata: | |
namespace: strest | |
name: blue-green | |
spec: | |
service: target | |
backends: | |
- service: blue | |
weight: 10m | |
- service: green | |
weight: 90m | |
--- | |
kind: ServiceAccount | |
apiVersion: v1 | |
metadata: | |
name: split-updater | |
namespace: strest | |
labels: | |
app: split-updater | |
--- | |
kind: Role | |
apiVersion: rbac.authorization.k8s.io/v1beta1 | |
metadata: | |
name: strest:split-updater | |
namespace: strest | |
labels: | |
app: split-updater | |
rules: | |
- apiGroups: ["split.smi-spec.io"] | |
resources: ["trafficsplits"] | |
verbs: ["create", "delete", "get", "update", "patch"] | |
--- | |
kind: RoleBinding | |
apiVersion: rbac.authorization.k8s.io/v1beta1 | |
metadata: | |
name: strest:split-updater | |
namespace: strest | |
labels: | |
app: split-updater | |
roleRef: | |
apiGroup: rbac.authorization.k8s.io | |
kind: Role | |
name: strest:split-updater | |
subjects: | |
- kind: ServiceAccount | |
name: split-updater |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment