Skip to content

Instantly share code, notes, and snippets.

@peterj
Created February 23, 2024 16:24
Show Gist options
  • Save peterj/a01ef6a0b6408657cf7e9750e1024d79 to your computer and use it in GitHub Desktop.
Save peterj/a01ef6a0b6408657cf7e9750e1024d79 to your computer and use it in GitHub Desktop.
stateful set stuff
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: httpbin-statefulset
spec:
serviceName: httpbin
replicas: 1
selector:
matchLabels:
app: httpbin
template:
metadata:
labels:
app: httpbin
selector: httpbin
spec:
containers:
- image: docker.io/kong/httpbin
imagePullPolicy: IfNotPresent
name: httpbin
# Same as found in Dockerfile's CMD but using an unprivileged port
command:
- gunicorn
- -b
- 0.0.0.0:8080
- httpbin:app
- -k
- gevent
env:
# Tells pipenv to use a writable directory instead of $HOME
- name: WORKON_HOME
value: /tmp
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: httpbin
labels:
app: httpbin
spec:
clusterIP: None
selector:
app: httpbin
ports:
- port: 80
targetPort: 8080
@peterj
Copy link
Author

peterj commented Feb 23, 2024

Assuming you've scaled up the set, you can run nslookup (from another pod) against the service name:

$ nslookup httpbin.default.svc.cluster.local
Server:         10.96.0.10
Address:        10.96.0.10:53


Name:   httpbin.default.svc.cluster.local
Address: 10.244.0.12
Name:   httpbin.default.svc.cluster.local
Address: 10.244.0.13
Name:   httpbin.default.svc.cluster.local
Address: 10.244.0.14

Note the 3 IP address at the end correspond to the pods' IP addresses. Then, if you do nslookup against any of the instances:

 nslookup httpbin-statefulset-0.httpbin.default.svc.cluster.local
Server:         10.96.0.10
Address:        10.96.0.10:53

Name:   httpbin-statefulset-0.httpbin.default.svc.cluster.local
Address: 10.244.0.12

And doing curl httpbin-statefulset-0.httpbin.default.svc.cluster.local:8080/headers will send a response to the pod 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment