Run docker container on k3s-agent from k3s-master

3k views Asked by At

I made one k3s-master on ubuntu 20 and one k3s-agent on another ubuntu 20. I have both system connected to same network.I have docker image on k3s-agent, I can able to run the container on k3s-agent.I created one cluster and k3s-agent and k3s-master both are connected to cluster. I checked with kubectl get nodes command on master and I can see agent and master are listed.

I need help on following points. I want to run docker image on k3s-agent from k3s-master. Is there any way to run docker image on agent from master ?

I came to know that I can make pod and using pod I can do that. but pod is not working out.

3

There are 3 answers

0
DRPandya On BEST ANSWER

There are two things we can do.

  1. nodeName,

Just mention the nodeName: mynode1 in yaml file.

  1. taints and toleration

We can set Taints and Toleration inside pod`s yaml file. Example below.

set Taints to node like this

kubectl taint nodes mynode1 app=Device:NoSchedule

and we can toleration in yaml file as below.

apiVersion: v1
kind: Pod
metadata:
  name: scriptpod
spec:
  containers:
    - name: scriptdo
      image: scriptdo
      imagePullPolicy: Always
nodeName: mynode1
restartPolicy: Always
tolerations:
- key: "app"
  operator: "Equal"
  value: "Device"
  effect: "NoSchedule"

Document for taints and toleration

Note:- I set nodeName and taints and toleration both, cause nodeName not worked in rare case.

1
Emre Odabaş On

If I did not misunderstand, you could simply deliver your docker image with kubectl command like; kubectl run my-pod --image=your-image ...

If you desire to run pods on the agent-side then you could use taint and toleration abilities to match pods and nodes.

0
J Pod On

One option to run a docker image on your agent node is that you can build the image locally on that node. Once it is built, you can set the imagePullPolicy: Never so it will try to grab it from the agent's local docker registry.

 spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: <label key>
                operator: In
                values:
                  - <agent label> 
  containers:
    - name: <container name>
      image: <image name>
      imagePullPolicy: Never