I have a statefulSet of pods running in my Kubernetes cluster.
apiVersion: apps/v1 kind: StatefulSet metadata: name: webserver namespace: kube-system labes: app: webserver spec: replicas: 3 selector: matchLabels: app: webserver template: metadata: labels: app: webserver spec: containers: name: php-apache-image image: my.localregistry.local:5000/php_apache:0.0.1 # Or your custom image ... ...
To use this "array of pods" I created the service
apiVersion: v1
kind: Service
metadata:
name: service4webserver
namespace: kube-system
spec:
selector:
app: webserver
ports:
- protocol: TCP
port: 8080 # The port on which the Service listens for incoming traffic.
targetPort: 80 # The port on the Pods to which the Service will forward the traffic.
This service will be directly called by another service which also will be called by a Traefik Ingress Controller. At the end, I need that any request arriving to service4webserver will be forwarded to the StatefulSet of pods and here be load balanced with Traefik. How to do this? Also, while at
it is said that to work with a StatefulSet services as service4webserver should be headless. However, I got service4webserver working well as a non headless service. Can this affect how to work with Traefik?
I am working with apiVersion: Traefik.io/alpha1 for my ingress route and the latest version of k3s version v1.33.3+k3s1 (236cbf25)
go version go1.24.4 and Traefik version 3.3.6
Thanks in Advance