Skip to content

Instantly share code, notes, and snippets.

@llamasoft
Created May 13, 2020 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llamasoft/aaca58fda0ec2e06f2fee4f272691460 to your computer and use it in GitHub Desktop.
Save llamasoft/aaca58fda0ec2e06f2fee4f272691460 to your computer and use it in GitHub Desktop.
A short, simple Istio traffic splitting demo.
apiVersion: v1
kind: ConfigMap
metadata:
name: httpy-files
data:
server.py: |
import http.server
import os
import socket
import json
class HTTPResponder(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
resp = {
"host": socket.gethostname(),
"pid": os.getpid(),
"response": os.environ.get("RESPONSE", "DEFAULT"),
"path": self.path,
}
self.wfile.write(
json.dumps(resp).encode('utf-8')
)
httpd = http.server.HTTPServer(
('localhost', 9080),
HTTPResponder
)
httpd.serve_forever()
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpy-stable
labels:
app: httpy
spec:
replicas: 1
selector:
matchLabels:
app: httpy
version: v1
isCanary: "false"
template:
metadata:
labels:
app: httpy
version: v1
isCanary: "false"
spec:
volumes:
- name: python-files
configMap:
name: httpy-files
containers:
- name: httpy
image: "python:rc-alpine"
volumeMounts:
- name: python-files
mountPath: /py
command:
- "python3"
args:
- "/py/server.py"
env:
- name: RESPONSE
value: "PRODUCTION"
ports:
- name: http
containerPort: 9080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpy-canary
labels:
app: httpy
spec:
replicas: 1
selector:
matchLabels:
app: httpy
version: v2
isCanary: "true"
template:
metadata:
labels:
app: httpy
version: v2
isCanary: "true"
spec:
volumes:
- name: python-files
configMap:
name: httpy-files
containers:
- name: httpy
image: "python:rc-alpine"
volumeMounts:
- name: python-files
mountPath: /py
command:
- "python3"
args:
- "/py/server.py"
env:
- name: RESPONSE
value: "CANARY"
ports:
- name: http
containerPort: 9080
---
apiVersion: v1
kind: Service
metadata:
name: httpy
labels:
app: httpy
spec:
selector:
app: httpy
ports:
- name: http
port: 9080
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpy
spec:
hosts:
- httpy
http:
- route:
- destination:
host: httpy
subset: prod
weight: 90
- destination:
host: httpy
subset: canary
weight: 10
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: httpy
spec:
host: httpy
subsets:
- name: prod
labels:
isCanary: "false"
- name: canary
labels:
isCanary: "true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment