k8smaster server works like a worker

I deploy my Spring projects to Kubernetes with Jenkins. I have k8smaster and 3 worker servers. It sometimes writes .m2 files under the k8smaster server. How can I prevent this? So I want it to write only on worker servers.

kubernetes nodes

enter image description here

I defined a label with a special name in Jenkins so that the job does not run on the master server, but it still works like a worker. enter image description here enter image description here

Jenkins List of volumes to mount in agent pod enter image description here

Pod Template Settings enter image description here

Example pipeline

node ("zrgl-label") {
        withCredentials([gitUsernamePassword(credentialsId: 'zrgl.jenkins')]){
            sh 'git clone -b ..'
    stage('Kubernetes Deployment'){


  • If you want your .m2 files only to be written or created on worker nodes you can follow one of the below ways

    1. You can use taint if you want it for the service not to be scheduled to the K8s master node.

    You add a taint to a node using kubectl taint.

    kubectl taint nodes node1 key1=value1:NoSchedule

    2. You can use node selectors on pods and labels on nodes to control where the pod is scheduled. Here you can either choose to not schedule pods on master nodes or have two different versions of the same application, one which will create .m2 files and one which doesn't use a node selector and distribute your pods accordingly on both master and worker nodes.

    Node selectors can be used to place specific pods on designated nodes; cluster-wide node selectors can be used to place new pods on designated nodes anywhere in the cluster; and project node selectors can be used to place new pods on designated nodes within a project.

    For further readings refer to this official doc 1 and doc 2