Skip to main content
By default, all containers within a Kubernetes Pod share the same filesystem. In this tutorial, we’ll demonstrate how to create a file in an Ubuntu container and then read it from a Node.js container within the same Pod using a Jenkins pipeline.
Containers in the same Pod share volumes and file systems, allowing seamless data exchange without additional configuration.

Jenkins Pipeline Configuration

Paste the following pipeline definition into your Jenkinsfile to set up two containers—ubuntu-container and node-container—in a single Pod:

Pipeline in Action

Once you commit and run this pipeline, Jenkins will create the Pod and execute both stages. The Ubuntu container writes ubuntu-$BUILD_ID.txt, and the Node.js container reads it immediately afterward.
The image shows a Jenkins dashboard displaying the status of a pipeline named "k8s-cloud-agent-demo," with several stages and their execution results.
According to the Kubernetes Pod Lifecycle documentation, all containers in a Pod can share volumes and files.
The image is a screenshot from the Kubernetes documentation website, showing a diagram of a multi-container Pod with a file puller sidecar, a web server, and a shared volume.

Console Output Example

Below is an excerpt from the Jenkins console log illustrating how the file is shared between containers:

Comparing Jenkins Agent Strategies

Choose the right Jenkins agent model based on your infrastructure and maintenance requirements:
Agent TypeDescription
Kubernetes Cloud AgentOn-demand Pods; auto-provisioned and cleaned up per job.
Docker AgentTemporary containers managed by Jenkins; easy to customize.
Static NodeAlways-on VMs or servers; requires manual OS and tool updates.
Static nodes demand ongoing maintenance (OS patches, software upgrades). For most CI/CD workflows, dynamic agents reduce resource waste and simplify updates.

Watch Video