k8s StatefulSet:
apiVersion: v1
kind: Service
metadata:
name: my-web
labels:
app: my-web
spec:
ports:
- name: http
port: 8080
targetPort: 8080
selector:
app: my-web
type: ClusterIP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: my-web
labels:
app: my-web
spec:
serviceName: my-web
selector:
matchLabels:
app: my-web
template:
metadata:
labels:
app: my-web
spec:
containers:
- image: my-web:1.0
ports:
- containerPort: 8080
server.xml
<Engine>
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.cloud.CloudMembershipService"/>
</Channel>
</Cluster>
...
</Engine>
Two pods running:
kubectl get pods | findstr web
NAME READY STATUS RESTARTS AGE
my-web-0 1/1 Running 0 53m
my-web-1 1/1 Running 0 52m
tomcat log from my-web-0 and my-web-1:
02-Jun-2023 17:43:26.282 INFO [main] org.apache.catalina.ha.session.DeltaManager.startInternal Register manager [localhost#] to cluster element [Engine] with name [Catalina]
02-Jun-2023 17:43:26.283 INFO [main] org.apache.catalina.ha.session.DeltaManager.startInternal Starting clustering manager at [localhost#]
02-Jun-2023 17:43:26.283 INFO [main] org.apache.catalina.ha.session.DeltaManager.getAllClusterSessions Manager [localhost#]: skipping state transfer. No members active in cluster group.
No members active in cluster group. Tomcat was not able to find cluster members. No error logs.
Pod my-web-0 and my-web-1 can connect each other.
my-web-0:
$ curl -v telnet://my-web-1.my-web:8080
Connected to my-web-1.my-web (10.1.0.247) port 8080 (#0)
my-web-1:
$ curl -v telnet://my-web-0.my-web:8080
Connected to my-web-0.my-web (10.1.0.246) port 8080 (#0)
web.xml contains:
<distributable />
Anything else needed for tomcat cluster to work in k8s?