Tuesday, March 26, 2024

Difference between cluster, pod, container and node in Kubernete

Container is a place that a program can be deployed and executed, it has all the dependent runtime libraries. Docker is a good candidate to work as a container in order to hold a program and run from there. In jenkensfile, container is specified under containers section, each container in pad is specified with containerTemplate method. 

Pod contains one or more containers. Pods are smallest deployable unit in Kubernetes, all containers within a pod share the storage, network resource. In jenkinsfile, pod is represented with podTemplate method.

Cluster holds and manages pods, the pods within a cluster can be grouped based on namespace.

Node means the computer machines, either physical or virtual machines, that host the pods. In jenkins file, node is specified with node method, the label parameter specifies the node machine's name.

Monday, March 25, 2024

Understanding jenkinsfile, Dockerfile, and deployment YAML files

JenkinsFile is loaded and called by jenkins server for build and deployment. Ths code in this file will run in the default jnlp container.

The podTemplate method defined in Jenkins file specifies multiple container's with name and image id. Inside the podTemplate method, it can access git commit and branch info through scmInof.GIT_COMMIT and scmInof.GIT_BRANCH.

You can define multiple steps for build and deployment by calling stage method with their unique name, if a stage succeeds, it will run the next one. If a stage fails, it will abort the jenkins file execution. Within each stage method implementation, call container () method with name parameter to indicate which container should run the code, 

In one step, the stage method is called on nodejs container to build the project

In one following step, the stage method is called on docker container to build the docker image, which will use the Dockerfile, it then tags docker image, and push it to docker registration.

After the docker image is published, then a new stage method can run in kubectl container to apply the infrastructure yaml file defined for each deployment, within the deployment yaml file, it specifies the docker image id which is published in previous step, and create a new container image for its service.


Please refer to the below link for more details

https://www.jenkins.io/doc/pipeline/steps/kubernetes/