Singleton Service
- Overview: Singleton Pattern ensures only one instance of an application is active at a time and is highly available
- Problem:
- In some cases only one instance of the service is allowed to run
- Solution:
- Out of Application Locking:
- Stateful set or replicat set with replicas = 1
- In-Application Locking
- In a distribute environment one way to control the service instance count is through a distributed lock
- We can implement leader election using kubernetes api’s. For example apache camel has a K8s connector that also provides leader election and Singleton capabilities
- This connector access the etcd api directly and k8s api to use Config Maps to acquire a distributed lock Refer Here
- Refer Here for sample leader election in k8s.
- Out of Application Locking:
DNS For Services and Pods
- Refer Here for the manifests used

- Lets create the test pod

- Make a note of service names and ip addresses of pods

- Now login into test pod
kubectl exec -it test -- /bin/sh
-
Look into resolve.conf

-
What objects in k8s gets DNS records
- Services
- Pods
-
Refer Here for the K8s DNS Based Service Discovery
-
DNS A record Refer Here
-
DNS CNAME Refer Here
-
DNS SRV Refer Here
-
K8s Services:
- A/AAAA records
- Normal Services are assigned a DNS A record depending on the IP family of the service for the name in the form of
my-svc.my-namespace.svc.cluster-domain.example
- Normal Services are assigned a DNS A record depending on the IP family of the service for the name in the form of
- SRV records:
- SRV records are created for each named ports that are part of normal or Headless Services. For each name port the SRV record would have the form
_my-port-name._my-port-protocol.my-svc.my-namespace.svc.cluster.local
- SRV records are created for each named ports that are part of normal or Headless Services. For each name port the SRV record would have the form
- A/AAAA records
-
K8S Pods
- A/AAAA records:
- Pod has the following dns resolution
pod-ip-address.my-namespace.pod.cluster.local
- A/AAAA records:
-
In kubernetes in addition to DNS records k8s create environmental variables with service information

