apiVersion: v1 kind: Pod metadata: name: client namespace: istio-vt-t34 labels: app: client annotations: sidecar.istio.io/inject: "true" spec: containers: - name: curl image: curlimages/curl:8.14.1 command: ["sleep", "infinity"] --- apiVersion: apps/v1 kind: Deployment metadata: name: echo namespace: istio-vt-t34 labels: app: echo spec: replicas: 1 selector: matchLabels: app: echo template: metadata: labels: app: echo annotations: sidecar.istio.io/inject: "true" spec: containers: - name: echo image: mendhak/http-https-echo:37 env: - name: HTTP_PORT value: "8080" - name: HTTPS_PORT value: "8443" ports: - containerPort: 8080 - containerPort: 8443 --- apiVersion: v1 kind: Service metadata: name: echo namespace: istio-vt-t34 spec: selector: app: echo ports: - name: http port: 80 targetPort: 8080 - name: https port: 443 targetPort: 8443 --- apiVersion: v1 kind: ConfigMap metadata: name: hc-mock-src namespace: istio-vt-t34 data: hc_mock.py: | import json, threading from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer lock = threading.Lock() state = "OPEN" TABLE = { "OPEN": {"health_check.html": 200, "health": 200, "live": 200}, "DRAINING": {"health_check.html": 200, "health": 200, "live": 200}, "CLOSING": {"health_check.html": 503, "health": 200, "live": 200}, "CLOSED": {"health_check.html": 503, "health": 503, "live": 200}, "FAULT": {"health_check.html": 503, "health": 503, "live": 500}, } class H(BaseHTTPRequestHandler): def _reply(self, code, body=b""): self.send_response(code); self.end_headers() if body: self.wfile.write(body) def do_GET(self): p = self.path.lstrip("/") if p in TABLE["OPEN"]: with lock: code = TABLE[state][p] self._reply(code) elif p == "drain/status": with lock: body = json.dumps({"state": state}).encode() self._reply(200, body) else: self._reply(404) def do_POST(self): global state p = self.path.lstrip("/") with lock: cur = state; nxt = None if p == "drain" and cur == "OPEN": nxt = "DRAINING" elif p == "close-lb" and cur == "DRAINING": nxt = "CLOSING" elif p == "close" and cur == "CLOSING": nxt = "CLOSED" elif p == "reopen" and cur in ("DRAINING", "CLOSING"): nxt = "OPEN" elif p == "fault": nxt = "FAULT" if nxt is None: self._reply(409); return state = nxt self._reply(200) def log_message(self, *a): pass if __name__ == "__main__": ThreadingHTTPServer(("0.0.0.0", 18180), H).serve_forever() --- apiVersion: v1 kind: Pod metadata: name: hc-mock namespace: istio-vt-t34 labels: app: hc-mock annotations: sidecar.istio.io/inject: "false" spec: containers: - name: hc-mock image: python:3.12-alpine command: ["python3", "/srv/hc_mock.py"] ports: - containerPort: 18180 volumeMounts: - name: src mountPath: /srv volumes: - name: src configMap: name: hc-mock-src --- apiVersion: v1 kind: Service metadata: name: hc-mock namespace: istio-vt-t34 spec: selector: app: hc-mock ports: - port: 18180 targetPort: 18180 name: http --- apiVersion: apps/v1 kind: Deployment metadata: name: slow-echo namespace: istio-vt-t34 labels: app: slow-echo spec: replicas: 1 selector: matchLabels: app: slow-echo template: metadata: labels: app: slow-echo annotations: sidecar.istio.io/inject: "true" spec: containers: - name: httpbin image: kennethreitz/httpbin ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: slow-echo namespace: istio-vt-t34 spec: selector: app: slow-echo ports: - port: 80 targetPort: 80 name: http