Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to communicate with daemonset pod from another pod in the same node?

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

like image 556
Oren Lalezari Avatar asked Jun 12 '19 13:06

Oren Lalezari


People also ask

How does the pod communicate with another pod?

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.

Can 2 pods communicate in Kubernetes?

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.

How do you communicate with DaemonSet?

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.

Can pods in different nodes communicate?

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.


2 Answers

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.

like image 65
Crou Avatar answered Oct 08 '22 20:10

Crou


you should define a service ( selecting all redis pods ) and then communicate with redis from other pods

like image 2
P Ekambaram Avatar answered Oct 08 '22 21:10

P Ekambaram