Skip to content

Instantly share code, notes, and snippets.

@chadmcrowell
Created August 29, 2025 22:07
Show Gist options
  • Save chadmcrowell/bdab50783c95601945526dfffb1b78c1 to your computer and use it in GitHub Desktop.
Save chadmcrowell/bdab50783c95601945526dfffb1b78c1 to your computer and use it in GitHub Desktop.
ingress to target one pod
# 1) Add a unique label to the target pod
kubectl -n "$NS" label pod "$POD" singled=true --overwrite
# 2) Service that selects only that pod
cat <<'YAML' | envsubst | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: web-single
namespace: ${NS}
spec:
selector:
app: web
singled: "true"
ports:
- port: 80
targetPort: 8080
YAML
# 3) Ingress host that points to that one-pod Service
cat <<'YAML' | envsubst | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-single
namespace: ${NS}
spec:
ingressClassName: nginx
rules:
- host: ${POD}.${NS}.app.${LB_IP}.sslip.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-single
port:
number: 80
YAML
# 4) Call that specific pod via Ingress
curl -sS "http://${POD}.${NS}.app.${LB_IP}.sslip.io/hostname"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment