Detail
Lets assume this sample YAML:
apiVersion: asdb.aerospike.com/v1beta1
kind: AerospikeCluster
metadata:
name: aerocluster
namespace: aerospike
spec:
size: 2
image: aerospike/aerospike-server-enterprise:6.2.0.3
storage:
volumes:
- name: workdir
aerospike:
path: /opt/aerospike
source:
persistentVolume:
storageClass: gp2
volumeMode: Filesystem
size: 1Gi
- name: test
aerospike:
path: /aerospike/dev/xvdf_test
source:
persistentVolume:
storageClass: gp2
volumeMode: Block
size: 5Gi
- name: aerospike-config-secret
source:
secret:
secretName: aerospike-secret
aerospike:
path: /etc/aerospike/secret
podSpec:
multiPodPerHost: false
rackConfig:
namespaces:
- test
racks:
- id: 1
- id: 2
aerospikeAccessControl:
users:
- name: admin
secretName: auth-secret
roles:
- sys-admin
- user-admin
- read-write
aerospikeConfig:
service:
feature-key-file: /etc/aerospike/secret/features.conf
security: {}
network:
service:
port: 3000
fabric:
port: 3001
heartbeat:
port: 3002
namespaces:
- name: test
memory-size: 3000000000
replication-factor: 2
storage-engine:
type: device
devices:
- /aerospike/dev/xvdf_test
Answer
Our AerospikeCluster name is defined by the metadata.name field:
kind: AerospikeCluster metadata: name: aerocluster
If using rack-aware, like we are in the YAML, then each rack will be created in its own statefulset. If racks are not defined then the default behavior will be a single rack of rack 0.
rackConfig:
namespaces:
- test
racks:
- id: 1
- id: 2
$ kubectl get statefulset -n aerospike NAME READY AGE statefulset.apps/aerocluster-1 1/1 2d18h statefulset.apps/aerocluster-2 1/1 2d18h
By design, each Pod in the StatefulSet will be assigned an integer ordinal, that is unique over the Set. By default, pods will be assigned ordinals from 0 up through N-1.
Putting this together we would have the following for a pod name:
Cluster Name + Rack ID + pod integer ordinal aerocluster + 1 + 0 (first pod in statefulset)
$ kubectl get pods -n aerospike NAME READY STATUS RESTARTS AGE pod/aerocluster-1-0 2/2 Running 0 2d18h pod/aerocluster-2-0 2/2 Running 0 2d18h
If we want to access the pod by its hostname through DNS we can take this a step further. Kubernetes will assign DNS records to services and pods with the following schemas:
<pod_name>.<service> <pod_name>.<service>.<namespace>or the FQDN internally
<pod_name>.<service>.<namespace>.svc.cluster.local
By default, AKO will create the service name using the cluster name in the metadata.name field of the YAML if multiPodPerHost=false.
$ kubectl get service -n aerospike NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/aerocluster ClusterIP None <none> 3000/TCP 2d18h
Translating this to our examples above would have the following resolvable hostnames for our aerocluster-1-0 pod:
aerocluster-1-0.aerocluster aerocluster-1-0.aerocluster.aerospike aerocluster-1-0.aerocluster.aerospike.svc.cluster.local
Notes
Additional details of StatefulSets and DNS in kubernetes can be found here:- https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-identity
- https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/