Deploy axon server on Kubernates - springboot microservices

Hi everyone
I’m developing a microservices project where I have to implement the saga pattern with axon server, and I have to deploy them on kubernates (minikube)

Trying to launch microservices plus axon servers with docker-compose they manage to connect and communicate correctly

Instead, trying to deploy everything with kubernates, when starting the spring boot applications I always get the following error, and I can’t get out of it:

here is the piece of code of the kubernates yaml involving axon server:

  • apiVersion: v1
    kind: Service
    metadata:
    name: axonserver-gui
    labels:
    app: axonserver
    spec:
    ports:
    • name: gui
      port: 8024
      targetPort: 8024
      selector:
      app: axonserver
      type: LoadBalancer
      sessionAffinity: ClientIP
  • apiVersion: apps/v1
    kind: Deployment
    metadata:
    annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --out provay.yaml
    kompose.version: 1.21.0 (992df58d8)
    creationTimestamp: null
    labels:
    io.kompose.service: axonserver
    name: axonserver
    spec:
    replicas: 1
    selector:
    matchLabels:
    io.kompose.service: axonserver
    strategy: {}
    template:
    metadata:
    annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --out provay.yaml
    kompose.version: 1.21.0 (992df58d8)
    creationTimestamp: null
    labels:
    io.kompose.service: axonserver
    spec:
    containers:
    - image: axoniq/axonserver
    imagePullPolicy: “”
    name: axon-server
    ports:
    - containerPort: 8124
    - containerPort: 8024
    resources: {}
    restartPolicy: Always
    serviceAccountName: “”
    volumes: null
    status: {}
  • apiVersion: v1
    kind: Service
    metadata:
    name: axonserver-grpc
    labels:
    app: axonserver
    spec:
    ports:
    • name: grpc
      port: 8124
      targetPort: 8124
      clusterIP: None
      selector:
      app: axonserver

There are a number of issues with the Kubernetes YAML file for Axon Server you included here.
First of all, the Axon Server component should be a stateful set instead of a deployment. This is because it should have a predictable hostname. Also, it should map directories to persistent volumes, so that on the restart of the pod the data is not lost.
Secondly, the selectors for the axonserver-grpc and the axonserver-ui are incorrect, these should be “io.kompose.service: axonserver” (same as the label for the AxonServer stateful set).
If this is set up like this, the client application can access Axon Server with hostname axonserver-0.axonserver..svc.cluster.local. You can configure the Axon Server address for the clients by setting the environment variable AXON_AXONSERVER_SERVERS .

For more information on running Axon Server with Kubernetes see: https://developer.axoniq.io/w/running-axon-server-in-docker-continuing-from-local-developer-install-to-containerized