# Docker & Kubernetes introduction (CARTA) - Docker -- Container key features -- Container versus Virtual Machine(VM) -- Basic command line -- CARTA CI/CD - Kubernetes (k8S) -- Official definition -- What problems does k8S solve? -- What k8S offer? -- Basic four components ## Docker Docker is a set of platform as a service (PaaS) products that use **OS-level virtualization** (e.g. Linux kernel namespace) to deliver software in packages called **containers**. Docker is a tool that is used to automate the deployment of applications in lightweight containers so that applications can work efficiently in different environments in isolation. #### Container key features - Consider as individual OS-level virtualization - Containers sharing the same Linux kernel - Each Container is isolated process - light-weight, can run several containers simultaneously. - Easy to deploy #### Container versus Virtual Machine(VM) ![Screen Shot 2024-05-08 at 3.57.12 PM](https://hackmd.io/_uploads/SykOlndzC.png) <span style="background-color: #FFFF00"> **MacOS Docker can have Ubuntu Linux kernel, however Linux kernel does not have MacOSX kernel. This is the main reason that our MacOS CARTA CI/CD are all native (MacOS11: acdcs-Mac-Pro; MacOS12: alm1ac; MacOS13: almac)** </span> **Official Docker image (e.g. ubuntu and centos) can be found in the [docker hub](https://hub.docker.com/)** #### Basic command line 1. We must have **Dockerfile**, we have Dockerfile in our CARTA backend repository ([link](https://github.com/CARTAvis/carta-backend/tree/dev/Dockerfiles)) 2. Using the Dockerfile to build the **image** ```bash= ## For example: I am building Ubuntu20.04 from Dockerfile and giving a tag: mylin/carta-ubunutu20.04:v1 docker build -f Dockerfile-ubuntu-20.04 . --tag mylin/carta-ubunutu20.04:v1 ``` 3. Check the image list ```bash= docker images ls ``` ![Screen Shot 2024-05-08 at 5.18.57 PM](https://hackmd.io/_uploads/ryG9X6uGA.png) 4. Using the image to build the container ```bash= docker run -itd -v $PWD:/mount -p 3002:3002 --name carta-ubunutu20.04 mylin/carta-ubunutu20.04:v1 ``` 6. Check the container list ```bash= docker ps -a ``` ![Screen Shot 2024-05-08 at 5.18.41 PM](https://hackmd.io/_uploads/SyFcXT_MC.png) 7. Access the container ```bash= docker exec -it [CONTAINER ID, e.g. 2d64a179fe94] bash ``` #### CARTA CI/CD We **used** Jankins blue-ocean plugin to run the carta CI/CD pipeline on the server (Linux in the containers and MacOS are native). (Now is removed from our project) ![Screen Shot 2024-05-09 at 1.41.49 PM](https://hackmd.io/_uploads/BkUwfyqG0.png) Now CI/CD pipelines are using **Apptainer (formerly Signularity)** with github action from Dec 2023. It is very similar to Docker but the command lines are slightly different. * Dockerfile <-> ubuntu-2004-dec2023.def (under cartaviewer server `/home/acdc/apptainer`) * Container <-> ubuntu-2004-dec2023.sif Using the *.def to build the latest version of *.sif ```bash= apptainer build testing.sif ubuntu-2004-dec2023.def ``` * [Docker]`docker image ls` <-> [Signularity]`ls *.sif` * [Docker]`docker ps -a` <-> [Signularity]`singularity instance list` * [Docker]`docker exec -it [CONTAINER ID] bash` <-> [Signularity]`apptainer shell instance://[INSTANCE NAME]` ## Kubernetes Motivation: Why Heng-tai implemented k8s in the carta-backend ICD tests ([link](https://github.com/CARTAvis/carta-backend-ICD-test/tree/master/k8s)) [Youtube k8S Reference](https://www.youtube.com/watch?v=s_o8dwzRlu4) [Game article Reference](https://medium.com/my-games-company/no-need-to-pause-how-we-update-games-without-downtime-7ebcff1ce813) #### Official definition * Open source container orchestration framework(tool) * Developed by Google * Managing containerized applications in different deployment environments(e.g. physical machine, virtual machine, cloud, etc.) #### What problems does K8S solve? * Services (contains serveral applications) from Monolith to microservices (small and independent) * Increased usage of containers * A proper way to manage those containers #### What k8S offer? * High avaliability (aka NO downtime), for example: the game services (Love and Deepspace from China 2024) offer the version update without downtime. Or Cisco offers high avaliability services ([link](https://www.cisco.com/c/en/us/solutions/hybrid-work/what-is-high-availability.html)) * Scalability or high performance (many users means high pressure data load) * Disaster recovery: backup and restore (e.g. self healing) #### Basic four components ([official website](https://kubernetes.io/docs/concepts/overview/components/)) * cluster > When you deploy Kubernetes, you get a cluster. * node(s) > A Kubernetes cluster consists of a set of worker machines, called nodes, that run containerized applications. Every cluster has at least one worker node. * pod(s) > The worker node(s) host the Pods that are the components of the application workload. * control plane (aka master node) > The control plane manages the worker nodes and the Pods in the cluster. In production environments, the control plane usually runs across multiple computers and a cluster usually runs multiple nodes, providing fault-tolerance and high availability. ![image-1](https://hackmd.io/_uploads/ryX7U7tG0.png)