Deploying Identical Pods on Different Nodes

I have a cluster with two nodes. On the first node, I’ve successfully deployed a simple json logger which spits out json messages. I’d like to deploy an identical logger on the second node. Name, image, etc all identical. I’ve tried modifying a yaml file to no avail and was wondering if there was a way I could, when I run the command ‘kubectl run jsonlogger’, run that pod on a specific node. Is there a command like ‘kubectl run jsonlogger --node=node_name_1’?


Sounds like you’re aiming to make a DaemonSet.

You can set the nodeSelector field in the Pod spec to node_name_1

Yep. It’s pretty obscure really, like I feel like this is a very buried piece of information but here it is. That page is good to know to refer to when you’re developing pods.

    - env:
        - name: MY_NODE_NAME
              fieldPath: spec.nodeName

Thanks for your reply! I’m a little stumped here though. I’m trying to incorporate that code but am running into an error that says “error: error parsing node.yaml: error converting YAML to JSON: yaml: line 10: did not find expected key.”

This is my yaml file:

apiVersion: v1
kind: Pod
  name: jsonlogger
    env: test
    - name:
      image: sikwan/random-json-logger
      - env:
          - name: jsonlogger
                fieldPath: jsonlogger

I’m not sure what I’m missing here, but the above code doesn’t give me the desired outcome of making an exact duplicate container of one I already have running.Thanks for your help!

Sorry, looking at my prior post, I forgot to put in what the thing does and what you probably should look into.

The shortest answer is pretty messy imo.

kubectl run jsonlogger --overrides='{ "apiVersion": "v1", "spec": { "nodeSelector": { "": "node-name-here" } } }'

More on assigning pods to nodes here.

Managing pods via the command line though is rarely good in practical applications though.

If you’re doing logging per-node on all of your nodes, DaemonSets makes that easy.

To make DaemonSets effective, you probably want the node name to be exposed. This section specifically shows an example of exposting that.