How to configure axon server in pod for Kubernetes

9/17/2019

I have 3 services which are axon, command and query. I am trying running them via Kubernetes. With docker-compose and swarm works perfectly. But somehow not working via K8s. Getting following error:

Connecting to AxonServer node axonserver:8124 failed: UNAVAILABLE: Unable to resolve host axonserver Below are my config files.

 `
  apiVersion: apps/v1
  kind: StatefulSet
  metadata:
    name: axonserver
    labels:
      app: axonserver
  spec:
    serviceName: axonserver
    replicas: 1
    selector:
      matchLabels:
        app: axonserver
    template:
      metadata:
        labels:
          app: axonserver
      spec:
        containers:
          - name: axonserver
            image: axoniq/axonserver
            env:
            - name: AXONSERVER_HOSTNAME
             value: axonserver
            imagePullPolicy: Always
            ports:
            - name: grpc
              containerPort: 8124
              protocol: TCP
            - name: gui
              containerPort: 8024
              protocol: TCP

`

Here is command-service yaml contains service as well.

  apiVersion: 
  kind: Pod
  metadata:
    name: command-service
    labels:
      name: peanuts
      app: axonserver
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          app: axonserver
      spec:
        containers:
        - image: celcin/command-svc
          name: command-service
          ports:
          - containerPort: 8080
          restartPolicy: Always
        status: {}
   ---
   apiVersion: v1 
   kind: Service
   metadata:
     name: command-service
       labels:
         name: peanuts
         app: axonserver
   spec:
     ports:
     - name: "8081"
       port: 8081
       targetPort: 8080
     selector:
       labels:
         app: axonserver

`

Here is last service as query-service yml file

 ` apiVersion: v1
   kind: Pod
   metadata:
     name: query-service
     labels:
       name: peanuts
       app: axonserver
   spec:
     replicas: 1
       template:
       metadata:
         labels:
           app: axonserver
       spec:
         containers:
         - image: celcin/query-svc
           name: query-service
           ports:
           - containerPort: 8080
         restartPolicy: Always
       ---
   apiVersion: v1
   kind: Service
   metadata:
     name: query-service
     labels:
       name: peanuts
       app: axonserver
   spec:
     ports:
     - name: "8082"
       port: 8082
       targetPort: 8080
     selector:
       labels:
         app: axonserver`
--
axon
kubernetes

1 Answer

9/18/2019

your YAML is somehow mixed. If I understood you correctly, you have three services:

  • command-service
  • query-service
  • axonserver

Your setup should be configured in a way that command-service and query-service expose their ports, but both use ports exposed by axonserver. Here is my attempt for your YAML:

 apiVersion: apps/v1
 kind: StatefulSet
 metadata:
   name: axonserver
   labels:
     app: axonserver
 spec:
   serviceName: axonserver
   replicas: 1
   selector:
     matchLabels:
       app: axonserver
   template:
     metadata:
       labels:
         app: axonserver
     spec:
       containers:
         - name: axonserver
           image: axoniq/axonserver
           imagePullPolicy: Always
         - name: grpc
           containerPort: 8124
           protocol: TCP
         - name: gui
           containerPort: 8024
           protocol: TCP

The ports your defined in:

       ports:
         - name: command-srv
           containerPort: 8081
           protocol: TCP
         - name: query-srv
           containerPort: 8082
           protocol: TCP 

are not ports of Axon Server, but of your command-service and query-service and should be exposed in those containers.

Kind regards,

Simon

-- Simon Zambrovski
Source: StackOverflow