0

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 />

Added the following to conf/logging.properties

org.apache.catalina.ha.session.level = FINE

But no more logging emitted.

The source code https://github.com/apache/tomcat/blob/main/java/org/apache/catalina/tribes/membership/cloud/CloudMembershipService.java

contains debug-level logging code like:

        if (log.isDebugEnabled()) {
            log.debug("Using membershipProvider: " + provider);
        }
eastwater
  • 4,624
  • 9
  • 49
  • 118
  • 1
    Note: `org.apache.catalina.ha.session` (the package you configure for log output) is different from `org.apache.catalina.tribes.membership.cloud` (the package that you reference to have a debug log statement) – Olaf Kock Jun 03 '23 at 20:07
  • FINE messages emitted after changing the logging package name. namespace tomcat is used for URL https://10.96.0.1:443/api/v1/namespaces/tomcat/pods. How to use a custom namespace such as my-namespace? thanks. – eastwater Jun 04 '23 at 01:35

0 Answers0