13

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

Oren Lalezari
  • 185
  • 2
  • 8

2 Answers2

20

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.

Crou
  • 10,232
  • 2
  • 26
  • 31
2

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

P Ekambaram
  • 15,499
  • 7
  • 34
  • 59
  • I also think this is the solution, but will pods strictly communicate with the local deamon? Do services provide that guarantee? – Alassane Ndiaye Jun 12 '19 at 14:19
  • i rather not use a service. i think theres another way i hoped to get that answer with accessing the node on which the pods are running with some kind of alias – Oren Lalezari Jun 12 '19 at 15:30