i want a daemonset-redis where every node will have it's own caching and each deployment pod will communicate with it's local daemonset-redis how to achieve it? how to reference daemonset pod in the same node from within docker-container?
UPDATE: i rather not use service option and make sure each pod access its local daemonset
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: redislocal
spec:
selector:
matchLabels:
name: redislocal
template:
metadata:
labels:
name: redislocal
spec:
hostNetwork: true
containers:
- name: redislocal
image: redis:5.0.5-alpine
ports:
- containerPort: 6379
hostPort: 6379
A Pod can communicate with another Pod by directly addressing its IP address, but the recommended way is to use Services. A Service is a set of Pods, which can be reached by a single, fixed DNS name or IP address. In reality, most applications on Kubernetes use Services as a way to communicate with each other.
Kubernetes assumes that pods can communicate with other pods, regardless of which host they land on. Kubernetes gives every pod its own cluster-private IP address, so you do not need to explicitly create links between pods or map container ports to host ports.
Communicating with a DaemonSetSpecify hostPort in the DaemonSet's pod spec to expose it on the node. You can then communicate with it directly by using the IP of the node it is running on. Create a service with the same pod selector as the DaemonSet and then use the service to reach your DaemonSet.
Pods on a node can communicate with all pods on all nodes without NAT. Agents on a node (system daemons, kubelet) can communicate with all the pods on that specific node.
There is a way of not using a service
.
You can Expose Pod Information to Containers Through Environment Variables.
And you can use status.hostIP
to know the ip address of node where pod
is running.
This was introduced in Kubernetes 1.7 link
You can add that to your pod
or deployment
yaml:
env:
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
It will set an variable HOST_IP
which will have a value of node ip on which the pod
is running, then you can use it to connect to a local DeamonSet
.
you should define a service ( selecting all redis pods ) and then communicate with redis from other pods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With