├── .vscode └── settings.json ├── 00-git ├── 01-understand-git.md ├── 02-git-command-list.md ├── 03-git-add.md ├── 04-git-merge.md ├── 05-git-remote-add.md ├── 06-git-pull.md ├── 07-git-push.md ├── 08-git-log-diff.md ├── 10-git-block-command.md └── images │ └── git.png ├── 00-kubernetes ├── 01-kubelet.md ├── 02-kubelet-tasks.md ├── 03-kubelet-importants.md ├── 04-minikube-command-list.md ├── 05-expose-versus-port-forward.md ├── 06-kubectl-expose-various-service-type.md └── metric-important │ ├── code │ └── components.yaml │ └── kubectl-top-nodes.md ├── 00-step-by-step-environment-intallation-on-codespace.md ├── 00-windows-shot-path.md ├── 000-markdown ├── 02-markdown-command-list.md └── markdown-list.md ├── 000-mermaid ├── 01-chart-language.md ├── 02-flowchart-element-list.md ├── 03-sequence-diagram-element-list.md ├── 04-timeline.md └── images │ ├── flowchat-sample.png │ ├── project-plan.png │ ├── sequence-diagram.png │ └── timeline.png ├── 01-pod ├── 01-what-is-pods.md ├── 02-how-to-create-a-pod.md ├── 03-multi-tenance.md ├── 04-how-to-install-developer-app-into-pod.md ├── 05-hot-to-install-multi-container-into-pod.md ├── 06-how-to-update-old-pod-to-new-pod.md ├── 07-ports-information.md ├── 08-port-types.md ├── 80-how-to-crate-a-container-and-push-hub-docker-com.md ├── code-flask │ ├── Dockerfile │ ├── hello-world-deployment.yaml │ ├── hello-world.py │ └── requirements.txt ├── code │ ├── multi-container-mounted-same-log.yaml │ ├── multi-container-pod.yaml │ ├── my-nginx-pod.yaml │ └── my-pods-limited.yaml └── docker-container-id.md ├── 02-node └── 01-node-command.md ├── 03-kubelet ├── 01-kubelet.md ├── 02-kube-proxy.md ├── 03-kubelet-logs.md ├── 04-kubelet-status-start-stop.md └── kubelet-command-list.md ├── 04-service └── 01-service-command.md ├── 05-deployment └── deployment-command.md ├── 06-replicaset └── 01-command-list.md ├── 07-namespaces ├── 01-command-list.md └── namespaces.md ├── 08-configmap └── 01-command-list.md ├── 09-secret └── 01-command-list.md ├── 10-docker-environment-update.md ├── 10-volume └── 01-command-list.md ├── 100-kubernetes-objects.md ├── 101-kubernetes-objects-all.md ├── 11-job └── 01-command-list.md ├── 11-minikube-status.md ├── 12-cronjob └── 01-command-list.md ├── 13-loadbalancer └── 01-command-list.md ├── 14-ingress └── 01-command-list.md ├── 15-persistenentvolume └── 01-command-list.md ├── 16-persistenentvolumeclaim └── 014-command-list.md ├── 17-StatefulSet ├── 01-command-list.md └── 02-step-by-step.md ├── 18-deamonset └── 01-command-list.md ├── 19-hpa └── 01-command-list.md ├── 20-clusterip └── 01-command-list.md ├── 20-docker-version-check_minikube-install.md ├── 21-kubectl-get-pods-show-error.md ├── 21-nodeport └── 01-command-list.md ├── 22-etcd └── 01-command-list.md ├── 23-port-type ├── 00-port-types.md ├── container-port.md ├── different-application-scenarios.md ├── host-port.md ├── ingress-port.md ├── loadbalancer-node.md ├── nodeport.md └── service-port.md ├── 30-minikube -commands.md ├── 31-why-use-minikube.md ├── 32-kubernetes-addons.md ├── 33-minikube-config-view-status.md ├── 34-minikube-in-commands.md ├── 35-linux-command.md ├── 40-kubectl-commands.md ├── 50-pyhton-flesk-expose-deploy.md ├── 51-check-environment-curl-nodeport.md ├── 52-python-flesk-publish-error.md ├── 53-codespace-stoped-restart-minikube.md ├── 80-practice ├── 01 │ ├── 01-create-a-container.md │ ├── Dockerfile │ └── html │ │ └── index.html ├── 02 │ ├── 01-create-a-container.md │ ├── Dockerfile │ ├── html │ │ └── index.html │ └── nginx.conf ├── 03 │ └── 01-hub-upload.md ├── 04 │ ├── 01-create-pod.md │ └── code │ │ ├── nginx-pod.yaml │ │ ├── nginx-service-2.yaml │ │ ├── nginx-service.yaml │ │ └── nginx.conf └── 05 │ ├── code │ ├── deployment.yaml │ ├── ingress.yaml │ └── service.yaml │ └── reamde.md ├── 90-works-with-sbm └── 01 │ ├── Dockerfile │ ├── html │ └── index.html │ └── nginx.conf ├── README.md ├── demon ├── 01-command-list.md └── demonaset.md ├── images ├── kubernetes.drawio.png ├── minikube-start-error.png └── my-app-image-on-docker-io.png ├── minikube-linux-amd64 ├── my-python-app ├── Dockerfile ├── app.py ├── deployment.yaml ├── logs.txt └── requirements.txt └── service.yaml /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "DockerRun.DisableDockerrc": true 3 | } -------------------------------------------------------------------------------- /00-git/01-understand-git.md: -------------------------------------------------------------------------------- 1 | # Git 2 | 3 | ![](./images/git.png) 4 | 5 | Git is a distributed version control system used to track and manage changes in software development projects. The basic workflow of Git involves transitioning changes between the **working directory**, **staging area**, and **local repository**. Here’s a detailed explanation of Git’s stages and processes: 6 | 7 | ## 1. **Working Directory** 8 | 9 | - The **working directory** is the folder on your local machine where your project files reside. When you create a Git repository or clone an existing one, all files are placed in the working directory. 10 | - When you make changes to files in this directory, Git tracks them, but these changes aren’t yet ready to be committed. 11 | 12 | ## 2. **Staging Area** 13 | 14 | - The **staging area** (also called the **index**) is where you prepare changes before committing them. When you modify files in the working directory and want to include those changes in the next commit, you need to add them to the staging area. 15 | - Use the `git add` command to move changes from the working directory to the staging area. 16 | 17 | ```bash 18 | git add # Adds a specific file to the staging area 19 | git add . # Adds all changes in the working directory to the staging area 20 | ``` 21 | 22 | - The files in the staging area are now ready to be committed to the repository. 23 | 24 | ## 3. **Commit (Saving Changes to Local Repository)** 25 | 26 | - A **commit** is a snapshot of the project at a specific point in time. It records the changes that were staged. 27 | - To commit the changes, use the `git commit` command. You will also need to include a message describing the changes made. 28 | 29 | ```bash 30 | git commit -m "Commit message describing the changes" 31 | ``` 32 | 33 | - This command permanently saves the changes to your **local repository**. 34 | 35 | ## 4. **Viewing the Commit History** 36 | 37 | - To view the history of commits, you can use the `git log` command. This shows a list of all commits, including the hash, author, date, and commit message. 38 | 39 | ```bash 40 | git log 41 | ``` 42 | 43 | ## 5. **Pushing to a Remote Repository** 44 | 45 | - Git allows you to share your changes with others by pushing them to a **remote repository**, typically hosted on services like GitHub, GitLab, or Bitbucket. 46 | - After committing your changes locally, use the `git push` command to upload them to the remote repository. 47 | 48 | ```bash 49 | git push origin main # Pushes changes to the main branch on the remote repository 50 | ``` 51 | 52 | ## 6. **Pulling Updates from the Remote Repository** 53 | 54 | - To bring changes from a remote repository to your local one, you can use two main commands: 55 | - `git fetch`: Downloads changes from the remote repository but does not apply them to your working directory. 56 | - `git pull`: Downloads and applies the changes to your working directory, combining the fetch and merge steps. 57 | 58 | ```bash 59 | git pull origin main 60 | ``` 61 | 62 | ## 7. **Working with Branches** 63 | 64 | - **Branches** are used to work on different features or fixes independently from the main codebase. This allows multiple people to work on different parts of the project simultaneously without interfering with each other. 65 | - To create a new branch: 66 | 67 | ```bash 68 | git branch 69 | ``` 70 | 71 | - To switch between branches: 72 | 73 | ```bash 74 | git checkout 75 | ``` 76 | 77 | - To merge changes from one branch into another: 78 | 79 | ```bash 80 | git merge 81 | ``` 82 | 83 | ## 8. **Handling Merge Conflicts** 84 | 85 | - Sometimes, when merging changes from different branches, you may encounter **merge conflicts** if the same part of a file was edited in both branches. 86 | - Git will notify you of the conflict and allow you to manually resolve it by editing the file and choosing which changes to keep. Once resolved, you can commit the changes. 87 | 88 | ## 9. **Undoing Changes (Reset, Revert, Checkout)** 89 | 90 | - Git provides several ways to undo changes: 91 | - `git reset`: Moves the HEAD to a previous commit and optionally modifies the staging area and working directory. 92 | - `git revert`: Reverts a specific commit by creating a new commit that undoes the changes from the specified commit. 93 | - `git checkout `: Restores a file to its state from the latest commit. 94 | 95 | ## Git Workflow Summary 96 | 97 | 1. **Work in the Working Directory**: Modify files. 98 | 2. **Stage Changes**: Add files to the staging area using `git add`. 99 | 3. **Commit Changes**: Save the staged changes to the local repository using `git commit`. 100 | 4. **Push Changes**: Send commits to a remote repository with `git push`. 101 | 5. **Pull Changes**: Retrieve and apply changes from the remote repository using `git pull`. 102 | -------------------------------------------------------------------------------- /00-git/02-git-command-list.md: -------------------------------------------------------------------------------- 1 | # Git Command List 2 | 3 | Here’s a table of essential Git commands along with their descriptions: 4 | 5 | | **Command** | **Description** | 6 | |---------------------------|-----------------------------------------------------------------------------------------------------------| 7 | | `git init` | Initializes a new Git repository in the current directory. | 8 | | `git clone ` | Clones an existing repository from a remote server (like GitHub) to your local machine. | 9 | | `git add ` | Adds a specific file to the staging area. | 10 | | `git add .` | Adds all changes (new, modified, deleted files) in the current directory to the staging area. | 11 | | `git commit -m "message"` | Commits staged changes with a message describing the changes. | 12 | | `git status` | Displays the status of the working directory and staging area, showing tracked/untracked changes. | 13 | | `git log` | Displays the commit history for the current branch. | 14 | | `git diff` | Shows the differences between the working directory and the last commit. | 15 | | `git branch` | Lists all branches in the repository. | 16 | | `git branch `| Creates a new branch. | 17 | | `git checkout ` | Switches to the specified branch. | 18 | | `git merge ` | Merges the specified branch into the current branch. | 19 | | `git pull` | Fetches and merges changes from the remote repository to the current branch. | 20 | | `git push` | Pushes committed changes from the local repository to the remote repository. | 21 | | `git fetch` | Downloads changes from the remote repository but doesn’t apply them to the working directory. | 22 | | `git reset` | Resets the current HEAD to a specific state, modifying the index and optionally the working directory. | 23 | | `git revert ` | Reverts a commit by creating a new commit that undoes the changes from the specified commit. | 24 | | `git rm ` | Removes a file from the working directory and stages the removal for the next commit. | 25 | | `git stash` | Temporarily saves changes that aren’t ready to be committed, allowing you to work on other things. | 26 | | `git stash pop` | Applies the most recent stashed changes back to the working directory and removes them from the stash list.| 27 | | `git tag ` | Creates a tag (reference) for a specific commit, often used for releases. | 28 | | `git remote -v` | Displays the URLs of the remote repositories linked to your local repository. | 29 | | `git show ` | Displays information about a specific commit, including changes made in the commit. | 30 | | `git config --global user.name "name"` | Sets the global username for Git commits. | 31 | | `git config --global user.email "email"` | Sets the global email for Git commits. | 32 | 33 | This table covers the most commonly used Git commands, helping you navigate through version control tasks efficiently. -------------------------------------------------------------------------------- /00-git/05-git-remote-add.md: -------------------------------------------------------------------------------- 1 | # Git Remote 2 | 3 | To add a remote repository in Git, you use the `git remote add` command. A **remote** is a version of your project that’s hosted on a server, allowing you to collaborate with others. 4 | 5 | ## Syntax 6 | 7 | ```bash 8 | git remote add 9 | ``` 10 | 11 | - ``: The short name for the remote repository (usually `origin` for the main remote). 12 | - ``: The URL of the remote repository (for example, a GitHub repository URL). 13 | 14 | ## Example 15 | 16 | 1. If you have a GitHub repository with the following URL: 17 | `https://github.com/username/project.git` 18 | 19 | 2. To add it as a remote with the name `origin`, you would run: 20 | 21 | ```bash 22 | git remote add origin https://github.com/username/project.git 23 | ``` 24 | 25 | 3. To check if the remote was added successfully, use: 26 | 27 | ```bash 28 | git remote -v 29 | ``` 30 | 31 | You should see: 32 | 33 | ```bash 34 | origin https://github.com/username/project.git (fetch) 35 | origin https://github.com/username/project.git (push) 36 | ``` 37 | 38 | ## Using the Remote 39 | 40 | After adding the remote, you can push changes to it using the following command: 41 | 42 | ```bash 43 | git push origin 44 | ``` 45 | 46 | For example: 47 | 48 | ```bash 49 | git push origin main 50 | ``` 51 | 52 | This pushes the local `main` branch to the `origin` remote repository. 53 | -------------------------------------------------------------------------------- /00-git/10-git-block-command.md: -------------------------------------------------------------------------------- 1 | # Git Block Command 2 | 3 | ```` 4 | git pull && git add . && git commit -m "cloudspaces copilot commit" && git push && clear 5 | ``` -------------------------------------------------------------------------------- /00-git/images/git.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/00-git/images/git.png -------------------------------------------------------------------------------- /00-kubernetes/01-kubelet.md: -------------------------------------------------------------------------------- 1 | # Kubelet 2 | 3 | **Kubelet** is a critical component in the Kubernetes architecture. It runs on each Kubernetes **node** and is responsible for managing the containers (typically Docker containers) on that node. Here are the key features and functions of Kubelet: 4 | 5 | ## What is Kubelet? 6 | 7 | 1. **Definition**: Kubelet is the node-level component of Kubernetes. It starts, stops, and manages the pods running on the node based on the specifications received from the Kubernetes API. 8 | 9 | 2. **Functionality**: 10 | - **Pod Management**: Kubelet launches, stops, and monitors the status of pods based on the configurations it retrieves from the Kubernetes API. 11 | - **Container Monitoring**: Kubelet checks the health and performance of the containers. It performs health checks to ensure that the containers are operating correctly. 12 | - **Reporting**: Kubelet reports information about resource usage, pod status, and other critical data back to the Kubernetes API. 13 | - **Container Management**: It handles the creation, updating, and deletion of containers. 14 | 15 | ## Is There At Least One Kubelet on Every Node? Why? 16 | 17 | Yes, there is at least one kubelet on every Kubernetes node. The reasons are: 18 | 19 | 1. **Node Management**: Kubelet is essential for the effective operation of the node within the Kubernetes cluster. It must be running to enable the node to communicate with the Kubernetes API and provide information about its status. 20 | 21 | 2. **Pod and Container Management**: Kubelet is necessary for managing the pods and containers on each node. Since it is responsible for ensuring that pods are running in their desired state, it must be present on the node. 22 | 23 | 3. **Foundation of Kubernetes Architecture**: Kubelet is one of the fundamental components of the Kubernetes architecture. To maintain consistency among nodes and ensure the integrity of the cluster, kubelet must exist on every node. 24 | 25 | ## Conclusion 26 | 27 | Kubelet is a critical component for the functioning of a Kubernetes cluster, and it is required on every node. It manages nodes and pods, allowing you to fully leverage Kubernetes's automation and orchestration capabilities. 28 | -------------------------------------------------------------------------------- /00-kubernetes/02-kubelet-tasks.md: -------------------------------------------------------------------------------- 1 | # Kubelet Tasks 2 | 3 | Kubelet is a critical component in the Kubernetes architecture, and it performs several essential functions. Here are the primary responsibilities of kubelet: 4 | 5 | ## Kubelet Responsibilities 6 | 7 | 1. **Pod Management**: 8 | - Kubelet manages the lifecycle of pods that need to run on each node, including starting and stopping them. 9 | - It monitors the state of pods and restarts them if necessary. 10 | 11 | 2. **Container Management**: 12 | - Kubelet oversees the state and management of containers running on the node. 13 | - It handles operations such as starting, stopping, and updating containers. 14 | 15 | 3. **Health Checks**: 16 | - Kubelet regularly performs health checks on pods and containers. 17 | - It evaluates the application’s functioning using health probes (liveness and readiness probes). 18 | 19 | 4. **Node Status Reporting**: 20 | - Kubelet reports the overall status of the node (e.g., available resources) to the Kubernetes API. 21 | - This information is utilized by the Kubernetes control plane to maintain up-to-date knowledge about the node's condition. 22 | 23 | 5. **Communication with the Kubernetes API**: 24 | - Kubelet maintains a continuous communication channel with the Kubernetes control plane. 25 | - It sends requests to the API for pod definitions and updates. 26 | 27 | 6. **Logging**: 28 | - Kubelet maintains detailed logs about the node and pods. 29 | - These logs are essential for troubleshooting and gaining insights into the system's status. 30 | 31 | 7. **Resource Management**: 32 | - Kubelet monitors and manages resources such as CPU and memory. 33 | - It ensures that pods operate within the defined resource limits. 34 | 35 | 8. **Volume Management**: 36 | - Kubelet manages the storage volumes required for pods. 37 | - It handles the creation, attachment, and maintenance of volumes. 38 | 39 | 9. **CGroup Usage**: 40 | - Kubelet utilizes Linux cgroups to limit the resources allocated to containers. 41 | - This ensures fair distribution and monitoring of resources. 42 | 43 | ## Conclusion 44 | 45 | Kubelet is one of the core components of the Kubernetes architecture, functioning on every node to manage pods and containers, monitor node status, and facilitate communication with the Kubernetes API. This enables full utilization of Kubernetes' automation and orchestration capabilities. 46 | -------------------------------------------------------------------------------- /00-kubernetes/03-kubelet-importants.md: -------------------------------------------------------------------------------- 1 | # Kubelet's Most Important Features to Know 2 | 3 | ## 1. **Pod Lifecycle Management** 4 | 5 | - Kubelet is responsible for managing the lifecycle of pods. It ensures that the desired state of the pods is maintained, including starting, stopping, and restarting containers as necessary. 6 | 7 | ## 2. **Node Registration** 8 | 9 | - Kubelet registers the node it is running on with the Kubernetes API server. This registration includes information about the node's resources, such as CPU, memory, and available storage. 10 | 11 | ## 3. **Container Runtime Interface (CRI)** 12 | 13 | - Kubelet uses the Container Runtime Interface to communicate with container runtimes (like Docker, containerd, or CRI-O). This abstraction allows it to manage containers without being tied to a specific runtime. 14 | 15 | ## 4. **Health Checking** 16 | 17 | - Kubelet performs liveness and readiness checks to monitor the health of running containers. If a container fails its health check, Kubelet can restart it to ensure application availability. 18 | 19 | ## 5. **Resource Monitoring and Reporting** 20 | 21 | - Kubelet collects metrics about resource usage (CPU, memory, disk, etc.) from the containers it manages and reports this data back to the Kubernetes API server. This helps in scheduling and resource allocation. 22 | 23 | ## 6. **Configuration and Secrets Management** 24 | 25 | - Kubelet retrieves and manages configuration data and secrets required by the pods. It can inject environment variables or mount configuration files as volumes into the containers. 26 | 27 | ## 7. **Networking and DNS Management** 28 | 29 | - Kubelet handles the networking setup for the pods it manages. It can also manage DNS entries for the pods, ensuring that they can resolve service names correctly. 30 | 31 | ## 8. **Volume Management** 32 | 33 | - Kubelet is responsible for mounting volumes (persistent or ephemeral) to the pods. It ensures that data is accessible to the containers as defined in their specifications. 34 | 35 | ## 9. **Pod Spec Validation** 36 | 37 | - Kubelet validates the pod specifications to ensure they comply with the required configurations and constraints before creating the corresponding containers. 38 | 39 | ## 10. **Event Logging** 40 | 41 | - Kubelet can log events related to the pods and nodes, which can be useful for troubleshooting and monitoring the state of the cluster. 42 | 43 | ## Conclusion 44 | 45 | Kubelet is a critical component of a Kubernetes cluster, managing pods and ensuring that the desired state of applications is maintained. Understanding its features is essential for effectively operating and troubleshooting a Kubernetes environment. 46 | -------------------------------------------------------------------------------- /00-kubernetes/04-minikube-command-list.md: -------------------------------------------------------------------------------- 1 | ### Basic Commands 2 | 3 | 1. **Start Minikube:** 4 | ```bash 5 | minikube start 6 | ``` 7 | Starts a Minikube cluster. 8 | 9 | 2. **Stop Minikube:** 10 | ```bash 11 | minikube stop 12 | ``` 13 | Stops the Minikube cluster. 14 | 15 | 3. **Delete Minikube Cluster:** 16 | ```bash 17 | minikube delete 18 | ``` 19 | Deletes the Minikube cluster. 20 | 21 | 4. **Check Minikube Status:** 22 | ```bash 23 | minikube status 24 | ``` 25 | Displays the status of the Minikube cluster and its components. 26 | 27 | 5. **Update Minikube:** 28 | ```bash 29 | minikube update-check 30 | ``` 31 | Checks for the latest Minikube version available. 32 | 33 | ### Configuration and Settings 34 | 35 | 6. **Configure Minikube:** 36 | ```bash 37 | minikube config set 38 | ``` 39 | Sets a Minikube configuration key. 40 | 41 | 7. **Get Minikube Configuration:** 42 | ```bash 43 | minikube config view 44 | ``` 45 | Displays the current Minikube configuration. 46 | 47 | 8. **List Configurations:** 48 | ```bash 49 | minikube config view --format=json 50 | ``` 51 | Shows the configurations in JSON format. 52 | 53 | ### Cluster Management 54 | 55 | 9. **SSH into Minikube VM:** 56 | ```bash 57 | minikube ssh 58 | ``` 59 | Opens an SSH session to the Minikube VM. 60 | 61 | 10. **Dashboard:** 62 | ```bash 63 | minikube dashboard 64 | ``` 65 | Launches the Kubernetes dashboard in a web browser. 66 | 67 | 11. **Addons:** 68 | - **List Available Addons:** 69 | ```bash 70 | minikube addons list 71 | ``` 72 | Displays a list of available addons. 73 | 74 | - **Enable an Addon:** 75 | ```bash 76 | minikube addons enable 77 | ``` 78 | Enables the specified addon. 79 | 80 | - **Disable an Addon:** 81 | ```bash 82 | minikube addons disable 83 | ``` 84 | Disables the specified addon. 85 | 86 | ### Networking 87 | 88 | 12. **Get Minikube IP Address:** 89 | ```bash 90 | minikube ip 91 | ``` 92 | Displays the IP address of the Minikube cluster. 93 | 94 | 13. **Expose a Service:** 95 | ```bash 96 | kubectl expose deployment --type=NodePort --name= 97 | ``` 98 | Exposes a deployment as a service. 99 | 100 | ### Resource Management 101 | 102 | 14. **Get Cluster Information:** 103 | ```bash 104 | kubectl cluster-info 105 | ``` 106 | Displays information about the cluster. 107 | 108 | 15. **View Logs:** 109 | ```bash 110 | minikube logs 111 | ``` 112 | Displays logs from the Minikube cluster. 113 | 114 | 16. **View Resource Usage:** 115 | ```bash 116 | kubectl top pods 117 | ``` 118 | Displays resource usage statistics for pods. 119 | 120 | ### Kubernetes Integration 121 | 122 | 17. **Use Minikube Context:** 123 | ```bash 124 | kubectl config use-context minikube 125 | ``` 126 | Switches the current context to the Minikube cluster. 127 | 128 | 18. **Apply a Kubernetes YAML Configuration:** 129 | ```bash 130 | kubectl apply -f 131 | ``` 132 | Applies the specified configuration file to the cluster. 133 | 134 | ### Advanced Features 135 | 136 | 19. **Start Minikube with Specific Driver:** 137 | ```bash 138 | minikube start --driver= 139 | ``` 140 | Starts Minikube using a specific driver (e.g., `docker`, `virtualbox`). 141 | 142 | 20. **Enable Ingress Addon:** 143 | ```bash 144 | minikube addons enable ingress 145 | ``` 146 | Enables the NGINX Ingress controller. 147 | 148 | ### Example Commands 149 | 150 | ```bash 151 | # Start Minikube cluster 152 | minikube start 153 | 154 | # Check Minikube status 155 | minikube status 156 | 157 | # Open Minikube dashboard 158 | minikube dashboard 159 | 160 | # SSH into Minikube VM 161 | minikube ssh 162 | 163 | # Delete Minikube cluster 164 | minikube delete 165 | ``` 166 | -------------------------------------------------------------------------------- /00-kubernetes/metric-important/code/components.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: metrics-server 5 | namespace: kube-system 6 | spec: 7 | selector: 8 | matchLabels: 9 | k8s-app: metrics-server 10 | template: 11 | metadata: 12 | labels: 13 | k8s-app: metrics-server 14 | spec: 15 | securityContext: # Move fsGroup to pod level 16 | fsGroup: 2000 # File system group to ensure permissions 17 | containers: 18 | - name: metrics-server 19 | image: k8s.gcr.io/metrics-server/metrics-server:v0.6.2 20 | args: 21 | - --kubelet-insecure-tls 22 | ports: 23 | - containerPort: 443 24 | protocol: TCP 25 | securityContext: # Keep this at the container level 26 | runAsUser: 1000 # Ensure it runs as a specific user 27 | runAsGroup: 3000 # Run as a specific group 28 | volumeMounts: 29 | - name: tmp-cert-storage 30 | mountPath: /apiserver.local.config # Specify the location where certificates are stored 31 | volumes: 32 | - name: tmp-cert-storage 33 | emptyDir: {} # Create a temporary directory for certificate storage 34 | -------------------------------------------------------------------------------- /00-step-by-step-environment-intallation-on-codespace.md: -------------------------------------------------------------------------------- 1 | # Merhaba Class - CG Updated This! 2 | Salih. 3 | # Installing Minikube in GitHub Codespaces 4 | tuncer 5 | Minikube allows you to run a local Kubernetes cluster on your machine. Below are the steps to set it up in a GitHub Codespace. 6 | 7 | ## Prerequisites 8 | 9 | Ensure you have the following installed in your Codespace: 10 | 11 | 1. **Docker**: Minikube uses Docker to create a virtual machine. You can check if Docker is installed by running: 12 | ```bash 13 | docker --version 14 | ``` 15 | 16 | 2. **kubectl**: The command-line tool for managing Kubernetes clusters. Install it using the following command: 17 | ```bash 18 | curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" 19 | chmod +x ./kubectl 20 | sudo mv ./kubectl /usr/local/bin/kubectl 21 | ``` 22 | 23 | 3. **Minikube**: Install Minikube with the following command: 24 | ```bash 25 | curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 26 | sudo install minikube-linux-amd64 /usr/local/bin/minikube 27 | ``` 28 | 29 | ## Steps to Install Minikube 30 | 31 | 1. **Update and Upgrade the System**: 32 | Before proceeding, it's good practice to update the package lists and upgrade installed packages: 33 | ```bash 34 | sudo apt update && sudo apt upgrade -y 35 | ``` 36 | 37 | 2. **Start Minikube with Docker Driver**: 38 | To start Minikube using Docker as the driver, run the following command: 39 | ```bash 40 | minikube start --driver=docker 41 | ``` 42 | 43 | 3. **Check Minikube Status**: 44 | Verify that Minikube is running correctly: 45 | ```bash 46 | minikube status 47 | ``` 48 | 49 | 4. **Access the Minikube Dashboard (Optional)**: 50 | Minikube provides a dashboard for visual management. To launch it, run: 51 | ```bash 52 | minikube dashboard 53 | ``` 54 | 55 | 5. **Using kubectl with Minikube**: 56 | You can now use `kubectl` to manage your Minikube cluster. For example, check the nodes in your cluster with: 57 | ```bash 58 | kubectl get nodes 59 | ``` 60 | 61 | ## Conclusion 62 | 63 | By following these steps, you will have a fully operational Minikube environment in your GitHub Codespace, ready for developing and testing Kubernetes applications. 64 | -------------------------------------------------------------------------------- /00-windows-shot-path.md: -------------------------------------------------------------------------------- 1 | # mklink 2 | 3 | If your windows path name is too long, you can generate a link to make it shorter. 4 | 5 | mklink /J C:\k8s-traning-class C:\Users\Administrator\Desktop\github-repo\kubernetes-rancher-on-codespaces\kubernetes-rancher-on-codespaces 6 | 7 | -------------------------------------------------------------------------------- /000-markdown/02-markdown-command-list.md: -------------------------------------------------------------------------------- 1 | # Markdown Commands Table 2 | 3 | | **Command** | **Syntax** | **Example** | **Rendered Output** | **Explanation** | 4 | |-------------------|-----------------------------------------|---------------------------------------------------------------|-----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| 5 | | **Headers** | `# Header 1`
`## Header 2`
`### Header 3` | ```markdown # Header 1 ## Header 2 ### Header 3 ``` | # Header 1
## Header 2
### Header 3 | Use `#` symbols to create headers. The number of `#` symbols indicates the header level (1-6). H1 is the largest and H6 is the smallest. | 6 | | **Bold Text** | `**bold**` or `__bold__` | ```markdown **This is bold text** ``` | **This is bold text** | Wrap text with double asterisks `**` or double underscores `__` to make it bold. | 7 | | **Italic Text** | `*italic*` or `_italic_` | ```markdown *This is italic text* ``` | *This is italic text* | Wrap text with single asterisks `*` or single underscores `_` to make it italic. | 8 | | **Unordered List**| `* Item`
`- Item`
`+ Item` | ```markdown * Item 1
* Item 2
* Item 3 ``` | - Item 1
- Item 2
- Item 3 | Use `*`, `-`, or `+` to create unordered lists. Items can have subitems by indenting them with spaces. | 9 | | **Ordered List** | `1. Item` | ```markdown 1. First item
2. Second item ``` | 1. First item
2. Second item | Use numbers followed by a period to create ordered lists. The numbering is automatically generated, so you can repeat `1.` for all items. | 10 | | **Links** | `[text](URL)` | ```markdown [OpenAI](https://www.openai.com) ``` | [OpenAI](https://www.openai.com) | Create a hyperlink by wrapping the link text in square brackets and the URL in parentheses. | 11 | | **Images** | `![alt text](image URL)` | ```markdown ![OpenAI Logo](https://openai.com/favicon.ico) ``` | ![OpenAI Logo](https://openai.com/favicon.ico) | Embed images similarly to links but with an exclamation mark before the brackets. The "alt text" appears if the image cannot be loaded. | 12 | | **Blockquotes** | `> Quote` | ```markdown > This is a blockquote. ``` | > This is a blockquote. | Use `>` to create blockquotes. You can nest blockquotes by adding additional `>` symbols. | 13 | | **Inline Code** | `` `code` `` | ```markdown Here is some inline code: `console.log('Hello')`. ``` | Here is some inline code: `console.log('Hello')`. | Use backticks `` ` `` to format code inline with the text. | 14 | | **Code Block** | ```` ```code``` ```` | ```markdown ```
function greet() {
console.log('Hi');
}
``` ``` | ```
function greet() {
console.log('Hi');
}
``` | Use triple backticks to create a code block. This is useful for larger code snippets. You can also specify a language right after the first set of backticks. | 15 | | **Horizontal Rule**| `---` or `***` or `___` | ```markdown --- ``` | --- | Create a horizontal line by using three or more dashes, asterisks, or underscores. This helps separate 16 | -------------------------------------------------------------------------------- /000-mermaid/01-chart-language.md: -------------------------------------------------------------------------------- 1 | # Chart Language 2 | 3 | **Mermaid** is a lightweight JavaScript-based diagramming and charting tool that allows you to define diagrams in text format. It simplifies the process of creating complex flowcharts, sequence diagrams, Gantt charts, class diagrams, and other types of visual representations, without needing to use a graphical interface. The diagrams are written in a simple markup language and are rendered as SVGs (Scalable Vector Graphics). 4 | 5 | ## Key Features: 6 | 7 | - **Text-based**: Diagrams are created using text, making it easy to version control and collaborate in codebases. 8 | - **Automated Rendering**: Mermaid automatically generates visual diagrams from simple text input, which can be easily integrated into Markdown files, web pages, and more. 9 | - **Variety of Diagrams**: Supports multiple diagram types, including flowcharts, sequence diagrams, Gantt charts, class diagrams, state diagrams, and pie charts. 10 | 11 | ## Example of a Mermaid Flowchart: 12 | 13 | ``` 14 | graph TD 15 | A[Start] --> B{Decision?} 16 | B -->|Yes| C[Proceed] 17 | B -->|No| D[Stop] 18 | C --> E[End] 19 | ``` 20 | 21 | ```mermaid 22 | graph TD 23 | A[Start] --> B{Decision?} 24 | B -->|Yes| C[Proceed] 25 | B -->|No| D[Stop] 26 | C --> E[End] 27 | ``` 28 | 29 | This simple example generates a flowchart with a decision point. You can write similar diagrams directly in text form, and Mermaid will handle rendering the graphical representation. 30 | 31 | ## Supported Diagrams: 32 | 33 | - **Flowcharts**: Visualizes processes, steps, or systems. 34 | - **Sequence Diagrams**: Shows interactions between entities over time. 35 | - **Gantt Charts**: Visualizes project timelines and task scheduling. 36 | - **Class Diagrams**: Used in object-oriented programming to represent relationships between classes. 37 | - **State Diagrams**: Describes different states of a system and transitions between those states. 38 | - **Pie Charts**: Displays data in a pie chart format. 39 | 40 | Mermaid is widely used in platforms like GitHub, GitLab, and various documentation tools to create diagrams directly in Markdown or web content. Its simplicity and flexibility make it a great tool for software developers, technical writers, and other professionals needing to visualize concepts without the overhead of traditional diagramming software. 41 | -------------------------------------------------------------------------------- /000-mermaid/02-flowchart-element-list.md: -------------------------------------------------------------------------------- 1 | # Flowchart Element List 2 | 3 | ## 1. **Standard Rectangle (Process)** 4 | 5 | - Represents a typical process or step. 6 | - Syntax: `ID[Text]` 7 | 8 | ``` 9 | A[Process] 10 | ``` 11 | 12 | ## 2. **Rounded Rectangle (Subprocess)** 13 | 14 | - Represents a subprocess or alternative process. 15 | - Syntax: `ID(Text)` 16 | 17 | ``` 18 | B(Rounded Process) 19 | ``` 20 | 21 | ## 3. **Circle (Start/End)** 22 | 23 | - Typically used for the start or end of a process. 24 | - Syntax: `ID((Text))` 25 | 26 | ``` 27 | C((Start/End)) 28 | ``` 29 | 30 | ## 4. **Diamond (Decision)** 31 | 32 | - Represents a decision point with multiple possible outcomes. 33 | - Syntax: `ID{Text}` 34 | 35 | ``` 36 | D{Decision} 37 | ``` 38 | 39 | ## 5. **Parallelogram (Input/Output)** 40 | 41 | - Used for data input or output. 42 | - Syntax: `ID[/Text/]` or `ID[\Text\]` 43 | 44 | ``` 45 | E[/Input/] 46 | ``` 47 | 48 | ## 6. **Hexagon (Preparation)** 49 | 50 | - Represents preparation steps or setup activities. 51 | - Syntax: `ID{{Text}}` 52 | 53 | ``` 54 | F{{Preparation}} 55 | ``` 56 | 57 | ## 7. **Parallelogram (Input/Output)** 58 | 59 | - Used for data input or output. 60 | - Syntax: `ID[/Text/]` or `ID[\Text\]` 61 | 62 | ``` 63 | E[/Input/] 64 | ``` 65 | 66 | ## 8. **Links (Arrows)** 67 | 68 | - Connects flowchart components and shows the flow direction. 69 | - **Solid Arrow**: `-->` 70 | - **Dashed Arrow**: `-.->` 71 | - **Thick Arrow**: `==>` 72 | 73 | ``` 74 | A --> B 75 | B -.-> C 76 | A ==> D 77 | ``` 78 | 79 | ## 9. **Text Labels on Links** 80 | 81 | - Adds labels to arrows to describe conditions or actions. 82 | - Syntax: `ID -->|Text| ID` 83 | 84 | ``` 85 | A -->|Yes| B 86 | A -->|No| C 87 | ``` 88 | 89 | ## 10. **Subgraphs** 90 | 91 | - Groups a set of nodes into a named cluster. 92 | - Syntax: `subgraph Name ... end` 93 | 94 | ``` 95 | subgraph Cluster1 96 | A --> B 97 | end 98 | ``` 99 | 100 | ## 11. **Direction** 101 | 102 | - Sets the direction of the flow in the chart. 103 | - **TD** (Top to Down): `graph TD` 104 | - **LR** (Left to Right): `graph LR` 105 | - **BT** (Bottom to Top): `graph BT` 106 | - **RL** (Right to Left): `graph RL` 107 | 108 | ``` 109 | graph LR 110 | ``` 111 | 112 | ## 12. **Loops** 113 | 114 | - Represents a process that repeats or loops. 115 | - Syntax: You can link a node back to itself. 116 | 117 | ``` 118 | A --> B 119 | B --> A 120 | ``` 121 | 122 | ## 13. **Notes** 123 | 124 | - Adds explanatory notes to the flowchart. 125 | - Syntax: `ID ---|Note| ID` 126 | 127 | ``` 128 | A ---|Note| B 129 | ``` 130 | 131 | ## 14. **Styling Components** 132 | 133 | - Customize the appearance of flowchart elements. 134 | - Syntax: `classDef className ...` 135 | - Use `class ID className` to apply the style. 136 | 137 | ``` 138 | classDef green fill:#9f6,stroke:#333,stroke-width:2px; 139 | A --> B 140 | class A green 141 | ``` 142 | 143 | ## Sample 144 | 145 | ``` 146 | graph TD 147 | A[Start] --> B{Decision Point} 148 | B -->|Yes| C[Action 1] 149 | B -->|No| D[Action 2] 150 | C --> E[End] 151 | D --> E[End] 152 | ``` 153 | 154 | ```mermaid 155 | graph TD 156 | A[Start] --> B{Decision Point} 157 | B -->|Yes| C[Action 1] 158 | B -->|No| D[Action 2] 159 | C --> E[End] 160 | D --> E[End] 161 | ``` 162 | 163 | ## Explanation 164 | 165 | - **A**: Represents the start of the process. 166 | - **B**: A decision point where the flow can branch based on "Yes" or "No". 167 | - **C**: The action to take if the decision is "Yes". 168 | - **D**: The action to take if the decision is "No". 169 | - **E**: Represents the end of the process. 170 | 171 | The diagram has a top-down (TD) flow, and arrows show the direction between each step. 172 | 173 | ![](./images/flowchat-sample.png) 174 | -------------------------------------------------------------------------------- /000-mermaid/03-sequence-diagram-element-list.md: -------------------------------------------------------------------------------- 1 | # Sequence Diagram Elements 2 | 3 | ## 1. **Participants** 4 | 5 | - Represents the actors or objects in the sequence diagram. 6 | - Syntax: `participant Name` 7 | 8 | ``` 9 | participant Alice 10 | participant Bob 11 | ``` 12 | 13 | ## 2. **Messages** 14 | 15 | - Used to show the flow of messages or actions between participants. 16 | - **Solid Arrow**: `->` for regular messages. 17 | - **Dashed Arrow**: `-->` for asynchronous messages. 18 | 19 | ``` 20 | Alice -> Bob: Hello 21 | Bob --> Alice: Hi back 22 | ``` 23 | 24 | ## 3. **Activation (Lifeline)** 25 | 26 | - Indicates when an object is active during the sequence. 27 | - Syntax: `activate Name` and `deactivate Name` 28 | 29 | ``` 30 | Alice -> Bob: Activate Bob 31 | activate Bob 32 | Bob -> Alice: Response 33 | deactivate Bob 34 | ``` 35 | 36 | ## 4. **Loops** 37 | 38 | - Represents repeating messages or actions. 39 | - Syntax: `loop Description ... end` 40 | 41 | ``` 42 | loop Check every second 43 | Alice -> Bob: Ping 44 | end 45 | ``` 46 | 47 | ## 5. **Alt/Else Blocks (Conditional Branching)** 48 | 49 | - For decisions and alternate paths. 50 | - Syntax: `alt Condition ... else ... end` 51 | 52 | ``` 53 | alt Successful 54 | Alice -> Bob: OK 55 | else Failed 56 | Alice -> Bob: Retry 57 | end 58 | ``` 59 | 60 | ### 6. **Parallel (Concurrency)** 61 | 62 | - Represents concurrent processes. 63 | - Syntax: `par ... and ... end` 64 | 65 | ``` 66 | par Task 1 67 | Alice -> Bob: Start task 1 68 | and Task 2 69 | Alice -> Charlie: Start task 2 70 | end 71 | ``` 72 | 73 | ### 7. **Notes** 74 | 75 | - You can add notes for clarification or comments. 76 | - Syntax: `Note left of Name: text` or `Note right of Name: text` 77 | 78 | ``` 79 | Note right of Bob: Thinking... 80 | ``` 81 | 82 | ### 8. **Message to Self** 83 | 84 | - Represents a message that a participant sends to themselves. 85 | - Syntax: `Name ->> Name: Action` 86 | 87 | ``` 88 | Alice ->> Alice: Reflecting 89 | ``` 90 | 91 | ### 9. **Break** 92 | 93 | - Used to indicate an interruption in the flow. 94 | - Syntax: `break Description ... end` 95 | 96 | ``` 97 | break System error 98 | Alice -> Bob: Error message 99 | end 100 | ``` 101 | 102 | ### 10. **Critical** 103 | 104 | - Shows critical sections. 105 | - Syntax: `critical Description ... end` 106 | 107 | ``` 108 | critical Critical operation 109 | Alice -> Bob: Do something critical 110 | end 111 | ``` 112 | 113 | ### 11. **Rect** 114 | 115 | - Groups actions together for emphasis. 116 | - Syntax: `rect color` 117 | 118 | ``` 119 | rect rgb(191, 223, 255) 120 | Alice -> Bob: Grouped action 121 | end 122 | ``` 123 | 124 | ### 12. **Opt (Optional Section)** 125 | 126 | - For optional steps. 127 | - Syntax: `opt Description ... end` 128 | 129 | ``` 130 | opt Optional step 131 | Alice -> Bob: Can skip this 132 | end 133 | ``` 134 | 135 | ## Sample 136 | 137 | ``` 138 | sequenceDiagram 139 | participant User 140 | participant System 141 | 142 | User->>System: Request Login 143 | System->>User: Display Login Form 144 | User->>System: Submit Credentials 145 | System->>System: Validate Credentials 146 | alt Successful Login 147 | System->>User: Display Dashboard 148 | else Failed Login 149 | System->>User: Display Error Message 150 | end 151 | ``` 152 | 153 | ```mermaid 154 | sequenceDiagram 155 | participant User 156 | participant System 157 | 158 | User->>System: Request Login 159 | System->>User: Display Login Form 160 | User->>System: Submit Credentials 161 | System->>System: Validate Credentials 162 | alt Successful Login 163 | System->>User: Display Dashboard 164 | else Failed Login 165 | System->>User: Display Error Message 166 | end 167 | ``` 168 | 169 | ### Explanation 170 | 171 | - **Participants**: There are two participants, `User` and `System`. 172 | - **Arrows**: The arrows indicate the messages being sent between the user and the system. 173 | - **alt/else**: The `alt` block shows an alternative flow depending on whether the login is successful or failed. 174 | 175 | ![](./images/sequence-diagram.png) -------------------------------------------------------------------------------- /000-mermaid/images/flowchat-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/000-mermaid/images/flowchat-sample.png -------------------------------------------------------------------------------- /000-mermaid/images/project-plan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/000-mermaid/images/project-plan.png -------------------------------------------------------------------------------- /000-mermaid/images/sequence-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/000-mermaid/images/sequence-diagram.png -------------------------------------------------------------------------------- /000-mermaid/images/timeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/000-mermaid/images/timeline.png -------------------------------------------------------------------------------- /01-pod/01-what-is-pods.md: -------------------------------------------------------------------------------- 1 | # What is the Pod 2 | 3 | In Kubernetes, a **Pod** is the smallest and most basic deployment unit. Each pod represents an abstraction layer for running applications and contains one or more containers. It groups containers together, allowing them to work cohesively and communicate over the same network. Here's a detailed overview of Pods: 4 | 5 | ## 1. **Definition of a Pod** 6 | 7 | A pod is a unit that logically groups one or more containers that are deployed together in a Kubernetes environment. When containers are placed in the same pod, they share the same IP address and ports, and often use shared storage resources (volumes). They also share network transmission and lifecycle management. 8 | 9 | ## 2. **Components of a Pod** 10 | 11 | A pod consists of several fundamental components: 12 | 13 | - **One or More Containers**: Typically, pods host a single container, but in some special cases, multiple containers are run within the same pod (such as in a sidecar pattern). 14 | - **Storage (Volumes)**: Pods can use persistent or ephemeral storage units to store their data. These volumes can be shared across all containers in the pod. 15 | - **Networking**: Each pod has a unique IP address assigned by Kubernetes. Containers within the same pod communicate with each other via this IP address. 16 | - **Configuration and Secrets (ConfigMap, Secret)**: A pod can use necessary configuration files, environment variables, or secrets provided by Kubernetes objects. 17 | 18 | ## 3. **Single- and Multi-Container Pods** 19 | 20 | - **Single-Container Pods**: Most applications run a single container. This is a simple structure and is widely used in Kubernetes. 21 | - **Multi-Container Pods**: Sometimes, multiple containers are run within the same pod. In this case, the containers are tightly integrated and work closely together. For example, a primary container might work alongside a helper container (like in the sidecar pattern). 22 | 23 | ## 4. **Pod Lifecycle** 24 | 25 | Pods have a specific lifecycle: 26 | 27 | - **Pending**: The pod has been created but the containers have not yet started running. 28 | - **Running**: The pod and its containers have successfully started and are running. 29 | - **Succeeded**: All containers in the pod have completed successfully. 30 | - **Failed**: One or more containers in the pod have terminated with an error. 31 | - **CrashLoopBackOff**: The pod is continually restarting due to repeated failures. 32 | 33 | ## 5. **Characteristics of a Pod** 34 | 35 | - **Single IP Address**: Each pod is assigned a unique IP address in the Kubernetes cluster. Containers within the pod communicate using this IP address. 36 | - **Ephemeral Nature**: Pods are generally ephemeral and temporary. By design, Kubernetes allows pods to die and be recreated. 37 | - **Scalability**: Pods cannot scale on their own. If more copies of the same application are needed, a higher-level Kubernetes object like a **Deployment** or **ReplicaSet** is used to create and manage multiple pod replicas. 38 | 39 | ## 6. **Use Cases for Pods** 40 | 41 | - **Simple Applications**: Used for simple web servers or microservices that run a single container. 42 | - **Interdependent Functions**: Multi-container pods run containers that complement each other (e.g., a web server and a cache manager). 43 | - **Data Sharing**: Containers can share data through volumes when they use a common file system. 44 | 45 | ## 7. **Managing Pods** 46 | 47 | Rather than managing pods directly, Kubernetes usually manages them via higher-level objects like **Deployments** or **ReplicaSets**. These objects handle scaling, updating, and automatically restarting pods. 48 | 49 | ## 8. **Other Important Pod Concepts** 50 | 51 | - **Multi-Tenancy**: Pods allow different applications to run on the same physical node while isolating their resources. 52 | - **Health Checks**: Kubernetes has health checks to monitor whether pods are functioning correctly. If a pod does not respond for a certain time, Kubernetes can restart it. 53 | 54 | ## Conclusion 55 | 56 | Pods are the fundamental units where applications run in Kubernetes. They can operate individually or with other containers and are managed, deployed, and monitored by Kubernetes. Although they are ephemeral, pods ensure containers run securely and are easily deployable. -------------------------------------------------------------------------------- /01-pod/03-multi-tenance.md: -------------------------------------------------------------------------------- 1 | # What is Multi-Tenancy? 2 | 3 | **Multi-tenancy** is an architectural approach that allows multiple users, applications, or services to operate in isolation on the same physical infrastructure. In the context of Kubernetes, multi-tenancy refers to the ability for multiple applications or user groups to utilize the same resources within a cluster while ensuring that these resources are securely and effectively isolated. 4 | 5 | ## Multi-Tenancy in Kubernetes 6 | 7 | Kubernetes offers various mechanisms to enable multi-tenancy features. With these mechanisms, different applications or user groups can control their access to each other's resources while running within the same Kubernetes cluster. Here are some key components of this approach and how they work: 8 | 9 | ### 1. **Namespaces** 10 | 11 | - **Definition**: Kubernetes uses the concept of **namespaces** to group resources. Each namespace creates a logical space for a specific application or user group. 12 | 13 | - **Purpose**: To isolate the resources of different applications or users. For instance, if two different projects are running in the same Kubernetes cluster, separate namespaces can be created for each to ensure resource separation. 14 | 15 | - **Usage**: All Kubernetes resources created within a namespace (such as Pods, Services, ConfigMaps, etc.) are only visible to users belonging to that namespace. This prevents users from accessing resources belonging to other applications. 16 | 17 | ### 2. **RBAC (Role-Based Access Control)** 18 | 19 | - **Definition**: RBAC is a method used in Kubernetes to manage access control to resources. It defines which resources a user or service account can access by assigning specific roles. 20 | 21 | - **Purpose**: To limit users or applications' access only to the resources they need. For example, a user might have access only to Pods within a specific namespace, while another user cannot access resources in other namespaces. 22 | 23 | - **Usage**: With RBAC, a specific role can be created (e.g., a role with read-only permissions), and this role is assigned to certain users or groups. This way, users can access only the resources they are authorized for. 24 | 25 | ### 3. **Network Policies** 26 | 27 | - **Definition**: Network policies are a mechanism that controls the network traffic between Pods. It defines which Pod can access which other Pods. 28 | 29 | - **Purpose**: To ensure secure communication between applications and support the isolation of resources. For example, Pods in one namespace can be restricted from accessing Pods in another namespace. 30 | 31 | - **Usage**: A network policy created within a specific namespace can allow traffic only from certain IP addresses or specific Pods. 32 | 33 | ### 4. **Resource Quotas** 34 | 35 | - **Definition**: Resource quotas are a mechanism used to limit the resources (CPU, memory, etc.) that can be utilized within a namespace. 36 | 37 | - **Purpose**: To ensure fair distribution of resources among different users or applications and to prevent excessive resource consumption. 38 | 39 | - **Usage**: A specific amount of CPU and memory can be allocated for a namespace. For instance, if a project is limited to 4 CPUs and 8 GB of memory, the Pods associated with that project cannot exceed this limit. 40 | 41 | ## Example Scenario 42 | 43 | Let's say a company wants to run two different applications (for instance, an e-commerce site and an internal communication tool) in the same Kubernetes cluster. Below is a scenario of how these applications can be managed using multi-tenancy: 44 | 45 | 1. **Creating Namespaces**: 46 | - A namespace called `ecommerce` is created for the e-commerce application. 47 | - Another namespace called `communication` is created for the communication tool. 48 | 49 | 2. **Access Control with RBAC**: 50 | - The e-commerce team is granted access only to the `ecommerce` namespace. 51 | - The communication tool team is granted access only to the `communication` namespace. 52 | 53 | 3. **Communication Control with Network Policies**: 54 | - Pods in the `ecommerce` namespace are allowed to access only other Pods within that namespace. Pods in the `communication` namespace cannot access them. 55 | 56 | 4. **Resource Management with Resource Quotas**: 57 | - Pods in the `ecommerce` namespace are limited to 8 CPUs and 16 GB of memory. 58 | - Pods in the `communication` namespace are limited to 4 CPUs and 8 GB of memory. 59 | 60 | ## Conclusion 61 | 62 | Multi-tenancy enables effective management of resources in Kubernetes while isolating applications from each other. This allows different applications or user groups sharing the same physical infrastructure to operate securely and efficiently. Mechanisms like **Namespaces**, **RBAC**, **Network Policies**, and **Resource Quotas** are fundamental components of the multi-tenancy approach, providing essential structures for applications and users within a Kubernetes cluster. -------------------------------------------------------------------------------- /01-pod/04-how-to-install-developer-app-into-pod.md: -------------------------------------------------------------------------------- 1 | # How to install developer app into pod 2 | 3 | To "push" an application developed into a Kubernetes Pod, you typically follow these steps. These steps include creating your application as a Docker image, uploading that image to a container registry, and then using that image to create a Pod in Kubernetes. 4 | 5 | ## Step 1: Create a Docker Image for Your Application 6 | 7 | 1. **Create a Dockerfile**: Create a `Dockerfile` in the directory where your application is located. Here’s an example of a `Dockerfile`: 8 | 9 | ```dockerfile 10 | # Base image 11 | FROM python:3.9-slim 12 | 13 | # Working directory 14 | WORKDIR /erdem-helloworld 15 | 16 | # Copy requirements file and application files 17 | COPY requirements.txt . 18 | RUN pip install -r requirements.txt 19 | COPY . . 20 | 21 | # Start the application 22 | CMD ["python", "app.py"] 23 | ``` 24 | 25 | 2. **Build the Docker Image**: Run the following command in the terminal to build your Docker image: 26 | 27 | ```bash 28 | docker build -t your-username/your-app-name:latest . 29 | ``` 30 | 31 | Replace `your-username/your-app-name` with your own username and application name. 32 | 33 | ## Step 2: Push the Docker Image to a Registry 34 | 35 | Follow these steps to upload your Docker image to a container registry (for example, Docker Hub): 36 | 37 | 1. **Login to Docker Hub**: If you're using Docker Hub, you need to log in first: 38 | 39 | ```bash 40 | docker login 41 | ``` 42 | 43 | 2. **Push the Image**: Use the following command to upload your created image: 44 | 45 | ```bash 46 | docker push your-username/your-app-name:latest 47 | ``` 48 | 49 | ## Step 3: Create a Kubernetes Pod 50 | 51 | Now that your Docker image is uploaded to the registry, you can create a Kubernetes Pod using that image. 52 | 53 | 1. **Create a YAML File**: Create a YAML file that defines a Pod for your application. Here’s a simple example: 54 | 55 | ```yaml 56 | apiVersion: v1 57 | kind: Pod 58 | metadata: 59 | name: your-app-pod 60 | spec: 61 | containers: 62 | - name: your-app-container 63 | image: your-username/your-app-name:latest 64 | ports: 65 | - containerPort: 80 66 | ``` 67 | 68 | 2. **Create the Pod**: Use the YAML file to create the Pod: 69 | 70 | ```bash 71 | kubectl apply -f your-app-pod.yaml 72 | ``` 73 | 74 | ## Step 4: Check the Pod Status 75 | 76 | You can check whether the Pod was created successfully by using the following command: 77 | 78 | ```bash 79 | kubectl get pods 80 | ``` 81 | 82 | ## Summary 83 | 84 | The steps above summarize how to "push" an application developed into a Kubernetes Pod. You create your application as a Docker image, upload that image to a registry, and then create a Pod in Kubernetes using that image. -------------------------------------------------------------------------------- /01-pod/05-hot-to-install-multi-container-into-pod.md: -------------------------------------------------------------------------------- 1 | # How to install multi container into pod 2 | 3 | To create multiple containers within a Kubernetes Pod, you need to define multiple containers under the `spec.containers` section in the Pod's manifest file. Below is a step-by-step example explaining how to set up multiple containers within a single Pod. 4 | 5 | ## Step 1: Create a YAML File 6 | 7 | Here’s a simple example of a Pod manifest file that contains two containers. In this example, a Python application and an Nginx web server run within the same Pod. 8 | 9 | ```yaml 10 | apiVersion: v1 11 | kind: Pod 12 | metadata: 13 | name: multi-container-pod 14 | spec: 15 | containers: 16 | - name: python-app 17 | image: your-username/python-app:latest 18 | ports: 19 | - containerPort: 5000 20 | # Optionally, you can add environment variables, volumes, etc. 21 | - name: nginx 22 | image: nginx:latest 23 | ports: 24 | - containerPort: 80 25 | ``` 26 | 27 | ## Step 2: Create the Pod 28 | 29 | Save the YAML file (for example, as `multi-container-pod.yaml`) and create the Pod using the following command: 30 | 31 | ```bash 32 | kubectl apply -f multi-container-pod.yaml 33 | ``` 34 | 35 | ## Step 3: Check the Pod's Status 36 | 37 | You can check whether the Pod has been successfully created with the following command: 38 | 39 | ```bash 40 | kubectl get pods 41 | ``` 42 | 43 | ## Explanation 44 | 45 | 1. **Container Definitions**: In the YAML file above, two containers are defined under `spec.containers`: `python-app` and `nginx`. Each container has a `name` and an `image` field. 46 | 47 | 2. **Ports**: The `containerPort` field specifies which ports each container will expose. 48 | 49 | 3. **Environment Variables and Volumes**: If needed, you can add environment variables, volumes, or other configurations for each container. 50 | 51 | ## Advanced Configurations 52 | 53 | Pods with multiple containers are useful for scenarios requiring communication and data sharing between containers. You can also define shared volumes to facilitate data sharing. For example: 54 | 55 | ```yaml 56 | apiVersion: v1 57 | kind: Pod 58 | metadata: 59 | name: multi-container-pod-with-volume 60 | spec: 61 | containers: 62 | - name: python-app 63 | image: your-username/python-app:latest 64 | ports: 65 | - containerPort: 5000 66 | volumeMounts: 67 | - name: shared-volume 68 | mountPath: /app/data 69 | - name: nginx 70 | image: nginx:latest 71 | ports: 72 | - containerPort: 80 73 | volumeMounts: 74 | - name: shared-volume 75 | mountPath: /usr/share/nginx/html 76 | volumes: 77 | - name: shared-volume 78 | emptyDir: {} 79 | ``` 80 | 81 | ## Conclusion 82 | 83 | Creating multiple containers within a Pod makes your applications more modular and allows direct communication between containers. The examples and steps above demonstrate how to achieve this process effectively. -------------------------------------------------------------------------------- /01-pod/06-how-to-update-old-pod-to-new-pod.md: -------------------------------------------------------------------------------- 1 | # How to update new pod 2 | 3 | To replace an old Pod with a new one in Kubernetes, you typically follow an update or redeployment process. This process may vary depending on the specific application deployment method you are using. Here are the steps on how to do this: 4 | 5 | ## 1. Update Using a Deployment 6 | 7 | The most common method is to use a **Deployment** to manage updates. This simplifies version control for your Pods. 8 | 9 | ### Step 1: Update the Deployment YAML File 10 | 11 | If you have an existing Deployment, update the YAML file to specify the new image version. For example: 12 | 13 | ```yaml 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: your-app-deployment 18 | spec: 19 | replicas: 3 20 | selector: 21 | matchLabels: 22 | app: your-app 23 | template: 24 | metadata: 25 | labels: 26 | app: your-app 27 | spec: 28 | containers: 29 | - name: your-app-container 30 | image: your-username/your-app-name:latest # New image version 31 | ports: 32 | - containerPort: 80 33 | ``` 34 | 35 | ### Step 2: Update the Deployment 36 | 37 | After saving the YAML file, apply the update using the following command: 38 | 39 | ```bash 40 | kubectl apply -f your-app-deployment.yaml 41 | ``` 42 | 43 | Kubernetes will create new Pods and gradually remove the old ones. 44 | 45 | ## 2. Using the `kubectl set image` Command 46 | 47 | Alternatively, you can directly update the image from the command line: 48 | 49 | ```bash 50 | kubectl set image deployment/your-app-deployment your-app-container=your-username/your-app-name:latest 51 | ``` 52 | 53 | This command updates the image of the container within the specified Deployment. 54 | 55 | ## 3. Deleting and Recreating the Pod 56 | 57 | If you are not using a Deployment and are working with a single Pod, you can delete the existing Pod and create a new one: 58 | 59 | ### Step 1: Delete the Existing Pod 60 | 61 | ```bash 62 | kubectl delete pod your-old-pod 63 | ``` 64 | 65 | ### Step 2: Create the New Pod 66 | 67 | Create the manifest file (YAML) for the new Pod and apply it using the following command: 68 | 69 | ```bash 70 | kubectl apply -f your-new-pod.yaml 71 | ``` 72 | 73 | ## Conclusion 74 | 75 | Using a Deployment is generally the best practice for replacing an old Pod with a new one, as it allows for a more stable update process. If you are not using a Deployment, it is also possible to delete the Pod and create a new one. In either case, you can update your Pods and ensure they continue running smoothly. -------------------------------------------------------------------------------- /01-pod/07-ports-information.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, the `ports` section in a service definition specifies how the service will expose and route network traffic to the underlying pods. Below is a detailed explanation of each parameter used in the `ports` section: `port`, `targetPort`, and `nodePort`. 2 | 3 | ### `ports` Section 4 | 5 | The `ports` section is where you define the ports for the service, indicating which ports the service will listen on and how to route requests to the pods. Typically, it contains three main parameters: `port`, `targetPort`, and `nodePort`. 6 | 7 | #### 1. **port** 8 | 9 | - **Definition**: This specifies the port number that the service will listen on. This is the port through which external clients or applications will access the service. 10 | - **Example**: 11 | ```yaml 12 | port: 3000 13 | ``` 14 | In this example, the service listens on port 3000. External requests will come through this port. 15 | 16 | #### 2. **targetPort** 17 | 18 | - **Definition**: This specifies the port on the pods that the service will route traffic to. It indicates which port the application inside the container is listening on. 19 | - **Example**: 20 | ```yaml 21 | targetPort: 3000 22 | ``` 23 | Here, incoming requests to the service on port 3000 will be forwarded to the pods' port 3000. This means the service will route requests from `port` 3000 to `targetPort` 3000 of the pod. 24 | 25 | #### 3. **nodePort** 26 | 27 | - **Definition**: This specifies a port number that the service will listen on each node in the Kubernetes cluster. It allows external traffic to reach the service via a specific port on any of the nodes. 28 | - **Example**: 29 | ```yaml 30 | nodePort: 30001 31 | ``` 32 | In this example, the node will listen on port 30001, and external requests can reach the service through this port. 33 | 34 | ### Example Service Definition 35 | 36 | Below is an example of a `service.yaml` file showcasing the `ports` section: 37 | 38 | ```yaml 39 | apiVersion: v1 40 | kind: Service 41 | metadata: 42 | name: my-app-service 43 | spec: 44 | type: NodePort 45 | selector: 46 | app: my-app 47 | ports: 48 | - port: 3000 # Port for incoming requests 49 | targetPort: 3000 # Port on the pod the traffic is sent to 50 | nodePort: 30001 # Specific port on each node 51 | ``` 52 | 53 | ### How It Works 54 | 55 | 1. **External Request**: When a user sends a request to `http://:30001` from outside the cluster, the request first arrives at the specified `nodePort` (30001). 56 | 57 | 2. **Service Listening**: Since the service listens on port 30001, it receives the request on that port. 58 | 59 | 3. **Routing**: The service routes the incoming request to the `targetPort` (3000) on the running application in the pod. 60 | 61 | 4. **Application**: The pod listens on port 3000, so it can handle the routed requests. 62 | 63 | ### Important Notes 64 | 65 | - The `nodePort` values must be between 30000 and 32767, which is the default range for Kubernetes. 66 | - If `nodePort` is not specified, Kubernetes will automatically assign a random port within the range of 30000 to 32767. 67 | - Choosing the service type as `NodePort` enables external access to your application. If only internal access is needed, the `ClusterIP` type can be used. 68 | 69 | With this information, you should have a clearer understanding of the port configurations in Kubernetes service definitions. If you have any further questions or need more details, feel free to ask! -------------------------------------------------------------------------------- /01-pod/08-port-types.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a **NodePort** service is one of the ways to expose a service to the outside world. When you create a NodePort service, Kubernetes assigns a specific port on each node to route external traffic to the appropriate service and its associated pods. Below, I’ll explain the key components of a NodePort service and the associated service types, including **ClusterIP** and **LoadBalancer**. 2 | 3 | ### Key Components of NodePort Service 4 | 5 | 1. **NodePort**: 6 | - **Definition**: A port that is opened on each Kubernetes node, allowing external traffic to access the service. 7 | - **Range**: The default range for NodePorts is **30000 to 32767**. 8 | - **Access**: You can access the service externally by sending requests to any node’s IP address and the assigned NodePort. 9 | 10 | 2. **ClusterIP**: 11 | - **Definition**: The default service type in Kubernetes. It exposes the service on a cluster-internal IP. 12 | - **Access**: Only accessible from within the cluster. 13 | - **Usage**: Used for internal services where external access is not required. 14 | 15 | 3. **LoadBalancer**: 16 | - **Definition**: This service type creates an external load balancer in a cloud provider (like AWS, GCP, Azure) and assigns a public IP to the service. 17 | - **Access**: It allows external traffic to reach the service through the load balancer's IP. 18 | - **Usage**: Ideal for production applications requiring external access with load balancing. 19 | 20 | ### How NodePort Works 21 | 22 | - When you create a NodePort service, Kubernetes automatically assigns a port in the specified range (if not specified, a random one is chosen). 23 | - Each node in the cluster listens on that NodePort. 24 | - Incoming requests to `:` are forwarded to the underlying pods based on the service definition. 25 | 26 | ### Example of a NodePort Service 27 | 28 | Here’s an example YAML configuration for a NodePort service: 29 | 30 | ```yaml 31 | apiVersion: v1 32 | kind: Service 33 | metadata: 34 | name: my-nodeport-service 35 | spec: 36 | type: NodePort 37 | selector: 38 | app: my-app 39 | ports: 40 | - port: 80 # The port that the service exposes 41 | targetPort: 8080 # The port on the pod to which traffic is directed 42 | nodePort: 30001 # The port exposed on each node 43 | ``` 44 | 45 | ### Accessing the Service 46 | 47 | - To access the service from outside the cluster, you would use the following URL format: 48 | 49 | ``` 50 | http://:30001 51 | ``` 52 | 53 | - Here, `` can be the IP address of any of the nodes in the Kubernetes cluster. 54 | 55 | ### Summary of Service Types 56 | 57 | | Service Type | Description | External Access | 58 | |----------------|-----------------------------------------------------------------------------------------------|-----------------------| 59 | | **ClusterIP** | Exposes the service on a cluster-internal IP. | No (internal only) | 60 | | **NodePort** | Exposes the service on each node's IP at a static port. | Yes (via NodeIP:NodePort) | 61 | | **LoadBalancer**| Creates an external load balancer in a cloud environment and assigns a public IP. | Yes (via LoadBalancer IP) | 62 | 63 | ### Additional Information 64 | 65 | - **Headless Services**: If you create a service without a ClusterIP (by setting `clusterIP: None`), it becomes a headless service, allowing you to directly reach the individual pods. 66 | - **Ingress**: For more complex routing scenarios (like host/path-based routing), you can use Ingress resources along with an Ingress controller, which allows for advanced HTTP routing configurations. 67 | 68 | If you need more specific details or have any other questions, feel free to ask! -------------------------------------------------------------------------------- /01-pod/code-flask/Dockerfile: -------------------------------------------------------------------------------- 1 | # Base image olarak Python 3.12 kullanıyoruz 2 | FROM python:3.12-slim 3 | 4 | # Çalışma dizinini ayarlayın 5 | WORKDIR /erdem-helloworld 6 | 7 | # Gerekli kütüphaneleri yüklemek için requirements.txt dosyasını kopyalayın 8 | COPY requirements.txt . 9 | 10 | # Gereksinimleri yükleyin 11 | RUN pip install --no-cache-dir -r requirements.txt 12 | 13 | # Uygulama dosyalarınızı kopyalayın 14 | # COPY . . # everything copied 15 | # COPY hello-world.py . 16 | 17 | # Flask uygulamanızı çalıştırın 18 | CMD ["python", "hello-world.py"] 19 | -------------------------------------------------------------------------------- /01-pod/code-flask/hello-world-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: erdem-flask-pod 5 | labels: 6 | app: erdemhelloworld 7 | spec: 8 | containers: 9 | - name: erdem-helloworld-container 10 | image: erdem-flask-helloworld-image:latest 11 | ports: 12 | - containerPort: 80 -------------------------------------------------------------------------------- /01-pod/code-flask/hello-world.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | app = Flask(__name__) 4 | 5 | @app.route('/') 6 | def hello_world(): 7 | return '

Hello, World!

' 8 | 9 | @app.route('/tuncer') 10 | def hello_tuncer(): 11 | return '

Hello, Tuncer!

' 12 | 13 | @app.route('/erdem') 14 | def hello_erdem(): 15 | return '

Hello, Erdem!

' 16 | 17 | if __name__ == '__main__': 18 | app.run(host='0.0.0.0', port=5000) 19 | -------------------------------------------------------------------------------- /01-pod/code-flask/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask -------------------------------------------------------------------------------- /01-pod/code/multi-container-mounted-same-log.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: my-multi-nginx-pod-mounted-logs 5 | spec: 6 | containers: 7 | - name: my-multi-nginx 8 | image: nginx:latest 9 | ports: 10 | - containerPort: 80 11 | volumeMounts: 12 | - name: shared-logs 13 | mountPath: /var/log/nginx 14 | - name: logging-sidecar 15 | image: fluentd:latest 16 | volumeMounts: 17 | - name: shared-logs 18 | mountPath: /var/log/nginx 19 | volumes: 20 | - name: shared-logs 21 | emptyDir: {} 22 | -------------------------------------------------------------------------------- /01-pod/code/multi-container-pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: my-multi-container-pod 5 | labels: 6 | app: myapp 7 | spec: 8 | containers: 9 | - name: my-multicontainer-nginx-container 10 | image: nginx:latest 11 | ports: 12 | - containerPort: 80 13 | - name: sidecar-container 14 | image: busybox 15 | command: ['sh', '-c', 'while true; do echo Hello Kubernetes!; sleep 10; done'] 16 | -------------------------------------------------------------------------------- /01-pod/code/my-nginx-pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: my-nginx-pod 5 | labels: 6 | app: mynginxapp 7 | spec: 8 | containers: 9 | - name: my-nginx-container 10 | image: nginx:latest 11 | ports: 12 | - containerPort: 80 -------------------------------------------------------------------------------- /01-pod/code/my-pods-limited.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: my-nginx-limited-pod 5 | labels: 6 | app: nginx 7 | spec: 8 | containers: 9 | - name: my-nginx-container 10 | image: nginx:latest 11 | ports: 12 | - containerPort: 80 13 | resources: 14 | requests: 15 | memory: "128Mi" 16 | cpu: "500m" 17 | limits: 18 | memory: "256Mi" 19 | cpu: "1" 20 | -------------------------------------------------------------------------------- /01-pod/docker-container-id.md: -------------------------------------------------------------------------------- 1 | Docker container IDs are typically 64 characters long, but you can use a shortened version of the ID, as the first 12 characters (or more) are usually sufficient for uniqueness. Here’s how to use a shortened container ID: 2 | 3 | ### Using Shortened Container IDs 4 | 5 | #### Example: 6 | 1. **List All Containers:** 7 | ```bash 8 | docker ps 9 | ``` 10 | 11 | This command shows the list of running containers. Example output might look like this: 12 | 13 | ``` 14 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 15 | 3c5e8827c95f myapp:latest "python app.py" 5 minutes ago Up 5 minutes 0.0.0.0:5000->5000 myapp 16 | 5c8f6a1bdeb3 nginx "nginx -g 'daemon..." 10 minutes ago Up 10 minutes 0.0.0.0:80->80 webserver 17 | ``` 18 | 19 | 2. **Using Shortened Container ID in Commands:** 20 | You can use the **first 12 characters** (or a sufficient portion) of the container ID to execute commands: 21 | 22 | ```bash 23 | docker logs 3c5e8827c95f 24 | ``` 25 | 26 | or 27 | 28 | ```bash 29 | docker stop 3c5e8827c 30 | ``` 31 | 32 | ### Important Notes: 33 | - The ***first 12 characters of the container ID*** are usually sufficient, but if there are multiple containers with similar IDs, you may need to use a longer portion. 34 | - When using a shortened ID, Docker will automatically complete the ID for you. 35 | 36 | ### Example Usage of Shortened IDs: 37 | - Checking the container's status: 38 | ```bash 39 | docker inspect 3c5e8827c95f 40 | ``` 41 | 42 | - Removing a container: 43 | ```bash 44 | docker rm 5c8f6a1bdeb3 45 | ``` 46 | 47 | This way, you can use shortened Docker container IDs for easier command execution. -------------------------------------------------------------------------------- /02-node/01-node-command.md: -------------------------------------------------------------------------------- 1 | Here’s a comprehensive list of commonly used `kubectl` commands related to managing nodes in a Kubernetes cluster: 2 | 3 | ### Basic Node Commands 4 | 5 | 1. **List all nodes:** 6 | ```bash 7 | kubectl get nodes 8 | ``` 9 | 10 | 2. **Describe a specific node:** 11 | ```bash 12 | kubectl describe node 13 | ``` 14 | 15 | 3. **Get node details in YAML format:** 16 | ```bash 17 | kubectl get nodes -o yaml 18 | ``` 19 | 20 | 4. **Get node details in JSON format:** 21 | ```bash 22 | kubectl get nodes -o json 23 | ``` 24 | 25 | ### Node Management Commands 26 | 27 | 5. **Drain a node (mark it as unschedulable):** 28 | ```bash 29 | kubectl drain --ignore-daemonsets 30 | ``` 31 | 32 | 6. **Uncordon a node (mark it as schedulable again):** 33 | ```bash 34 | kubectl uncordon 35 | ``` 36 | 37 | 7. **Delete a node from the cluster:** 38 | ```bash 39 | kubectl delete node 40 | ``` 41 | 42 | 8. **Label a node:** 43 | ```bash 44 | kubectl label nodes = 45 | ``` 46 | 47 | 9. **Remove a label from a node:** 48 | ```bash 49 | kubectl label nodes - 50 | ``` 51 | 52 | ### Node Status and Resource Monitoring 53 | 54 | 10. **Get detailed status of nodes:** 55 | ```bash 56 | kubectl get nodes -o wide 57 | ``` 58 | 59 | 11. **Check resource usage for nodes (requires metrics server):** 60 | ```bash 61 | kubectl top nodes 62 | ``` 63 | 64 | ### Filtering and Sorting 65 | 66 | 12. **List nodes with specific labels:** 67 | ```bash 68 | kubectl get nodes --selector== 69 | ``` 70 | 71 | 13. **Sort nodes by specific fields (e.g., status):** 72 | ```bash 73 | kubectl get nodes --sort-by=.status.conditions[?(@.type=="Ready")].status 74 | ``` 75 | 76 | ### Additional Useful Commands 77 | 78 | 14. **Get a specific node's labels:** 79 | ```bash 80 | kubectl get node --show-labels 81 | ``` 82 | 83 | 15. **Get a node’s conditions:** 84 | ```bash 85 | kubectl get node -o=jsonpath='{.status.conditions[*].type}' 86 | ``` 87 | 88 | 16. **View events related to a node:** 89 | ```bash 90 | kubectl get events --field-selector involvedObject.kind=Node,involvedObject.name= 91 | ``` 92 | 93 | ### Example Usage 94 | 95 | ```bash 96 | # List all nodes 97 | kubectl get nodes 98 | 99 | # Get details of a specific node 100 | kubectl describe node node-1 101 | 102 | # Drain a node for maintenance 103 | kubectl drain node-1 --ignore-daemonsets 104 | 105 | # Uncordon a node after maintenance 106 | kubectl uncordon node-1 107 | 108 | # Add a label to a node 109 | kubectl label nodes node-1 environment=production 110 | 111 | # Get resource usage of nodes 112 | kubectl top nodes 113 | ``` 114 | 115 | ### Summary 116 | These commands are essential for managing nodes in a Kubernetes environment. You can always refer to the official Kubernetes documentation for more advanced usage and additional options. -------------------------------------------------------------------------------- /03-kubelet/01-kubelet.md: -------------------------------------------------------------------------------- 1 | Kubelet is one of the most critical components in the Kubernetes ecosystem. Kubernetes is an orchestration platform for managing containerized applications, and Kubelet acts as an agent running on the nodes of this platform. Here’s a detailed overview of Kubelet: 2 | 3 | ### 1. **Definition and Function** 4 | Kubelet is a background service that runs on Kubernetes nodes. Its primary function is to ensure that containers are running on the specified node. Kubelet interacts with the Kubernetes API server to update the node's status information and manage application containers. 5 | 6 | ### 2. **Main Responsibilities** 7 | Kubelet has several key responsibilities: 8 | 9 | - **Pod Management:** Kubelet creates, updates, and deletes Kubernetes pods (the smallest deployment unit consisting of one or more containers). It monitors the health status of the pods. 10 | - **Status Monitoring:** Kubelet continuously monitors the status of the running pods and containers. If a container fails, Kubelet can restart it. 11 | - **Communication with the API:** Kubelet maintains constant communication with the Kubernetes API server, reporting the state of the node and its pods. 12 | - **Container Launching:** Kubelet starts and manages containers using a specified container runtime (e.g., Docker, containerd). 13 | 14 | ### 3. **Kubelet Configuration** 15 | Kubelet can be customized through various configuration options. These include: 16 | 17 | - **Kubelet Flags:** Kubelet can be started with specific flags that determine its operational behavior (e.g., port numbers, polling intervals, etc.). 18 | - **Container Runtime:** Specifies which container runtime to use (e.g., Docker, containerd). 19 | - **YAML Configuration File:** A YAML file can be used to manage Kubelet configuration more comprehensively. 20 | 21 | ### 4. **Kubelet and Kube-Proxy Relationship** 22 | Kubelet often works alongside kube-proxy. While Kubelet manages the status and updates of the pods, kube-proxy handles the routing of traffic to those pods, managing the services within Kubernetes. 23 | 24 | ### 5. **Health Checks** 25 | Kubelet performs two types of health checks to monitor container health: 26 | 27 | - **Liveness Probe:** Checks whether a container is still running. If this check fails, Kubelet will restart the container. 28 | - **Readiness Probe:** Checks whether a container is ready to receive traffic. If this check fails, Kubelet will stop routing traffic to that pod. 29 | 30 | ### 6. **Security Features of Kubelet** 31 | Kubelet can incorporate various security features: 32 | 33 | - **RBAC (Role-Based Access Control):** Kubelet can control which users or applications with specific permissions can interact with the API. 34 | - **TLS:** Kubelet can use TLS (Transport Layer Security) to secure communication. 35 | 36 | ### 7. **Common Issues with Kubelet** 37 | Some common issues related to Kubelet and their solutions include: 38 | 39 | - **Container Startup Issues:** If a container fails to start, Kubelet logs should be checked for insights. 40 | - **Pod Status:** If a pod remains in the "Pending" state, it may indicate insufficient resources or communication issues between Kubelet and the API server. 41 | 42 | ### 8. **Conclusion** 43 | Kubelet is a fundamental building block of the Kubernetes architecture. It plays a critical role in managing and monitoring containers. Proper configuration and management of Kubelet are essential for the healthy operation of a Kubernetes environment. 44 | 45 | ### 9. **Resources** 46 | For more information and in-depth study, the official Kubernetes documentation and community resources are recommended: 47 | 48 | - [Kubernetes Official Documentation](https://kubernetes.io/docs/home/) 49 | - [Kubelet Reference Documentation](https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/) 50 | 51 | If you have any questions or need further details, feel free to ask! -------------------------------------------------------------------------------- /03-kubelet/02-kube-proxy.md: -------------------------------------------------------------------------------- 1 | Kube-proxy is an essential component of the Kubernetes architecture that manages network traffic routing. When Kubernetes manages a series of containerized applications, kube-proxy directs incoming traffic to the appropriate pods. Here’s a detailed overview of kube-proxy: 2 | 3 | ### 1. **Definition** 4 | Kube-proxy is a network component that runs on Kubernetes nodes. Its primary function is to route incoming network traffic (such as HTTP, TCP, etc.) to the correct pods corresponding to the Kubernetes services. Kube-proxy monitors the IP addresses and statuses of pods to ensure that requests are directed appropriately. 5 | 6 | ### 2. **Main Responsibilities** 7 | The main responsibilities of kube-proxy include: 8 | 9 | - **Traffic Routing:** Kube-proxy directs incoming requests to the appropriate pods, enabling load balancing among them. 10 | - **Service Definitions:** It defines Kubernetes services and determines which pods the services will route to. 11 | - **Status Monitoring:** Kube-proxy monitors the status of pods and can automatically redirect traffic to another healthy pod if one pod fails. 12 | 13 | ### 3. **Operating Modes** 14 | Kube-proxy can operate in different modes: 15 | 16 | - **iptables Mode:** In this mode, kube-proxy uses the Linux iptables feature to create rules for routing incoming traffic. This method typically offers high performance. 17 | - **IPVS Mode:** The IP Virtual Server (IPVS) mode provides more advanced load balancing functionality. IPVS can handle more connections and manage performance more efficiently. 18 | - **Userspace Mode:** This older mode, userspace, involves kube-proxy operating in user space to capture and route incoming requests. It generally offers lower performance and is no longer recommended. 19 | 20 | ### 4. **Security and Access Control** 21 | Kube-proxy has certain security features when managing network traffic. It integrates with Kubernetes' Role-Based Access Control (RBAC) system to determine which users and applications can route traffic and how. 22 | 23 | ### 5. **Common Issues and Solutions** 24 | Some common issues related to kube-proxy include: 25 | 26 | - **Routing Issues:** If traffic is not being routed correctly, kube-proxy logs should be reviewed, and service definitions should be checked. 27 | - **Pod Status:** If pods do not appear healthy or cannot route traffic, it should be verified whether kube-proxy is updating the pod statuses properly. 28 | 29 | ### 6. **Conclusion** 30 | Kube-proxy plays a critical role in managing network traffic within a Kubernetes environment. It is necessary for facilitating communication between applications and performing load balancing. Proper configuration and management of kube-proxy directly impact the performance of Kubernetes applications. 31 | 32 | If you have any questions or would like further information, feel free to ask! -------------------------------------------------------------------------------- /03-kubelet/03-kubelet-logs.md: -------------------------------------------------------------------------------- 1 | Monitoring kubelet logs is essential for understanding the state of your Kubernetes cluster and troubleshooting issues. Kubelet logs provide insights into the status of the node, the status of pods, and other critical events. Here’s how to view kubelet logs: 2 | 3 | ### 1. **Location of Kubelet Logs** 4 | Kubelet logs are typically located in the system's log directory. Kubelet usually logs either to the system journal or to a specific log file. 5 | 6 | #### a. **Using Systemd** 7 | If kubelet is managed by systemd, you can use the `journalctl` command to view the logs: 8 | 9 | ```bash 10 | journalctl -u kubelet 11 | ``` 12 | 13 | This command will show the kubelet service logs along with timestamps. If you only want to see the last few lines, you can add the `-n` option: 14 | 15 | ```bash 16 | journalctl -u kubelet -n 100 17 | ``` 18 | 19 | #### b. **Using Log Files** 20 | If kubelet writes logs directly to a log file (for example, `/var/log/kubelet.log`), you can view this file directly using commands like `cat`, `tail`, or `less`: 21 | 22 | ```bash 23 | tail -f /var/log/kubelet.log 24 | ``` 25 | 26 | ### 2. **Log Filtering** 27 | Kubelet logs can be verbose. You can use the `grep` command to filter for specific errors or events: 28 | 29 | ```bash 30 | journalctl -u kubelet | grep "error" 31 | ``` 32 | 33 | This command will display lines in the kubelet logs that contain the word "error." 34 | 35 | ### 3. **Log Levels** 36 | Kubelet allows you to adjust log levels using the `--v` flag. Log levels range from 0 (least verbose) to 10 (most verbose). If you want kubelet to log more detailed information, you can set it to a higher level, such as `--v=4`, in the kubelet configuration file or startup command. 37 | 38 | ### 4. **Using Kubernetes Dashboard or Monitoring Tools** 39 | If you are using a monitoring or management tool for your Kubernetes cluster (like Grafana, Prometheus, or the Kubernetes Dashboard), you can also monitor kubelet logs and status through these tools. Such tools allow for better visualization and analysis of the logs. 40 | 41 | ### 5. **Conclusion** 42 | Monitoring kubelet logs is crucial for tracking the health of your Kubernetes environment. Using the methods outlined above, you can view logs and obtain the necessary information to diagnose issues. If you need further assistance, feel free to ask! -------------------------------------------------------------------------------- /03-kubelet/04-kubelet-status-start-stop.md: -------------------------------------------------------------------------------- 1 | Kubelet is a critical component that runs on Kubernetes nodes and is typically managed by systemd. You can start or stop kubelet using the following steps: 2 | 3 | ### Starting and Stopping Kubelet 4 | 5 | #### 1. **Using Systemd to Start/Stop Kubelet** 6 | If kubelet is managed by systemd, you can use the `systemctl` command to control its state. 7 | 8 | - **Start Kubelet:** 9 | ```bash 10 | sudo systemctl start kubelet 11 | ``` 12 | 13 | - **Stop Kubelet:** 14 | ```bash 15 | sudo systemctl stop kubelet 16 | ``` 17 | 18 | - **Check Kubelet Status:** 19 | To check the current status of kubelet, you can use: 20 | ```bash 21 | sudo systemctl status kubelet 22 | ``` 23 | 24 | - **Restart Kubelet:** 25 | To restart kubelet, use: 26 | ```bash 27 | sudo systemctl restart kubelet 28 | ``` 29 | 30 | #### 2. **View Logs** 31 | After starting or stopping kubelet, you might want to review the logs to ensure everything is functioning correctly. You can do this using `journalctl`: 32 | 33 | ```bash 34 | journalctl -u kubelet -f 35 | ``` 36 | 37 | This command will display the logs for the kubelet service in real time. 38 | 39 | ### 3. **Enable Kubelet to Start Automatically on Boot** 40 | If you want kubelet to start automatically when the system boots, you can enable this feature with the following command: 41 | 42 | ```bash 43 | sudo systemctl enable kubelet 44 | ``` 45 | 46 | ### 4. **Important Notes** 47 | - Stopping kubelet can impact the operation of pods running on that node, so you should consider this before stopping it. 48 | - The methods for starting and stopping kubelet may vary based on your system configuration and deployment method. 49 | 50 | If you have any further questions or need additional assistance, feel free to ask! -------------------------------------------------------------------------------- /03-kubelet/kubelet-command-list.md: -------------------------------------------------------------------------------- 1 | Kubelet is a key component of Kubernetes responsible for managing the lifecycle of pods on a node. It communicates with the Kubernetes API server to ensure that the desired state of the system matches the actual state. Below is a list of commonly used kubelet commands along with brief descriptions. 2 | 3 | ### Kubelet Command List 4 | 5 | 1. **Start the Kubelet** 6 | ```bash 7 | kubelet 8 | ``` 9 | Starts the kubelet service on the node. 10 | 11 | 2. **Get the Kubelet version** 12 | ```bash 13 | kubelet --version 14 | ``` 15 | Displays the version of the kubelet. 16 | 17 | 3. **Check Kubelet logs** 18 | ```bash 19 | journalctl -u kubelet 20 | ``` 21 | Displays the logs of the kubelet service. 22 | 23 | 4. **Set the Kubelet configuration file** 24 | ```bash 25 | kubelet --config=/path/to/kubelet-config.yaml 26 | ``` 27 | Specifies a configuration file for the kubelet. 28 | 29 | 5. **Run in the foreground** 30 | ```bash 31 | kubelet --v=2 32 | ``` 33 | Runs the kubelet in the foreground with a specified verbosity level for logging. 34 | 35 | 6. **Register the node** 36 | ```bash 37 | kubelet --register-node=true 38 | ``` 39 | Registers the node with the Kubernetes cluster. 40 | 41 | 7. **Health check** 42 | ```bash 43 | curl http://localhost:10255/healthz 44 | ``` 45 | Checks the health of the kubelet (the default health check endpoint). 46 | 47 | 8. **Get the list of pods running on the node** 48 | ```bash 49 | curl http://localhost:10255/pods 50 | ``` 51 | Retrieves information about all pods managed by the kubelet on that node. 52 | 53 | 9. **List containers** 54 | ```bash 55 | docker ps 56 | ``` 57 | If using Docker, this command lists all containers running on the node. Note that this may vary depending on the container runtime. 58 | 59 | 10. **Restart Kubelet** 60 | ```bash 61 | systemctl restart kubelet 62 | ``` 63 | Restarts the kubelet service (for systems using systemd). 64 | 65 | 11. **Check Kubelet configuration** 66 | ```bash 67 | kubelet --help 68 | ``` 69 | Displays help information about kubelet command-line options and flags. 70 | 71 | ### Common Kubelet Flags 72 | 73 | - **`--kubeconfig`**: Path to the kubeconfig file used to connect to the API server. 74 | - **`--cgroup-driver`**: Specifies the cgroup driver to use (e.g., `cgroupfs`, `systemd`). 75 | - **`--pod-manifest-path`**: Path to a directory containing static pod manifests. 76 | - **`--container-runtime`**: Specifies the container runtime to use (e.g., `docker`, `remote`). 77 | - **`--register-with-taints`**: Taints to apply to the node when registering it with the API server. 78 | 79 | ### Important Notes 80 | 81 | - Kubelet is usually managed as a system service. The actual command to start it may be included in a service file, so you might not need to start it manually. 82 | - The specific options and flags available may depend on the version of Kubernetes you are using. 83 | 84 | For more detailed information about kubelet commands and options, refer to the [Kubernetes official documentation](https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/). 85 | 86 | If you have any specific questions or need further details, feel free to ask! -------------------------------------------------------------------------------- /04-service/01-service-command.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, services are essential for enabling communication between different components and applications. Here’s a list of common `kubectl` commands related to services, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Services 4 | 5 | 1. **List Services** 6 | ```bash 7 | kubectl get services 8 | ``` 9 | - Lists all the services in the current namespace. 10 | 11 | 2. **Describe a Service** 12 | ```bash 13 | kubectl describe service 14 | ``` 15 | - Provides detailed information about a specific service, including its endpoints and configuration. 16 | 17 | 3. **Create a Service** 18 | ```bash 19 | kubectl expose deployment --type= --name= 20 | ``` 21 | - Exposes a deployment as a service. The `` can be `ClusterIP`, `NodePort`, or `LoadBalancer`. 22 | 23 | 4. **Delete a Service** 24 | ```bash 25 | kubectl delete service 26 | ``` 27 | - Deletes a specified service. 28 | 29 | 5. **Edit a Service** 30 | ```bash 31 | kubectl edit service 32 | ``` 33 | - Opens the service configuration in your default text editor for inline editing. 34 | 35 | 6. **Scale a Service** 36 | ```bash 37 | kubectl scale deployment --replicas= 38 | ``` 39 | - Scales a deployment, which indirectly affects the service associated with it. 40 | 41 | 7. **Get Service YAML/JSON** 42 | ```bash 43 | kubectl get service -o yaml 44 | ``` 45 | - Retrieves the service configuration in YAML format. 46 | 47 | ```bash 48 | kubectl get service -o json 49 | ``` 50 | - Retrieves the service configuration in JSON format. 51 | 52 | 8. **Get Endpoints** 53 | ```bash 54 | kubectl get endpoints 55 | ``` 56 | - Lists the endpoints associated with the specified service. 57 | 58 | 9. **Get Services in All Namespaces** 59 | ```bash 60 | kubectl get services --all-namespaces 61 | ``` 62 | - Lists all services across all namespaces. 63 | 64 | 10. **Port Forwarding to a Service** 65 | ```bash 66 | kubectl port-forward service/ : 67 | ``` 68 | - Forwards a local port to a port on a service. 69 | 70 | ### Example of Service Creation 71 | 72 | Here's an example of how to create a service using a YAML file: 73 | 74 | 1. **Create a YAML file (e.g., `my-service.yaml`)**: 75 | ```yaml 76 | apiVersion: v1 77 | kind: Service 78 | metadata: 79 | name: my-service 80 | spec: 81 | selector: 82 | app: my-app 83 | ports: 84 | - protocol: TCP 85 | port: 80 86 | targetPort: 8080 87 | type: ClusterIP 88 | ``` 89 | 90 | 2. **Apply the YAML file**: 91 | ```bash 92 | kubectl apply -f my-service.yaml 93 | ``` 94 | 95 | ### Summary 96 | 97 | These commands provide a comprehensive toolkit for managing services in Kubernetes. Depending on your specific needs, you can create, modify, and monitor services to ensure your applications are accessible and function as expected. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /05-deployment/deployment-command.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, deployments are used to manage the deployment of applications, ensuring that the desired number of replicas of a pod are running at all times. Below is a list of common `kubectl` commands related to deployments, along with brief descriptions: 2 | 3 | ### Common `kubectl` Commands for Deployments 4 | 5 | 1. **List Deployments** 6 | ```bash 7 | kubectl get deployments 8 | ``` 9 | - Lists all deployments in the current namespace. 10 | 11 | 2. **Describe a Deployment** 12 | ```bash 13 | kubectl describe deployment 14 | ``` 15 | - Provides detailed information about a specific deployment, including its strategy, replicas, and events. 16 | 17 | 3. **Create a Deployment** 18 | ```bash 19 | kubectl create deployment --image= 20 | ``` 21 | - Creates a new deployment using the specified image. 22 | 23 | 4. **Update a Deployment** 24 | ```bash 25 | kubectl set image deployment/ = 26 | ``` 27 | - Updates the image of a specified container within the deployment. 28 | 29 | 5. **Scale a Deployment** 30 | ```bash 31 | kubectl scale deployment --replicas= 32 | ``` 33 | - Scales the number of replicas for a deployment. 34 | 35 | 6. **Rollback a Deployment** 36 | ```bash 37 | kubectl rollout undo deployment/ 38 | ``` 39 | - Rolls back to the previous version of a deployment. 40 | 41 | 7. **Check Rollout Status** 42 | ```bash 43 | kubectl rollout status deployment/ 44 | ``` 45 | - Checks the status of a deployment rollout. 46 | 47 | 8. **Get Deployment YAML/JSON** 48 | ```bash 49 | kubectl get deployment -o yaml 50 | ``` 51 | - Retrieves the deployment configuration in YAML format. 52 | 53 | ```bash 54 | kubectl get deployment -o json 55 | ``` 56 | - Retrieves the deployment configuration in JSON format. 57 | 58 | 9. **Delete a Deployment** 59 | ```bash 60 | kubectl delete deployment 61 | ``` 62 | - Deletes a specified deployment. 63 | 64 | 10. **Edit a Deployment** 65 | ```bash 66 | kubectl edit deployment 67 | ``` 68 | - Opens the deployment configuration in your default text editor for inline editing. 69 | 70 | 11. **View Deployment History** 71 | ```bash 72 | kubectl rollout history deployment/ 73 | ``` 74 | - Displays the rollout history of a deployment. 75 | 76 | 12. **Pause a Deployment** 77 | ```bash 78 | kubectl rollout pause deployment/ 79 | ``` 80 | - Pauses a deployment, preventing further changes. 81 | 82 | 13. **Resume a Deployment** 83 | ```bash 84 | kubectl rollout resume deployment/ 85 | ``` 86 | - Resumes a paused deployment. 87 | 88 | ### Example of Deployment Creation 89 | 90 | Here's an example of how to create a deployment using a YAML file: 91 | 92 | 1. **Create a YAML file (e.g., `my-deployment.yaml`)**: 93 | ```yaml 94 | apiVersion: apps/v1 95 | kind: Deployment 96 | metadata: 97 | name: my-deployment 98 | spec: 99 | replicas: 3 100 | selector: 101 | matchLabels: 102 | app: my-app 103 | template: 104 | metadata: 105 | labels: 106 | app: my-app 107 | spec: 108 | containers: 109 | - name: my-container 110 | image: my-image:latest 111 | ports: 112 | - containerPort: 8080 113 | ``` 114 | 115 | 2. **Apply the YAML file**: 116 | ```bash 117 | kubectl apply -f my-deployment.yaml 118 | ``` 119 | 120 | ### Summary 121 | 122 | These commands provide a comprehensive toolkit for managing deployments in Kubernetes. Depending on your needs, you can create, update, scale, and monitor your applications effectively. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /06-replicaset/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a ReplicaSet ensures that a specified number of pod replicas are running at any given time. It is often used as part of a Deployment, but you can also manage ReplicaSets directly. Here’s a list of common `kubectl` commands related to ReplicaSets, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for ReplicaSets 4 | 5 | 1. **List ReplicaSets** 6 | ```bash 7 | kubectl get replicasets 8 | ``` 9 | - Lists all ReplicaSets in the current namespace. 10 | 11 | 2. **Describe a ReplicaSet** 12 | ```bash 13 | kubectl describe replicaset 14 | ``` 15 | - Provides detailed information about a specific ReplicaSet, including its pods and labels. 16 | 17 | 3. **Create a ReplicaSet** 18 | ```bash 19 | kubectl create -f 20 | ``` 21 | - Creates a new ReplicaSet based on the provided YAML file. 22 | 23 | 4. **Scale a ReplicaSet** 24 | ```bash 25 | kubectl scale replicaset --replicas= 26 | ``` 27 | - Scales the number of replicas for the specified ReplicaSet. 28 | 29 | 5. **Get ReplicaSet YAML/JSON** 30 | ```bash 31 | kubectl get replicaset -o yaml 32 | ``` 33 | - Retrieves the ReplicaSet configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get replicaset -o json 37 | ``` 38 | - Retrieves the ReplicaSet configuration in JSON format. 39 | 40 | 6. **Delete a ReplicaSet** 41 | ```bash 42 | kubectl delete replicaset 43 | ``` 44 | - Deletes a specified ReplicaSet. 45 | 46 | 7. **Edit a ReplicaSet** 47 | ```bash 48 | kubectl edit replicaset 49 | ``` 50 | - Opens the ReplicaSet configuration in your default text editor for inline editing. 51 | 52 | 8. **Get Pods Managed by a ReplicaSet** 53 | ```bash 54 | kubectl get pods --selector= 55 | ``` 56 | - Lists all pods managed by a specific ReplicaSet using label selectors. 57 | 58 | 9. **View ReplicaSet Status** 59 | ```bash 60 | kubectl get replicaset -o wide 61 | ``` 62 | - Provides a more detailed view of the ReplicaSet status, including pod IPs. 63 | 64 | 10. **Check ReplicaSet Events** 65 | ```bash 66 | kubectl get events --field-selector involvedObject.kind=ReplicaSet,involvedObject.name= 67 | ``` 68 | - Displays events related to the specified ReplicaSet. 69 | 70 | ### Example of ReplicaSet Creation 71 | 72 | Here's an example of how to create a ReplicaSet using a YAML file: 73 | 74 | 1. **Create a YAML file (e.g., `my-replicaset.yaml`)**: 75 | ```yaml 76 | apiVersion: apps/v1 77 | kind: ReplicaSet 78 | metadata: 79 | name: my-replicaset 80 | spec: 81 | replicas: 3 82 | selector: 83 | matchLabels: 84 | app: my-app 85 | template: 86 | metadata: 87 | labels: 88 | app: my-app 89 | spec: 90 | containers: 91 | - name: my-container 92 | image: my-image:latest 93 | ports: 94 | - containerPort: 8080 95 | ``` 96 | 97 | 2. **Apply the YAML file**: 98 | ```bash 99 | kubectl apply -f my-replicaset.yaml 100 | ``` 101 | 102 | ### Summary 103 | 104 | These commands provide a comprehensive toolkit for managing ReplicaSets in Kubernetes. They help ensure that your applications have the desired number of replicas running at all times. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /07-namespaces/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, namespaces are a way to organize and manage resources in a cluster. They provide a mechanism for isolating groups of resources and can be particularly useful in multi-tenant environments. Here’s a list of common `kubectl` commands related to namespaces, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Namespaces 4 | 5 | 1. **List Namespaces** 6 | ```bash 7 | kubectl get namespaces 8 | ``` 9 | - Lists all namespaces in the cluster. 10 | 11 | 2. **Describe a Namespace** 12 | ```bash 13 | kubectl describe namespace 14 | ``` 15 | - Provides detailed information about a specific namespace. 16 | 17 | 3. **Create a Namespace** 18 | ```bash 19 | kubectl create namespace 20 | ``` 21 | - Creates a new namespace. 22 | 23 | 4. **Delete a Namespace** 24 | ```bash 25 | kubectl delete namespace 26 | ``` 27 | - Deletes a specified namespace and all resources within it. 28 | 29 | 5. **Get Resources in a Specific Namespace** 30 | ```bash 31 | kubectl get all -n 32 | ``` 33 | - Lists all resources (pods, services, deployments, etc.) in the specified namespace. 34 | 35 | 6. **Set the Default Namespace for kubectl** 36 | ```bash 37 | kubectl config set-context --current --namespace= 38 | ``` 39 | - Sets the default namespace for the current context, so you don't have to specify `-n ` with each command. 40 | 41 | 7. **Get Pods in a Specific Namespace** 42 | ```bash 43 | kubectl get pods -n 44 | ``` 45 | - Lists all pods in the specified namespace. 46 | 47 | 8. **Get Services in a Specific Namespace** 48 | ```bash 49 | kubectl get services -n 50 | ``` 51 | - Lists all services in the specified namespace. 52 | 53 | 9. **Get Deployments in a Specific Namespace** 54 | ```bash 55 | kubectl get deployments -n 56 | ``` 57 | - Lists all deployments in the specified namespace. 58 | 59 | 10. **Get ReplicaSets in a Specific Namespace** 60 | ```bash 61 | kubectl get replicasets -n 62 | ``` 63 | - Lists all ReplicaSets in the specified namespace. 64 | 65 | 11. **Get Events in a Specific Namespace** 66 | ```bash 67 | kubectl get events -n 68 | ``` 69 | - Lists all events in the specified namespace. 70 | 71 | ### Example of Namespace Creation 72 | 73 | Here's an example of how to create a namespace using a YAML file: 74 | 75 | 1. **Create a YAML file (e.g., `my-namespace.yaml`)**: 76 | ```yaml 77 | apiVersion: v1 78 | kind: Namespace 79 | metadata: 80 | name: my-namespace 81 | ``` 82 | 83 | 2. **Apply the YAML file**: 84 | ```bash 85 | kubectl apply -f my-namespace.yaml 86 | ``` 87 | 88 | ### Summary 89 | 90 | These commands provide a comprehensive toolkit for managing namespaces in Kubernetes. They help you organize and isolate resources effectively within your cluster. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /08-configmap/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a ConfigMap is an API object that allows you to store non-confidential configuration data in key-value pairs. This data can be consumed by your applications as environment variables, command-line arguments, or configuration files. Here’s a list of common `kubectl` commands related to ConfigMaps, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for ConfigMaps 4 | 5 | 1. **List ConfigMaps** 6 | ```bash 7 | kubectl get configmaps 8 | ``` 9 | - Lists all ConfigMaps in the current namespace. 10 | 11 | 2. **Describe a ConfigMap** 12 | ```bash 13 | kubectl describe configmap 14 | ``` 15 | - Provides detailed information about a specific ConfigMap, including its data and metadata. 16 | 17 | 3. **Create a ConfigMap from Literal Values** 18 | ```bash 19 | kubectl create configmap --from-literal== 20 | ``` 21 | - Creates a new ConfigMap with key-value pairs specified as literals. 22 | 23 | 4. **Create a ConfigMap from a File** 24 | ```bash 25 | kubectl create configmap --from-file= 26 | ``` 27 | - Creates a new ConfigMap from the contents of a specified file. 28 | 29 | 5. **Create a ConfigMap from a Directory** 30 | ```bash 31 | kubectl create configmap --from-file= 32 | ``` 33 | - Creates a new ConfigMap from all files in the specified directory. 34 | 35 | 6. **Update a ConfigMap** 36 | ```bash 37 | kubectl apply -f 38 | ``` 39 | - Updates an existing ConfigMap using a YAML file. 40 | 41 | 7. **Get ConfigMap YAML/JSON** 42 | ```bash 43 | kubectl get configmap -o yaml 44 | ``` 45 | - Retrieves the ConfigMap configuration in YAML format. 46 | 47 | ```bash 48 | kubectl get configmap -o json 49 | ``` 50 | - Retrieves the ConfigMap configuration in JSON format. 51 | 52 | 8. **Delete a ConfigMap** 53 | ```bash 54 | kubectl delete configmap 55 | ``` 56 | - Deletes a specified ConfigMap. 57 | 58 | 9. **Edit a ConfigMap** 59 | ```bash 60 | kubectl edit configmap 61 | ``` 62 | - Opens the ConfigMap configuration in your default text editor for inline editing. 63 | 64 | 10. **View ConfigMap Data** 65 | ```bash 66 | kubectl get configmap -o jsonpath='{.data}' 67 | ``` 68 | - Retrieves only the data part of the ConfigMap in a specified format. 69 | 70 | ### Example of ConfigMap Creation 71 | 72 | Here's an example of how to create a ConfigMap using a YAML file: 73 | 74 | 1. **Create a YAML file (e.g., `my-configmap.yaml`)**: 75 | ```yaml 76 | apiVersion: v1 77 | kind: ConfigMap 78 | metadata: 79 | name: my-configmap 80 | data: 81 | my-key: my-value 82 | another-key: another-value 83 | ``` 84 | 85 | 2. **Apply the YAML file**: 86 | ```bash 87 | kubectl apply -f my-configmap.yaml 88 | ``` 89 | 90 | ### Summary 91 | 92 | These commands provide a comprehensive toolkit for managing ConfigMaps in Kubernetes. ConfigMaps are useful for decoupling environment-specific configurations from your application code, allowing for more flexible deployments. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /09-secret/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, Secrets are used to store sensitive information, such as passwords, OAuth tokens, and SSH keys. Secrets are encoded in base64 and can be referenced in Pods to avoid exposing sensitive data in your application code. Here’s a list of common `kubectl` commands related to Secrets, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Secrets 4 | 5 | 1. **List Secrets** 6 | ```bash 7 | kubectl get secrets 8 | ``` 9 | - Lists all Secrets in the current namespace. 10 | 11 | 2. **Describe a Secret** 12 | ```bash 13 | kubectl describe secret 14 | ``` 15 | - Provides detailed information about a specific Secret, including its data and metadata. 16 | 17 | 3. **Create a Secret from Literal Values** 18 | ```bash 19 | kubectl create secret generic --from-literal== 20 | ``` 21 | - Creates a new Secret with key-value pairs specified as literals. 22 | 23 | 4. **Create a Secret from a File** 24 | ```bash 25 | kubectl create secret generic --from-file= 26 | ``` 27 | - Creates a new Secret from the contents of a specified file. 28 | 29 | 5. **Create a Secret from a Directory** 30 | ```bash 31 | kubectl create secret generic --from-file= 32 | ``` 33 | - Creates a new Secret from all files in the specified directory. 34 | 35 | 6. **Update a Secret** 36 | ```bash 37 | kubectl apply -f 38 | ``` 39 | - Updates an existing Secret using a YAML file. 40 | 41 | 7. **Get Secret YAML/JSON** 42 | ```bash 43 | kubectl get secret -o yaml 44 | ``` 45 | - Retrieves the Secret configuration in YAML format. 46 | 47 | ```bash 48 | kubectl get secret -o json 49 | ``` 50 | - Retrieves the Secret configuration in JSON format. 51 | 52 | 8. **Delete a Secret** 53 | ```bash 54 | kubectl delete secret 55 | ``` 56 | - Deletes a specified Secret. 57 | 58 | 9. **Edit a Secret** 59 | ```bash 60 | kubectl edit secret 61 | ``` 62 | - Opens the Secret configuration in your default text editor for inline editing. 63 | 64 | 10. **Decode a Secret** 65 | ```bash 66 | kubectl get secret -o jsonpath='{.data.}' | base64 --decode 67 | ``` 68 | - Retrieves and decodes the value of a specific key in the Secret. 69 | 70 | ### Example of Secret Creation 71 | 72 | Here's an example of how to create a Secret using a YAML file: 73 | 74 | 1. **Create a YAML file (e.g., `my-secret.yaml`)**: 75 | ```yaml 76 | apiVersion: v1 77 | kind: Secret 78 | metadata: 79 | name: my-secret 80 | type: Opaque 81 | data: 82 | my-key: bXktcGFzc3dvcmQ= # base64-encoded value of "my-password" 83 | ``` 84 | 85 | 2. **Apply the YAML file**: 86 | ```bash 87 | kubectl apply -f my-secret.yaml 88 | ``` 89 | 90 | ### Summary 91 | 92 | These commands provide a comprehensive toolkit for managing Secrets in Kubernetes. Using Secrets helps protect sensitive data from being exposed in your application's code or configuration files. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /10-docker-environment-update.md: -------------------------------------------------------------------------------- 1 | # Initial Setup of Codespace Environment 2 | 3 | When you first open a Codespace environment, it's crucial to ensure that your package manager is up to date. Running the following commands will help keep your system secure and stable: 4 | 5 | ## Step 1: Update Package Lists 6 | 7 | Use the command below to refresh your package database, allowing your system to know about the latest available packages and their versions: 8 | 9 | ```bash 10 | sudo apt update 11 | ``` 12 | 13 | - **What it does:** This command updates the list of packages in your repositories. It does not install or upgrade any packages yet but prepares the system for that action. 14 | 15 | ## Step 2: Upgrade Installed Packages 16 | 17 | After updating the package list, you should upgrade any outdated packages using: 18 | 19 | ```bash 20 | sudo apt upgrade 21 | ``` 22 | 23 | - **What it does:** This command installs the latest versions of all packages currently installed on your system. It ensures that any security vulnerabilities and bugs are patched, enhancing system stability and performance. 24 | 25 | ## Why It Matters 26 | 27 | 1. **Security:** Keeping your packages updated minimizes security risks by ensuring you have the latest security patches. 28 | 2. **Stability:** Upgrading packages reduces the likelihood of bugs and compatibility issues with new software you might install later. 29 | 3. **Access to New Features:** Upgraded packages often include new features and improvements that can enhance your development experience. 30 | 31 | ## Conclusion 32 | 33 | Running `sudo apt update` followed by `sudo apt upgrade` is a simple yet effective practice to maintain your Codespace environment. Always remember to perform these steps whenever you start a new session to ensure a smooth and secure development experience. 34 | -------------------------------------------------------------------------------- /10-volume/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, Secrets are used to store sensitive information, such as passwords, OAuth tokens, and SSH keys. Secrets are encoded in base64 and can be referenced in Pods to avoid exposing sensitive data in your application code. Here’s a list of common `kubectl` commands related to Secrets, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Secrets 4 | 5 | 1. **List Secrets** 6 | ```bash 7 | kubectl get secrets 8 | ``` 9 | - Lists all Secrets in the current namespace. 10 | 11 | 2. **Describe a Secret** 12 | ```bash 13 | kubectl describe secret 14 | ``` 15 | - Provides detailed information about a specific Secret, including its data and metadata. 16 | 17 | 3. **Create a Secret from Literal Values** 18 | ```bash 19 | kubectl create secret generic --from-literal== 20 | ``` 21 | - Creates a new Secret with key-value pairs specified as literals. 22 | 23 | 4. **Create a Secret from a File** 24 | ```bash 25 | kubectl create secret generic --from-file= 26 | ``` 27 | - Creates a new Secret from the contents of a specified file. 28 | 29 | 5. **Create a Secret from a Directory** 30 | ```bash 31 | kubectl create secret generic --from-file= 32 | ``` 33 | - Creates a new Secret from all files in the specified directory. 34 | 35 | 6. **Update a Secret** 36 | ```bash 37 | kubectl apply -f 38 | ``` 39 | - Updates an existing Secret using a YAML file. 40 | 41 | 7. **Get Secret YAML/JSON** 42 | ```bash 43 | kubectl get secret -o yaml 44 | ``` 45 | - Retrieves the Secret configuration in YAML format. 46 | 47 | ```bash 48 | kubectl get secret -o json 49 | ``` 50 | - Retrieves the Secret configuration in JSON format. 51 | 52 | 8. **Delete a Secret** 53 | ```bash 54 | kubectl delete secret 55 | ``` 56 | - Deletes a specified Secret. 57 | 58 | 9. **Edit a Secret** 59 | ```bash 60 | kubectl edit secret 61 | ``` 62 | - Opens the Secret configuration in your default text editor for inline editing. 63 | 64 | 10. **Decode a Secret** 65 | ```bash 66 | kubectl get secret -o jsonpath='{.data.}' | base64 --decode 67 | ``` 68 | - Retrieves and decodes the value of a specific key in the Secret. 69 | 70 | ### Example of Secret Creation 71 | 72 | Here's an example of how to create a Secret using a YAML file: 73 | 74 | 1. **Create a YAML file (e.g., `my-secret.yaml`)**: 75 | ```yaml 76 | apiVersion: v1 77 | kind: Secret 78 | metadata: 79 | name: my-secret 80 | type: Opaque 81 | data: 82 | my-key: bXktcGFzc3dvcmQ= # base64-encoded value of "my-password" 83 | ``` 84 | 85 | 2. **Apply the YAML file**: 86 | ```bash 87 | kubectl apply -f my-secret.yaml 88 | ``` 89 | 90 | ### Summary 91 | 92 | These commands provide a comprehensive toolkit for managing Secrets in Kubernetes. Using Secrets helps protect sensitive data from being exposed in your application's code or configuration files. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /100-kubernetes-objects.md: -------------------------------------------------------------------------------- 1 | # Kubrenetes Objetcs List 2 | 3 | | **Kubernetes Object** | **Description** | **Purpose** | 4 | |----------------------------|-----------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------| 5 | | **Pod** | The smallest and simplest unit of deployment in Kubernetes. It contains one or more containers.| Units where applications run. Each pod runs one or more containers. | 6 | | **Service** | Provides access to Pods from outside or within the cluster. | Allows Pods to receive traffic from other applications or users. | 7 | | **Deployment** | An object used to manage and update Pods. | Manages scaling, updating, and redeploying operations. | 8 | | **StatefulSet** | An object used for stateful applications. | Used to run applications that require state (e.g., databases). | 9 | | **DaemonSet** | An object used to ensure that a copy of a Pod runs on each node in the cluster. | Functions that must be present on every node, such as network components or monitoring agents.| 10 | | **ReplicaSet** | An object that ensures a specified number of Pods are running. | Maintains the number of Pod replicas and automatically recreates them when needed. | 11 | | **Job** | An object used to run one-off tasks. | Used for scheduled or one-time jobs. | 12 | | **CronJob** | An object used for scheduled tasks. | Runs jobs at specific time intervals or at specified times. | 13 | | **ConfigMap** | Stores configuration data for applications. | Holds configuration files, command-line arguments, or environment variables. | 14 | | **Secret** | Ensures sensitive information is stored securely. | Safely stores passwords, API keys, or other sensitive data. | 15 | | **PersistentVolume (PV)** | Defines storage resources that are independent of the lifecycle of Pods. | Ensures persistent storage within the cluster. | 16 | | **PersistentVolumeClaim (PVC)**| An object that allows users to request persistent storage. | Enables Pods to interact with persistent storage volumes. | 17 | | **Ingress** | An object used to route HTTP and HTTPS requests. | Directs incoming web traffic to Pods. | 18 | | **NetworkPolicy** | Controls network traffic between Pods or between Pods and other network components. | Used to isolate or restrict network traffic. | 19 | | **Namespace** | Provides a mechanism for logically separating Kubernetes resources. | Manages resources in distinct sections, provides access control, and organizes resources. | 20 | | **Role/ClusterRole** | Grants permissions on specific resources to users or service accounts. | Used to define permissions and manage access control. | 21 | | **RoleBinding/ClusterRoleBinding** | Associates roles with users or service accounts. | Used to perform authorization tasks. | -------------------------------------------------------------------------------- /101-kubernetes-objects-all.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Keywords List 2 | 3 | ### 1. **Pod** 4 | - The smallest deployable unit in Kubernetes. It can host one or more containers. 5 | 6 | ### 2. **Node** 7 | - Each physical or virtual machine in a Kubernetes cluster that represents the environment where Pods run. 8 | 9 | ### 3. **Kubelet** 10 | - An agent that runs on each node and manages the state of Pods. 11 | 12 | ### 4. **Service** 13 | - An abstraction layer used to provide network access to Pods. 14 | 15 | ### 5. **Deployment** 16 | - An object used for managing and scaling Pods. 17 | 18 | ### 6. **ReplicaSet** 19 | - Ensures that a specified number of Pod replicas are running at all times. 20 | 21 | ### 7. **Namespace** 22 | - A mechanism for grouping and isolating resources within a cluster. 23 | 24 | ### 8. **ConfigMap** 25 | - An object used to store application configurations. 26 | 27 | ### 9. **Secret** 28 | - An object used to securely store sensitive information. 29 | 30 | ### 10. **Volume** 31 | - Used for sharing data between Pods and providing persistence. 32 | 33 | ### 11. **Job** 34 | - Used for running one-off tasks. 35 | 36 | ### 12. **CronJob** 37 | - Used for scheduling recurring tasks at specified intervals. 38 | 39 | ### 13. **LoadBalancer** 40 | - A type of service that routes external traffic to the appropriate Pods. 41 | 42 | ### 14. **Ingress** 43 | - A resource for managing external HTTP and HTTPS traffic routing. 44 | 45 | ### 15. **PersistentVolume (PV)** 46 | - A resource type that provides persistent storage space. 47 | 48 | ### 16. **PersistentVolumeClaim (PVC)** 49 | - A resource type that allows users to request persistent disk space. 50 | 51 | ### 17. **StatefulSet** 52 | - Manages stateful applications, ensuring each Pod has a unique identity. 53 | 54 | ### 18. **DaemonSet** 55 | - Ensures that a specific Pod runs on all or some nodes in the cluster. 56 | 57 | ### 19. **Horizontal Pod Autoscaler (HPA)** 58 | - Automatically adjusts the number of Pods based on demand. 59 | 60 | ### 20. **ClusterIP** 61 | - A service type that is accessible only within the cluster. 62 | 63 | ### 21. **NodePort** 64 | - Opens a specific port on each node to allow external access. 65 | 66 | ### 22. **etcd** 67 | - A distributed key-value store that holds the state of the Kubernetes cluster. 68 | -------------------------------------------------------------------------------- /11-job/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a Job is a controller that creates one or more Pods and ensures that a specified number of them successfully terminate. Jobs are typically used for running batch processing tasks. Here’s a list of common `kubectl` commands related to Jobs, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Jobs 4 | 5 | 1. **List Jobs** 6 | ```bash 7 | kubectl get jobs 8 | ``` 9 | - Lists all Jobs in the current namespace. 10 | 11 | 2. **Describe a Job** 12 | ```bash 13 | kubectl describe job 14 | ``` 15 | - Provides detailed information about a specific Job, including its status and events. 16 | 17 | 3. **Create a Job from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a Job using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a Job** 24 | ```bash 25 | kubectl delete job 26 | ``` 27 | - Deletes a specified Job and its associated Pods. 28 | 29 | 5. **Get Job YAML/JSON** 30 | ```bash 31 | kubectl get job -o yaml 32 | ``` 33 | - Retrieves the Job configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get job -o json 37 | ``` 38 | - Retrieves the Job configuration in JSON format. 39 | 40 | 6. **Get Pods Created by a Job** 41 | ```bash 42 | kubectl get pods --selector=job-name= 43 | ``` 44 | - Lists all Pods created by the specified Job. 45 | 46 | 7. **Watch Job Status** 47 | ```bash 48 | kubectl get jobs --watch 49 | ``` 50 | - Continuously watches and displays the status of Jobs in the current namespace. 51 | 52 | 8. **Scale a Job** 53 | ```bash 54 | kubectl scale job --replicas= 55 | ``` 56 | - Scales the specified Job to the desired number of replicas. 57 | 58 | 9. **Get Job Logs** 59 | ```bash 60 | kubectl logs job/ 61 | ``` 62 | - Retrieves the logs from the Pods created by the specified Job. 63 | 64 | ### Example of Job Creation 65 | 66 | Here’s an example of how to create a Job using a YAML file: 67 | 68 | 1. **Create a YAML file (e.g., `my-job.yaml`)**: 69 | ```yaml 70 | apiVersion: batch/v1 71 | kind: Job 72 | metadata: 73 | name: my-job 74 | spec: 75 | template: 76 | spec: 77 | containers: 78 | - name: my-job-container 79 | image: busybox 80 | command: ["sh", "-c", "echo Hello, Kubernetes! && sleep 30"] 81 | restartPolicy: Never 82 | backoffLimit: 4 83 | ``` 84 | 85 | 2. **Apply the YAML file**: 86 | ```bash 87 | kubectl apply -f my-job.yaml 88 | ``` 89 | 90 | ### Summary 91 | 92 | These commands provide a comprehensive toolkit for managing Jobs in Kubernetes. Jobs are ideal for running batch jobs or tasks that can be executed to completion without requiring persistent execution. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /11-minikube-status.md: -------------------------------------------------------------------------------- 1 | # How to check minikube status and minikube environment 2 | 3 | To check the environment where Minikube is running and find out which driver (e.g., Docker, VirtualBox, Hyper-V) it is using, you can use the following commands: 4 | 5 | ## 1. **Minikube Status Command:** 6 | 7 | To view the environment in which Minikube is running, you can use the `minikube status` command. This command shows the status of the cluster and provides information about the driver being used. 8 | 9 | ```bash 10 | minikube status 11 | ``` 12 | 13 | This command provides general information about the running Minikube cluster and also displays the driver being used. 14 | 15 | ## 2. **Minikube Profile Info Command:** 16 | 17 | To get more detailed information about the cluster, you can use the `minikube profile` command to see the profile details. 18 | 19 | ```bash 20 | minikube profile 21 | ``` 22 | 23 | This command gives more details about the profile, including the driver in use. 24 | 25 | ## 3. **Minikube Config View Command:** 26 | 27 | To view Minikube’s configuration, you can use the `minikube config view` command. This shows which driver and other configuration settings Minikube is using by default. 28 | 29 | ```bash 30 | minikube config view 31 | ``` 32 | 33 | ## Example Output 34 | 35 | If Minikube is running with Docker, the `minikube status` command might produce output like this: 36 | 37 | ``` 38 | host: Running 39 | kubelet: Running 40 | apiserver: Running 41 | kubeconfig: Configured 42 | driver: docker 43 | ``` 44 | 45 | From this output, you can see that Minikube is using the Docker driver, and that the Kubernetes components are running properly. 46 | 47 | These commands allow you to easily check the environment where Minikube is running and its driver settings. -------------------------------------------------------------------------------- /12-cronjob/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a CronJob is a controller that allows you to run Jobs on a scheduled basis. It is similar to the cron utility in Unix/Linux. CronJobs are useful for creating periodic and recurring tasks, such as backups or report generation. Here’s a list of common `kubectl` commands related to CronJobs, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for CronJobs 4 | 5 | 1. **List CronJobs** 6 | ```bash 7 | kubectl get cronjobs 8 | ``` 9 | - Lists all CronJobs in the current namespace. 10 | 11 | 2. **Describe a CronJob** 12 | ```bash 13 | kubectl describe cronjob 14 | ``` 15 | - Provides detailed information about a specific CronJob, including its schedule and status. 16 | 17 | 3. **Create a CronJob from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a CronJob using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a CronJob** 24 | ```bash 25 | kubectl delete cronjob 26 | ``` 27 | - Deletes a specified CronJob and any associated Jobs it has created. 28 | 29 | 5. **Get CronJob YAML/JSON** 30 | ```bash 31 | kubectl get cronjob -o yaml 32 | ``` 33 | - Retrieves the CronJob configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get cronjob -o json 37 | ``` 38 | - Retrieves the CronJob configuration in JSON format. 39 | 40 | 6. **Get Jobs Created by a CronJob** 41 | ```bash 42 | kubectl get jobs --selector=job-name= 43 | ``` 44 | - Lists all Jobs created by the specified CronJob. 45 | 46 | 7. **Get Logs of a Job Created by a CronJob** 47 | ```bash 48 | kubectl logs job/ 49 | ``` 50 | - Retrieves the logs from a specific Job created by the CronJob. 51 | 52 | 8. **Watch CronJob Status** 53 | ```bash 54 | kubectl get cronjobs --watch 55 | ``` 56 | - Continuously watches and displays the status of CronJobs in the current namespace. 57 | 58 | 9. **Pause a CronJob** 59 | ```bash 60 | kubectl patch cronjob -p '{"spec" : {"suspend" : true }}' 61 | ``` 62 | - Temporarily suspends the CronJob, preventing it from creating new Jobs. 63 | 64 | 10. **Resume a CronJob** 65 | ```bash 66 | kubectl patch cronjob -p '{"spec" : {"suspend" : false }}' 67 | ``` 68 | - Resumes the CronJob, allowing it to create new Jobs again. 69 | 70 | ### Example of CronJob Creation 71 | 72 | Here’s an example of how to create a CronJob using a YAML file: 73 | 74 | 1. **Create a YAML file (e.g., `my-cronjob.yaml`)**: 75 | ```yaml 76 | apiVersion: batch/v1 77 | kind: CronJob 78 | metadata: 79 | name: my-cronjob 80 | spec: 81 | schedule: "*/5 * * * *" # Run every 5 minutes 82 | jobTemplate: 83 | spec: 84 | template: 85 | spec: 86 | containers: 87 | - name: my-cronjob-container 88 | image: busybox 89 | command: ["sh", "-c", "echo Hello, Kubernetes!"] 90 | restartPolicy: OnFailure 91 | ``` 92 | 93 | 2. **Apply the YAML file**: 94 | ```bash 95 | kubectl apply -f my-cronjob.yaml 96 | ``` 97 | 98 | ### Summary 99 | 100 | These commands provide a comprehensive toolkit for managing CronJobs in Kubernetes. CronJobs enable you to automate scheduled tasks, making it easier to handle periodic operations. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /13-loadbalancer/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a LoadBalancer is a service type that automatically provisions an external load balancer to distribute traffic to the Pods in your application. Below is a list of common `kubectl` commands related to LoadBalancer services, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for LoadBalancer Services 4 | 5 | 1. **List Services** 6 | ```bash 7 | kubectl get services 8 | ``` 9 | - Lists all services in the current namespace, including LoadBalancer services. 10 | 11 | 2. **Describe a LoadBalancer Service** 12 | ```bash 13 | kubectl describe service 14 | ``` 15 | - Provides detailed information about a specific LoadBalancer service, including its external IP address and configuration. 16 | 17 | 3. **Create a LoadBalancer Service from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a LoadBalancer service using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a LoadBalancer Service** 24 | ```bash 25 | kubectl delete service 26 | ``` 27 | - Deletes a specified LoadBalancer service. 28 | 29 | 5. **Get LoadBalancer Service YAML/JSON** 30 | ```bash 31 | kubectl get service -o yaml 32 | ``` 33 | - Retrieves the LoadBalancer service configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get service -o json 37 | ``` 38 | - Retrieves the LoadBalancer service configuration in JSON format. 39 | 40 | 6. **Check the External IP of a LoadBalancer Service** 41 | ```bash 42 | kubectl get service -o wide 43 | ``` 44 | - Displays the external IP address assigned to the LoadBalancer service, along with additional information. 45 | 46 | 7. **Get Logs of Pods Behind a LoadBalancer** 47 | ```bash 48 | kubectl logs 49 | ``` 50 | - Retrieves the logs from a specific Pod that is behind the LoadBalancer service. 51 | 52 | 8. **Edit a LoadBalancer Service** 53 | ```bash 54 | kubectl edit service 55 | ``` 56 | - Opens the service configuration in your default text editor for inline editing. 57 | 58 | ### Example of LoadBalancer Service Creation 59 | 60 | Here’s an example of how to create a LoadBalancer service using a YAML file: 61 | 62 | 1. **Create a YAML file (e.g., `my-loadbalancer-service.yaml`)**: 63 | ```yaml 64 | apiVersion: v1 65 | kind: Service 66 | metadata: 67 | name: my-loadbalancer 68 | spec: 69 | type: LoadBalancer 70 | selector: 71 | app: my-app 72 | ports: 73 | - port: 80 74 | targetPort: 8080 75 | ``` 76 | 77 | 2. **Apply the YAML file**: 78 | ```bash 79 | kubectl apply -f my-loadbalancer-service.yaml 80 | ``` 81 | 82 | ### Summary 83 | 84 | These commands provide a comprehensive toolkit for managing LoadBalancer services in Kubernetes. LoadBalancer services enable you to expose your applications to external traffic effectively. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /14-ingress/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, an Ingress is a resource that manages external access to services within a cluster, typically HTTP and HTTPS traffic. It provides routing rules to manage how traffic is directed to different services based on the request's hostname or path. Below is a list of common `kubectl` commands related to Ingress resources, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Ingress Resources 4 | 5 | 1. **List Ingress Resources** 6 | ```bash 7 | kubectl get ingress 8 | ``` 9 | - Lists all Ingress resources in the current namespace. 10 | 11 | 2. **Describe an Ingress Resource** 12 | ```bash 13 | kubectl describe ingress 14 | ``` 15 | - Provides detailed information about a specific Ingress resource, including its rules and backend services. 16 | 17 | 3. **Create an Ingress from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates an Ingress resource using the configuration defined in a YAML file. 22 | 23 | 4. **Delete an Ingress Resource** 24 | ```bash 25 | kubectl delete ingress 26 | ``` 27 | - Deletes a specified Ingress resource. 28 | 29 | 5. **Get Ingress YAML/JSON** 30 | ```bash 31 | kubectl get ingress -o yaml 32 | ``` 33 | - Retrieves the Ingress configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get ingress -o json 37 | ``` 38 | - Retrieves the Ingress configuration in JSON format. 39 | 40 | 6. **Edit an Ingress Resource** 41 | ```bash 42 | kubectl edit ingress 43 | ``` 44 | - Opens the Ingress resource configuration in your default text editor for inline editing. 45 | 46 | 7. **Check the Ingress Controller Logs** 47 | ```bash 48 | kubectl logs 49 | ``` 50 | - Retrieves the logs from the Ingress controller Pod to debug routing issues. 51 | 52 | 8. **Get the IP Address of the Ingress** 53 | ```bash 54 | kubectl get ingress -o wide 55 | ``` 56 | - Displays the external IP address assigned to the Ingress resource, if available. 57 | 58 | ### Example of Ingress Creation 59 | 60 | Here’s an example of how to create an Ingress resource using a YAML file: 61 | 62 | 1. **Create a YAML file (e.g., `my-ingress.yaml`)**: 63 | ```yaml 64 | apiVersion: networking.k8s.io/v1 65 | kind: Ingress 66 | metadata: 67 | name: my-ingress 68 | spec: 69 | rules: 70 | - host: myapp.example.com 71 | http: 72 | paths: 73 | - path: / 74 | pathType: Prefix 75 | backend: 76 | service: 77 | name: my-service 78 | port: 79 | number: 80 80 | ``` 81 | 82 | 2. **Apply the YAML file**: 83 | ```bash 84 | kubectl apply -f my-ingress.yaml 85 | ``` 86 | 87 | ### Summary 88 | 89 | These commands provide a comprehensive toolkit for managing Ingress resources in Kubernetes. Ingress allows you to control how external HTTP/S traffic is routed to your services, offering flexibility and advanced routing capabilities. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /15-persistenentvolume/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, Persistent Volumes (PVs) are a key part of the storage system. They provide an abstraction for storage that is independent of individual Pods, allowing storage to persist beyond the lifecycle of a Pod. Below is a list of common `kubectl` commands related to Persistent Volumes, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Persistent Volumes 4 | 5 | 1. **List Persistent Volumes** 6 | ```bash 7 | kubectl get pv 8 | ``` 9 | - Lists all Persistent Volumes in the cluster. 10 | 11 | 2. **Describe a Persistent Volume** 12 | ```bash 13 | kubectl describe pv 14 | ``` 15 | - Provides detailed information about a specific Persistent Volume, including its capacity, access modes, and status. 16 | 17 | 3. **Create a Persistent Volume from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a Persistent Volume using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a Persistent Volume** 24 | ```bash 25 | kubectl delete pv 26 | ``` 27 | - Deletes a specified Persistent Volume. 28 | 29 | 5. **Get Persistent Volume YAML/JSON** 30 | ```bash 31 | kubectl get pv -o yaml 32 | ``` 33 | - Retrieves the Persistent Volume configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get pv -o json 37 | ``` 38 | - Retrieves the Persistent Volume configuration in JSON format. 39 | 40 | 6. **List Persistent Volume Claims** 41 | ```bash 42 | kubectl get pvc 43 | ``` 44 | - Lists all Persistent Volume Claims (PVCs) in the current namespace. 45 | 46 | 7. **Describe a Persistent Volume Claim** 47 | ```bash 48 | kubectl describe pvc 49 | ``` 50 | - Provides detailed information about a specific Persistent Volume Claim, including its status and bound Persistent Volume. 51 | 52 | 8. **Create a Persistent Volume Claim from a YAML File** 53 | ```bash 54 | kubectl apply -f 55 | ``` 56 | - Creates a Persistent Volume Claim using the configuration defined in a YAML file. 57 | 58 | 9. **Delete a Persistent Volume Claim** 59 | ```bash 60 | kubectl delete pvc 61 | ``` 62 | - Deletes a specified Persistent Volume Claim. 63 | 64 | 10. **Get Persistent Volume Claim YAML/JSON** 65 | ```bash 66 | kubectl get pvc -o yaml 67 | ``` 68 | - Retrieves the Persistent Volume Claim configuration in YAML format. 69 | 70 | ```bash 71 | kubectl get pvc -o json 72 | ``` 73 | - Retrieves the Persistent Volume Claim configuration in JSON format. 74 | 75 | 11. **Get Events Related to a Persistent Volume** 76 | ```bash 77 | kubectl get events --field-selector involvedObject.name= 78 | ``` 79 | - Displays events related to a specific Persistent Volume, useful for troubleshooting. 80 | 81 | 12. **Check Storage Classes** 82 | ```bash 83 | kubectl get storageclass 84 | ``` 85 | - Lists all Storage Classes in the cluster, which define how storage is dynamically provisioned. 86 | 87 | 13. **Describe a Storage Class** 88 | ```bash 89 | kubectl describe storageclass 90 | ``` 91 | - Provides detailed information about a specific Storage Class. 92 | 93 | ### Example of Persistent Volume Creation 94 | 95 | Here’s an example of how to create a Persistent Volume and a Persistent Volume Claim using YAML files: 96 | 97 | 1. **Create a Persistent Volume YAML file (e.g., `my-pv.yaml`)**: 98 | ```yaml 99 | apiVersion: v1 100 | kind: PersistentVolume 101 | metadata: 102 | name: my-pv 103 | spec: 104 | capacity: 105 | storage: 10Gi 106 | accessModes: 107 | - ReadWriteOnce 108 | hostPath: 109 | path: /data/my-pv 110 | ``` 111 | 112 | 2. **Create a Persistent Volume Claim YAML file (e.g., `my-pvc.yaml`)**: 113 | ```yaml 114 | apiVersion: v1 115 | kind: PersistentVolumeClaim 116 | metadata: 117 | name: my-pvc 118 | spec: 119 | accessModes: 120 | - ReadWriteOnce 121 | resources: 122 | requests: 123 | storage: 5Gi 124 | ``` 125 | 126 | 3. **Apply the Persistent Volume and Claim**: 127 | ```bash 128 | kubectl apply -f my-pv.yaml 129 | kubectl apply -f my-pvc.yaml 130 | ``` 131 | 132 | ### Summary 133 | 134 | These commands provide a comprehensive toolkit for managing Persistent Volumes and Persistent Volume Claims in Kubernetes. They enable you to define and manage storage resources that persist beyond the lifecycle of individual Pods. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /16-persistenentvolumeclaim/014-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, Persistent Volume Claims (PVCs) are requests for storage by a user or application. They allow users to claim and use Persistent Volumes (PVs) without needing to know the details of the underlying storage infrastructure. Below is a list of common `kubectl` commands related to Persistent Volume Claims, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Persistent Volume Claims (PVCs) 4 | 5 | 1. **List Persistent Volume Claims** 6 | ```bash 7 | kubectl get pvc 8 | ``` 9 | - Lists all Persistent Volume Claims in the current namespace. 10 | 11 | 2. **Describe a Persistent Volume Claim** 12 | ```bash 13 | kubectl describe pvc 14 | ``` 15 | - Provides detailed information about a specific Persistent Volume Claim, including its status, requested resources, and bound Persistent Volume. 16 | 17 | 3. **Create a Persistent Volume Claim from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a Persistent Volume Claim using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a Persistent Volume Claim** 24 | ```bash 25 | kubectl delete pvc 26 | ``` 27 | - Deletes a specified Persistent Volume Claim. 28 | 29 | 5. **Get Persistent Volume Claim YAML/JSON** 30 | ```bash 31 | kubectl get pvc -o yaml 32 | ``` 33 | - Retrieves the Persistent Volume Claim configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get pvc -o json 37 | ``` 38 | - Retrieves the Persistent Volume Claim configuration in JSON format. 39 | 40 | 6. **List Persistent Volume Claims in a Specific Namespace** 41 | ```bash 42 | kubectl get pvc -n 43 | ``` 44 | - Lists all Persistent Volume Claims in a specified namespace. 45 | 46 | 7. **Get Events Related to a Persistent Volume Claim** 47 | ```bash 48 | kubectl get events --field-selector involvedObject.name= 49 | ``` 50 | - Displays events related to a specific Persistent Volume Claim, which can help in troubleshooting issues. 51 | 52 | 8. **Check the Status of the Bound Persistent Volume** 53 | ```bash 54 | kubectl get pv 55 | ``` 56 | - Lists all Persistent Volumes and allows you to see which Persistent Volume is bound to your PVC. 57 | 58 | 9. **Edit a Persistent Volume Claim** 59 | ```bash 60 | kubectl edit pvc 61 | ``` 62 | - Opens the Persistent Volume Claim configuration in your default text editor for inline editing. 63 | 64 | 10. **Patch a Persistent Volume Claim** 65 | ```bash 66 | kubectl patch pvc -p '{"spec": {"resources": {"requests": {"storage": "new-size"}}}}' 67 | ``` 68 | - Updates the specified field of a Persistent Volume Claim without needing to delete and recreate it. 69 | 70 | ### Example of Persistent Volume Claim Creation 71 | 72 | Here’s an example of how to create a Persistent Volume Claim using a YAML file: 73 | 74 | 1. **Create a Persistent Volume Claim YAML file (e.g., `my-pvc.yaml`)**: 75 | ```yaml 76 | apiVersion: v1 77 | kind: PersistentVolumeClaim 78 | metadata: 79 | name: my-pvc 80 | spec: 81 | accessModes: 82 | - ReadWriteOnce 83 | resources: 84 | requests: 85 | storage: 5Gi 86 | ``` 87 | 88 | 2. **Apply the Persistent Volume Claim**: 89 | ```bash 90 | kubectl apply -f my-pvc.yaml 91 | ``` 92 | 93 | ### Summary 94 | 95 | These commands provide a comprehensive toolkit for managing Persistent Volume Claims in Kubernetes. PVCs enable users to request storage resources dynamically without needing to understand the underlying storage details. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /17-StatefulSet/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a StatefulSet is a workload API object used to manage stateful applications. It provides guarantees about the ordering and uniqueness of Pods. Below is a list of common `kubectl` commands related to StatefulSets, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for StatefulSets 4 | 5 | 1. **List StatefulSets** 6 | ```bash 7 | kubectl get statefulsets 8 | ``` 9 | - Lists all StatefulSets in the current namespace. 10 | 11 | 2. **Describe a StatefulSet** 12 | ```bash 13 | kubectl describe statefulset 14 | ``` 15 | - Provides detailed information about a specific StatefulSet, including its Pods, replicas, and configuration. 16 | 17 | 3. **Create a StatefulSet from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a StatefulSet using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a StatefulSet** 24 | ```bash 25 | kubectl delete statefulset 26 | ``` 27 | - Deletes a specified StatefulSet. 28 | 29 | 5. **Get StatefulSet YAML/JSON** 30 | ```bash 31 | kubectl get statefulset -o yaml 32 | ``` 33 | - Retrieves the StatefulSet configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get statefulset -o json 37 | ``` 38 | - Retrieves the StatefulSet configuration in JSON format. 39 | 40 | 6. **Scale a StatefulSet** 41 | ```bash 42 | kubectl scale statefulset --replicas= 43 | ``` 44 | - Scales the number of replicas for a specified StatefulSet. 45 | 46 | 7. **Rollout a StatefulSet** 47 | ```bash 48 | kubectl rollout status statefulset 49 | ``` 50 | - Shows the rollout status of a StatefulSet. 51 | 52 | ```bash 53 | kubectl rollout history statefulset 54 | ``` 55 | - Displays the rollout history of a StatefulSet. 56 | 57 | ```bash 58 | kubectl rollout undo statefulset 59 | ``` 60 | - Undoes the last rollout of a StatefulSet. 61 | 62 | 8. **Get Pods Managed by a StatefulSet** 63 | ```bash 64 | kubectl get pods -l app= 65 | ``` 66 | - Lists all Pods managed by a specific StatefulSet, using labels to filter. 67 | 68 | 9. **Get Events Related to a StatefulSet** 69 | ```bash 70 | kubectl get events --field-selector involvedObject.name= 71 | ``` 72 | - Displays events related to a specific StatefulSet, useful for troubleshooting. 73 | 74 | 10. **Edit a StatefulSet** 75 | ```bash 76 | kubectl edit statefulset 77 | ``` 78 | - Opens the StatefulSet configuration in your default text editor for inline editing. 79 | 80 | ### Example of StatefulSet Creation 81 | 82 | Here’s an example of how to create a StatefulSet using a YAML file: 83 | 84 | 1. **Create a StatefulSet YAML file (e.g., `my-statefulset.yaml`)**: 85 | ```yaml 86 | apiVersion: apps/v1 87 | kind: StatefulSet 88 | metadata: 89 | name: my-statefulset 90 | spec: 91 | serviceName: "my-service" 92 | replicas: 3 93 | selector: 94 | matchLabels: 95 | app: my-app 96 | template: 97 | metadata: 98 | labels: 99 | app: my-app 100 | spec: 101 | containers: 102 | - name: my-container 103 | image: my-image:latest 104 | ports: 105 | - containerPort: 80 106 | ``` 107 | 108 | 2. **Apply the StatefulSet**: 109 | ```bash 110 | kubectl apply -f my-statefulset.yaml 111 | ``` 112 | 113 | ### Summary 114 | 115 | These commands provide a comprehensive toolkit for managing StatefulSets in Kubernetes. StatefulSets are essential for deploying stateful applications, ensuring that Pods maintain a stable identity and persistent storage. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /17-StatefulSet/02-step-by-step.md: -------------------------------------------------------------------------------- 1 | When using a **StatefulSet** in Kubernetes, each pod is assigned its own **PersistentVolumeClaim (PVC)**, which means each pod has its own separate storage volume. If these pods are meant to work with the same database, having separate PVCs can lead to potential issues such as data inconsistency, data conflicts, or access problems. 2 | 3 | Here’s a detailed explanation of the implications of using separate PVCs in a StatefulSet for a database application, along with various scenarios and solutions: 4 | 5 | ### Implications of Separate PVCs 6 | 7 | 1. **Data Isolation**: Each pod will write its data to its own volume. This means that if multiple pods are trying to access the same database, they will not see each other's data unless the database is designed for such use (e.g., through replication). 8 | 9 | 2. **Data Consistency**: Without a mechanism to synchronize data, having separate PVCs can lead to inconsistent states across pods. For example, if Pod A updates a record, Pod B won't see that change unless they are coordinated. 10 | 11 | ### Possible Scenarios and Solutions 12 | 13 | #### 1. **Non-Distributed Database** 14 | If you are using a traditional, non-distributed database (like a standalone MySQL instance), each pod having its own PVC would lead to data inconsistency because each pod would maintain its own version of the database. 15 | 16 | **Solution:** 17 | - Use a single deployment for your database to ensure that only one pod handles the database. This approach eliminates conflicts and ensures data consistency. 18 | - If a central database is required, you may want to use a **Deployment** or **DaemonSet** to manage a single instance of the database. 19 | 20 | #### 2. **Distributed Database (e.g., Cassandra, etcd, MySQL Galera)** 21 | Some databases are designed to work in a distributed manner. These systems can handle multiple instances (pods) that share data and maintain consistency through their internal mechanisms. 22 | 23 | **Examples:** 24 | - **Cassandra** and **etcd** allow each pod to maintain its own copy of the data while ensuring data consistency through replication. 25 | - **MySQL Galera Cluster** or **PostgreSQL Replication** enables multiple instances to work together, synchronizing changes across the pods. 26 | 27 | **Solution:** 28 | - StatefulSet is suitable for distributed databases. Each pod can use its own PVC while the database management system takes care of data consistency through replication mechanisms. 29 | 30 | #### 3. **Single Database Instance** 31 | If you are using a single, central database instance that all pods need to access, then sharing PVCs becomes a concern. 32 | 33 | **Solution:** 34 | - Instead of using StatefulSet, consider using a single database instance managed by a **Deployment**. All pods can connect to this central instance. 35 | - If using a shared PVC, ensure that the underlying storage can support concurrent writes from multiple pods. Shared file systems like NFS can be used here, but they may introduce performance issues. 36 | 37 | #### 4. **Using Shared PVCs** 38 | While StatefulSets typically assign individual PVCs to each pod, there are scenarios where you might want to use a shared PVC for a database. 39 | 40 | **Solution:** 41 | - Define a single **PersistentVolume** (like an NFS share) that can be accessed by all pods. This allows for data sharing but requires careful handling to avoid data corruption and ensure data integrity. 42 | - However, this can lead to performance bottlenecks and issues with concurrent writes, so use it judiciously. 43 | 44 | ### Summary 45 | When using StatefulSets with separate PVCs for a database application, consider the following: 46 | 47 | - **Distributed Database Systems**: If using a distributed database (e.g., Cassandra, etcd), having separate PVCs is acceptable as the database manages data synchronization. 48 | - **Single Central Database**: For a single database instance, having separate PVCs can cause data inconsistency. It's better to manage one instance with a Deployment. 49 | - **Shared Storage Solutions**: If sharing storage across pods, use shared file systems like NFS, but be cautious about performance and data integrity issues. 50 | 51 | The choice of solution should be guided by the specific requirements of your database system and the nature of your application. -------------------------------------------------------------------------------- /18-deamonset/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a DaemonSet ensures that a copy of a specific Pod runs on all (or a subset of) nodes in the cluster. This is useful for running background tasks such as log collection, monitoring, or managing storage on each node. Below is a list of common `kubectl` commands related to DaemonSets, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for DaemonSets 4 | 5 | 1. **List DaemonSets** 6 | ```bash 7 | kubectl get daemonsets 8 | ``` 9 | - Lists all DaemonSets in the current namespace. 10 | 11 | 2. **Describe a DaemonSet** 12 | ```bash 13 | kubectl describe daemonset 14 | ``` 15 | - Provides detailed information about a specific DaemonSet, including its Pods, configuration, and events. 16 | 17 | 3. **Create a DaemonSet from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a DaemonSet using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a DaemonSet** 24 | ```bash 25 | kubectl delete daemonset 26 | ``` 27 | - Deletes a specified DaemonSet. 28 | 29 | 5. **Get DaemonSet YAML/JSON** 30 | ```bash 31 | kubectl get daemonset -o yaml 32 | ``` 33 | - Retrieves the DaemonSet configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get daemonset -o json 37 | ``` 38 | - Retrieves the DaemonSet configuration in JSON format. 39 | 40 | 6. **Get Pods Managed by a DaemonSet** 41 | ```bash 42 | kubectl get pods -l name= 43 | ``` 44 | - Lists all Pods managed by a specific DaemonSet, using labels to filter. 45 | 46 | 7. **Get Events Related to a DaemonSet** 47 | ```bash 48 | kubectl get events --field-selector involvedObject.name= 49 | ``` 50 | - Displays events related to a specific DaemonSet, which can help in troubleshooting issues. 51 | 52 | 8. **Edit a DaemonSet** 53 | ```bash 54 | kubectl edit daemonset 55 | ``` 56 | - Opens the DaemonSet configuration in your default text editor for inline editing. 57 | 58 | 9. **Rollout a DaemonSet** 59 | ```bash 60 | kubectl rollout status daemonset 61 | ``` 62 | - Shows the rollout status of a DaemonSet. 63 | 64 | ```bash 65 | kubectl rollout history daemonset 66 | ``` 67 | - Displays the rollout history of a DaemonSet. 68 | 69 | ```bash 70 | kubectl rollout undo daemonset 71 | ``` 72 | - Undoes the last rollout of a DaemonSet. 73 | 74 | ### Example of DaemonSet Creation 75 | 76 | Here’s an example of how to create a DaemonSet using a YAML file: 77 | 78 | 1. **Create a DaemonSet YAML file (e.g., `my-daemonset.yaml`)**: 79 | ```yaml 80 | apiVersion: apps/v1 81 | kind: DaemonSet 82 | metadata: 83 | name: my-daemonset 84 | spec: 85 | selector: 86 | matchLabels: 87 | name: my-daemonset 88 | template: 89 | metadata: 90 | labels: 91 | name: my-daemonset 92 | spec: 93 | containers: 94 | - name: my-container 95 | image: my-image:latest 96 | ports: 97 | - containerPort: 80 98 | ``` 99 | 100 | 2. **Apply the DaemonSet**: 101 | ```bash 102 | kubectl apply -f my-daemonset.yaml 103 | ``` 104 | 105 | ### Summary 106 | 107 | These commands provide a comprehensive toolkit for managing DaemonSets in Kubernetes. DaemonSets are essential for ensuring that specific workloads run on every node, making them ideal for services like monitoring, logging, and network services. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /19-hpa/01-command-list.md: -------------------------------------------------------------------------------- 1 | Horizontal Pod Autoscaler (HPA) in Kubernetes automatically scales the number of Pods in a Deployment, StatefulSet, or ReplicaSet based on observed CPU utilization or other select metrics. Below is a list of common `kubectl` commands related to HPA, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for Horizontal Pod Autoscaler (HPA) 4 | 5 | 1. **List Horizontal Pod Autoscalers** 6 | ```bash 7 | kubectl get hpa 8 | ``` 9 | - Lists all HPA objects in the current namespace. 10 | 11 | 2. **Describe a Horizontal Pod Autoscaler** 12 | ```bash 13 | kubectl describe hpa 14 | ``` 15 | - Provides detailed information about a specific HPA, including the metrics used for scaling and the status of the scaling activities. 16 | 17 | 3. **Create a Horizontal Pod Autoscaler** 18 | ```bash 19 | kubectl autoscale deployment --min= --max= --cpu-percent= 20 | ``` 21 | - Automatically creates an HPA for a specified Deployment based on CPU utilization. 22 | 23 | 4. **Delete a Horizontal Pod Autoscaler** 24 | ```bash 25 | kubectl delete hpa 26 | ``` 27 | - Deletes a specified HPA. 28 | 29 | 5. **Get HPA YAML/JSON** 30 | ```bash 31 | kubectl get hpa -o yaml 32 | ``` 33 | - Retrieves the HPA configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get hpa -o json 37 | ``` 38 | - Retrieves the HPA configuration in JSON format. 39 | 40 | 6. **Edit a Horizontal Pod Autoscaler** 41 | ```bash 42 | kubectl edit hpa 43 | ``` 44 | - Opens the HPA configuration in your default text editor for inline editing. 45 | 46 | 7. **Get Metrics for the Horizontal Pod Autoscaler** 47 | ```bash 48 | kubectl get hpa --watch 49 | ``` 50 | - Continuously watches and displays the HPA metrics and scaling activities. 51 | 52 | 8. **Set Custom Metrics for HPA** 53 | You can also set up HPA based on custom metrics using the following command (requires additional setup): 54 | ```bash 55 | kubectl autoscale deployment --min= --max= --metric=: 56 | ``` 57 | 58 | ### Example of HPA Creation 59 | 60 | Here’s an example of how to create a Horizontal Pod Autoscaler for a Deployment: 61 | 62 | 1. **Create a Deployment (if not already created)** 63 | ```bash 64 | kubectl create deployment my-deployment --image=my-image:latest 65 | ``` 66 | 67 | 2. **Create the HPA** 68 | ```bash 69 | kubectl autoscale deployment my-deployment --min=1 --max=10 --cpu-percent=50 70 | ``` 71 | 72 | ### Summary 73 | 74 | These commands provide a comprehensive toolkit for managing Horizontal Pod Autoscalers in Kubernetes. HPA is crucial for ensuring that applications can scale dynamically based on demand, improving resource utilization and performance. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /20-clusterip/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a ClusterIP is a type of Service that provides a stable IP address for Pods and is only accessible within the cluster. Below is a list of common `kubectl` commands related to ClusterIP Services, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for ClusterIP Services 4 | 5 | 1. **List ClusterIP Services** 6 | ```bash 7 | kubectl get services --field-selector spec.type=ClusterIP 8 | ``` 9 | - Lists all Services of type ClusterIP in the current namespace. 10 | 11 | 2. **Describe a ClusterIP Service** 12 | ```bash 13 | kubectl describe service 14 | ``` 15 | - Provides detailed information about a specific ClusterIP Service, including its endpoints and configuration. 16 | 17 | 3. **Create a ClusterIP Service from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a ClusterIP Service using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a ClusterIP Service** 24 | ```bash 25 | kubectl delete service 26 | ``` 27 | - Deletes a specified ClusterIP Service. 28 | 29 | 5. **Get ClusterIP Service YAML/JSON** 30 | ```bash 31 | kubectl get service -o yaml 32 | ``` 33 | - Retrieves the Service configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get service -o json 37 | ``` 38 | - Retrieves the Service configuration in JSON format. 39 | 40 | 6. **Edit a ClusterIP Service** 41 | ```bash 42 | kubectl edit service 43 | ``` 44 | - Opens the Service configuration in your default text editor for inline editing. 45 | 46 | 7. **Get Endpoints of a ClusterIP Service** 47 | ```bash 48 | kubectl get endpoints 49 | ``` 50 | - Displays the endpoints that the ClusterIP Service is routing traffic to. 51 | 52 | 8. **Get Events Related to a ClusterIP Service** 53 | ```bash 54 | kubectl get events --field-selector involvedObject.name= 55 | ``` 56 | - Displays events related to a specific Service, which can help in troubleshooting issues. 57 | 58 | ### Example of ClusterIP Service Creation 59 | 60 | Here’s an example of how to create a ClusterIP Service using a YAML file: 61 | 62 | 1. **Create a Service YAML file (e.g., `my-service.yaml`)**: 63 | ```yaml 64 | apiVersion: v1 65 | kind: Service 66 | metadata: 67 | name: my-clusterip-service 68 | spec: 69 | type: ClusterIP 70 | selector: 71 | app: my-app 72 | ports: 73 | - port: 80 74 | targetPort: 8080 75 | ``` 76 | 77 | 2. **Apply the Service**: 78 | ```bash 79 | kubectl apply -f my-service.yaml 80 | ``` 81 | 82 | ### Summary 83 | 84 | These commands provide a comprehensive toolkit for managing ClusterIP Services in Kubernetes. ClusterIP Services are essential for enabling communication between Pods within the cluster, making them a foundational component of Kubernetes networking. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /20-docker-version-check_minikube-install.md: -------------------------------------------------------------------------------- 1 | # Installing Minikube in GitHub Codespaces 2 | 3 | Minikube allows you to run a local Kubernetes cluster on your machine. Below are the steps to set it up in a GitHub Codespace. 4 | 5 | ## Prerequisites 6 | 7 | Ensure you have the following installed in your Codespace: 8 | 9 | 1. **Docker**: Minikube uses Docker to create a virtual machine. You can check if Docker is installed by running: 10 | ```bash 11 | docker --version 12 | ``` 13 | 14 | 15 | 3. **Minikube**: Install Minikube with the following command: 16 | ```bash 17 | curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 18 | sudo install minikube-linux-amd64 /usr/local/bin/minikube 19 | ``` 20 | 21 | Single line version 22 | 23 | ```bash 24 | curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && sudo install minikube-linux-amd64 /usr/local/bin/minikube 25 | ``` 26 | 27 | ## Steps to Install Minikube 28 | 29 | 1. **Update and Upgrade the System**: 30 | Before proceeding, it's good practice to update the package lists and upgrade installed packages: 31 | ```bash 32 | sudo apt update && sudo apt upgrade -y 33 | ``` 34 | 35 | 2. **Start Minikube with Docker Driver**: 36 | To start Minikube using Docker as the driver, run the following command: 37 | ```bash 38 | minikube start --driver=docker 39 | ``` 40 | 41 | 3. **Check Minikube Status**: 42 | Verify that Minikube is running correctly: 43 | ```bash 44 | minikube status 45 | ``` 46 | 47 | 4. **Access the Minikube Dashboard (Optional)**: 48 | Minikube provides a dashboard for visual management. To launch it, run: 49 | ```bash 50 | minikube dashboard 51 | ``` 52 | 53 | 5. **Using kubectl with Minikube**: 54 | You can now use `kubectl` to manage your Minikube cluster. For example, check the nodes in your cluster with: 55 | ```bash 56 | kubectl get nodes 57 | ``` 58 | 59 | ## Conclusion 60 | 61 | By following these steps, you will have a fully operational Minikube environment in your GitHub Codespace, ready for developing and testing Kubernetes applications. 62 | -------------------------------------------------------------------------------- /21-kubectl-get-pods-show-error.md: -------------------------------------------------------------------------------- 1 | kubectl get nodes 2 | E1006 09:33:59.155266 32661 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"http://localhost:8080/api?timeout=32s\": dial tcp [::1]:8080: connect: connection refused" 3 | E1006 09:33:59.156781 32661 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"http://localhost:8080/api?timeout=32s\": dial tcp [::1]:8080: connect: connection refused" 4 | E1006 09:33:59.158130 32661 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"http://localhost:8080/api?timeout=32s\": dial tcp [::1]:8080: connect: connection refused" 5 | E1006 09:33:59.159515 32661 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"http://localhost:8080/api?timeout=32s\": dial tcp [::1]:8080: connect: connection refused" 6 | E1006 09:33:59.160980 32661 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get \"http://localhost:8080/api?timeout=32s\": dial tcp [::1]:8080: connect: connection refused" 7 | The connection to the server localhost:8080 was refused - did you specify the right host or port? 8 | 9 | ![Minikubestart Eror](/images/minikube-start-error.png) 10 | 11 | 🤔 12 | 13 | --- 14 | 15 | This error message indicates that Minikube is not running properly or has not been started when you run the `kubectl` command. The error shows that `kubectl` is trying to connect to `localhost:8080`, but the connection is being refused. Here are the steps you can take to resolve this issue: 16 | 17 | 1. **Start Minikube:** 18 | Make sure Minikube is running by executing the following command in your terminal: 19 | ```bash 20 | minikube start 21 | ``` 22 | 23 | 2. **Check Minikube Status:** 24 | You can check the status of Minikube with: 25 | ```bash 26 | minikube status 27 | ``` 28 | 29 | 3. **Update kubectl Config:** 30 | If you still receive the same error after starting Minikube, ensure that `kubectl` is configured correctly for Minikube: 31 | ```bash 32 | kubectl config use-context minikube 33 | ``` 34 | 35 | 4. **Check Logs:** 36 | If you encounter an error while starting Minikube, check the Minikube log files: 37 | ```bash 38 | minikube logs 39 | ``` 40 | 41 | 5. **Restart Minikube:** 42 | If you are still facing issues, try stopping and restarting Minikube: 43 | ```bash 44 | minikube stop 45 | minikube start 46 | ``` 47 | 48 | 6. **Check Firewall Settings:** 49 | In some cases, firewall settings can lead to connection issues. Check your firewall settings and allow `kubectl` to access the required ports. 50 | 51 | If these steps do not resolve your issue, consider carefully reviewing the error messages or consulting the Minikube documentation for further insights. -------------------------------------------------------------------------------- /21-nodeport/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a NodePort is a type of Service that exposes an application on a static port on each Node's IP address. This allows external traffic to access the Service via the Node's IP address and the specified NodePort. Below is a list of common `kubectl` commands related to NodePort Services, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for NodePort Services 4 | 5 | 1. **List NodePort Services** 6 | ```bash 7 | kubectl get services --field-selector spec.type=NodePort 8 | ``` 9 | - Lists all Services of type NodePort in the current namespace. 10 | 11 | 2. **Describe a NodePort Service** 12 | ```bash 13 | kubectl describe service 14 | ``` 15 | - Provides detailed information about a specific NodePort Service, including its configuration and endpoints. 16 | 17 | 3. **Create a NodePort Service from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a NodePort Service using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a NodePort Service** 24 | ```bash 25 | kubectl delete service 26 | ``` 27 | - Deletes a specified NodePort Service. 28 | 29 | 5. **Get NodePort Service YAML/JSON** 30 | ```bash 31 | kubectl get service -o yaml 32 | ``` 33 | - Retrieves the Service configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get service -o json 37 | ``` 38 | - Retrieves the Service configuration in JSON format. 39 | 40 | 6. **Edit a NodePort Service** 41 | ```bash 42 | kubectl edit service 43 | ``` 44 | - Opens the Service configuration in your default text editor for inline editing. 45 | 46 | 7. **Get Endpoints of a NodePort Service** 47 | ```bash 48 | kubectl get endpoints 49 | ``` 50 | - Displays the endpoints that the NodePort Service is routing traffic to. 51 | 52 | 8. **Get Events Related to a NodePort Service** 53 | ```bash 54 | kubectl get events --field-selector involvedObject.name= 55 | ``` 56 | - Displays events related to a specific Service, which can help in troubleshooting issues. 57 | 58 | ### Example of NodePort Service Creation 59 | 60 | Here’s an example of how to create a NodePort Service using a YAML file: 61 | 62 | 1. **Create a Service YAML file (e.g., `my-nodeport-service.yaml`)**: 63 | ```yaml 64 | apiVersion: v1 65 | kind: Service 66 | metadata: 67 | name: my-nodeport-service 68 | spec: 69 | type: NodePort 70 | selector: 71 | app: my-app 72 | ports: 73 | - port: 80 74 | targetPort: 8080 75 | nodePort: 30000 # Optional: Specify a custom NodePort 76 | ``` 77 | 78 | 2. **Apply the Service**: 79 | ```bash 80 | kubectl apply -f my-nodeport-service.yaml 81 | ``` 82 | 83 | ### Summary 84 | 85 | These commands provide a comprehensive toolkit for managing NodePort Services in Kubernetes. NodePort Services are essential for allowing external traffic to access applications running in the cluster, making them useful for development, testing, and specific production scenarios. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /22-etcd/01-command-list.md: -------------------------------------------------------------------------------- 1 | `etcd` is a distributed key-value store used by Kubernetes to store all cluster data, including configuration data and state information. While `etcd` commands are typically run in the context of etcd management rather than via `kubectl`, here’s a list of common `etcd` commands and their descriptions for managing etcd directly. 2 | 3 | ### Common `etcd` Command List 4 | 5 | 1. **Start etcd** 6 | ```bash 7 | etcd 8 | ``` 9 | - Starts the etcd server. You may need to specify additional flags such as `--data-dir`, `--listen-client-urls`, and `--advertise-client-urls`. 10 | 11 | 2. **Check etcd health** 12 | ```bash 13 | etcdctl endpoint health 14 | ``` 15 | - Checks the health of the etcd cluster. 16 | 17 | 3. **List all keys** 18 | ```bash 19 | etcdctl get "" --from-key 20 | ``` 21 | - Retrieves all keys stored in etcd. 22 | 23 | 4. **Get a specific key** 24 | ```bash 25 | etcdctl get 26 | ``` 27 | - Retrieves the value associated with a specific key. 28 | 29 | 5. **Set a key-value pair** 30 | ```bash 31 | etcdctl put 32 | ``` 33 | - Stores a key-value pair in etcd. 34 | 35 | 6. **Delete a key** 36 | ```bash 37 | etcdctl del 38 | ``` 39 | - Deletes a specific key from etcd. 40 | 41 | 7. **Watch for changes to a key** 42 | ```bash 43 | etcdctl watch 44 | ``` 45 | - Watches for changes to a specific key and outputs changes in real-time. 46 | 47 | 8. **Get the cluster status** 48 | ```bash 49 | etcdctl endpoint status 50 | ``` 51 | - Displays the status of each etcd member in the cluster. 52 | 53 | 9. **Snapshot etcd data** 54 | ```bash 55 | etcdctl snapshot save 56 | ``` 57 | - Saves a snapshot of the etcd database to a file. 58 | 59 | 10. **Restore etcd from a snapshot** 60 | ```bash 61 | etcdctl snapshot restore 62 | ``` 63 | - Restores the etcd database from a specified snapshot file. 64 | 65 | 11. **Compact the etcd database** 66 | ```bash 67 | etcdctl compact 68 | ``` 69 | - Compacts the etcd database to reclaim storage space. 70 | 71 | 12. **Defragment the etcd database** 72 | ```bash 73 | etcdctl defrag 74 | ``` 75 | - Defragments the etcd database, improving performance and reclaiming storage space. 76 | 77 | 13. **List members of the etcd cluster** 78 | ```bash 79 | etcdctl member list 80 | ``` 81 | - Lists all members of the etcd cluster along with their status. 82 | 83 | ### Example of Using `etcdctl` 84 | 85 | Here’s an example of how to set and get a key-value pair using `etcdctl`: 86 | 87 | 1. **Set a key** 88 | ```bash 89 | etcdctl put my-key "Hello, etcd!" 90 | ``` 91 | 92 | 2. **Get the value of the key** 93 | ```bash 94 | etcdctl get my-key 95 | ``` 96 | 97 | ### Important Notes 98 | 99 | - **Environment Variables**: Make sure to set the necessary environment variables or flags for authentication and connection settings, such as `ETCDCTL_API`, `ETCDCTL_CACERT`, `ETCDCTL_CERT`, and `ETCDCTL_KEY`. 100 | 101 | - **Versions**: The `etcdctl` commands might vary slightly between different versions of `etcd`. Always refer to the official etcd documentation for the version you are using. 102 | 103 | ### Summary 104 | 105 | These commands provide a comprehensive toolkit for managing etcd, which is a critical component of Kubernetes for storing configuration and state data. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /23-port-type/00-port-types.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, ports are essential for enabling communication between a Pod or Service and the outside world. The following are the main types of ports used in Kubernetes: 2 | 3 | 1. **Container Port**: 4 | - This is the port that a container listens on inside a Pod. 5 | - It is specified in the `containers` section of a Pod definition. 6 | - Example: 7 | ```yaml 8 | containers: 9 | - name: my-app 10 | image: my-app-image 11 | ports: 12 | - containerPort: 8080 13 | ``` 14 | 15 | **PROMPT:** 16 | ***What is Container Port? When is it used? What is its function? How can we use it > explain in detail*** 17 | 18 | 2. **Host Port**: 19 | - This maps a port inside a container to a specific port on the host machine. 20 | - Host ports are typically used in low-level configurations. 21 | - Example: 22 | ```yaml 23 | containers: 24 | - name: my-app 25 | image: my-app-image 26 | ports: 27 | - containerPort: 8080 28 | hostPort: 80 29 | ``` 30 | 31 | **PROMPT:** 32 | ***What is Host Port? When is it used? What is its function? How can we use it > explain in detail*** 33 | 34 | 3. **Service Port**: 35 | - This is the port on which a Kubernetes Service listens and forwards traffic to the container ports of Pods. 36 | - Defined in the Service resource specification. 37 | - Example: 38 | ```yaml 39 | kind: Service 40 | apiVersion: v1 41 | metadata: 42 | name: my-service 43 | spec: 44 | ports: 45 | - port: 80 46 | targetPort: 8080 47 | ``` 48 | 49 | **PROMPT:** 50 | ***What is Service Port? When is it used? What is its function? How can we use it > explain in detail*** 51 | 52 | 4. **NodePort**: 53 | - This type exposes a Service on a static port (usually between 30000-32767) on each node in the cluster. 54 | - External traffic can reach the Service via the node’s IP and NodePort. 55 | - Example: 56 | ```yaml 57 | kind: Service 58 | apiVersion: v1 59 | metadata: 60 | name: my-service 61 | spec: 62 | type: NodePort 63 | ports: 64 | - port: 80 65 | targetPort: 8080 66 | nodePort: 30001 67 | ``` 68 | 69 | **PROMPT:** 70 | ***What is Nodeport? When is it used? What is its function? How can we use it > explain in detail*** 71 | 72 | 5. **LoadBalancer Port**: 73 | - Used in cloud environments, this port exposes the Service via a load balancer. 74 | - It allows external access to the Service through the cloud provider’s load balancer. 75 | - Example: 76 | ```yaml 77 | kind: Service 78 | apiVersion: v1 79 | metadata: 80 | name: my-service 81 | spec: 82 | type: LoadBalancer 83 | ports: 84 | - port: 80 85 | targetPort: 8080 86 | ``` 87 | 88 | **PROMPT:** 89 | ***What is Loadbalancer Port? When is it used? What is its function? How can we use it > explain in detail*** 90 | 91 | 6. **Ingress Port**: 92 | - Ingress is a higher-level component that manages external HTTP(S) traffic to services within the Kubernetes cluster. 93 | - It typically uses rules to route requests to the appropriate service based on the request's host or path. 94 | - Example: 95 | ```yaml 96 | kind: Ingress 97 | apiVersion: networking.k8s.io/v1 98 | metadata: 99 | name: my-ingress 100 | spec: 101 | rules: 102 | - host: example.com 103 | http: 104 | paths: 105 | - path: / 106 | backend: 107 | service: 108 | name: my-service 109 | port: 110 | number: 80 111 | ``` 112 | 113 | **PROMPT:** 114 | ***What is Ingress Port? When is it used? What is its function? How can we use it > explain in detail*** 115 | 116 | These port types play a critical role in configuring network communication and enabling applications to interact with external or internal networks in a Kubernetes environment. -------------------------------------------------------------------------------- /31-why-use-minikube.md: -------------------------------------------------------------------------------- 1 | ### What is Minikube? 2 | 3 | Minikube is an open-source tool that enables users to run a single-node Kubernetes cluster locally. While it is not a Kubernetes distribution itself, it provides a lightweight version of Kubernetes that simplifies the process of developing and testing applications in a Kubernetes environment. This makes it particularly useful for those who want to explore Kubernetes functionalities without the complexities of managing a full-fledged cluster in a cloud setup. 4 | 5 | ### Why Use Minikube? 6 | 7 | 1. **Local Development**: Minikube allows developers to run Kubernetes on their local machines, enabling rapid prototyping and testing of applications within a Kubernetes environment without needing cloud resources. 8 | 9 | 2. **Learning and Experimentation**: For those new to Kubernetes, Minikube serves as an excellent educational tool, providing a straightforward way to understand how Kubernetes works. It allows users to experiment with Kubernetes features in a safe and controlled environment. 10 | 11 | 3. **Environment Consistency**: It provides a local environment that closely resembles production setups, allowing developers to ensure that applications will behave consistently when deployed. 12 | 13 | 4. **Resource Efficiency**: Minikube is designed to be resource-efficient, making it suitable for development machines that may not have extensive resources. 14 | 15 | ### When and Where to Use Minikube? 16 | 17 | - **Development Phase**: Ideal for developers who are building, testing, and debugging applications intended for Kubernetes deployment. 18 | - **Learning Environments**: Useful for teams or individuals learning Kubernetes, as it provides a hands-on way to explore Kubernetes features. 19 | - **Continuous Integration (CI)**: It can be integrated into CI pipelines for testing Kubernetes-related workflows. 20 | 21 | ### Considerations When Using Minikube 22 | 23 | 1. **Resource Limitations**: Since Minikube runs a single-node cluster, it may not simulate production environments with multiple nodes. This could lead to discrepancies in performance or behavior when deploying to a more complex environment. 24 | 25 | 2. **Configuration Complexity**: Although Minikube simplifies many processes, some advanced configurations may still require deeper knowledge of Kubernetes. 26 | 27 | 3. **Network Configurations**: Local networking can sometimes present challenges, especially with services that require specific networking setups or firewall configurations. 28 | 29 | 4. **Driver Compatibility**: Minikube supports various drivers (e.g., VirtualBox, Docker). Choosing the right driver for your environment is crucial for optimal performance. 30 | 31 | 5. **Platform Dependencies**: Ensure that your local environment meets the prerequisites for running Minikube, such as virtualization support. 32 | 33 | ### Conclusion 34 | 35 | Minikube is an invaluable tool for developers working with Kubernetes, providing a manageable and efficient way to develop and test applications locally. By understanding its capabilities and limitations, users can effectively leverage Minikube for a variety of development needs. 36 | -------------------------------------------------------------------------------- /33-minikube-config-view-status.md: -------------------------------------------------------------------------------- 1 | To read the memory and CPU count of your running Minikube instance, you can use the following commands: 2 | 3 | ### 1. **Check Memory and CPU Usage with `minikube status`:** 4 | The `minikube status` command provides the overall status of your Minikube instance, but it does not show memory or CPU allocation directly. Instead, use the next command. 5 | 6 | ### 2. **Check Minikube Configuration:** 7 | To see the memory and CPU settings for Minikube, use the `minikube config view` command to display the current configuration. 8 | 9 | ```bash 10 | minikube config view 11 | ``` 12 | 13 | This will show the configuration for memory and CPU if you have set them previously using the `minikube config set` command. 14 | 15 | ### 3. **Check CPU and Memory Allocation of the Running Minikube VM:** 16 | You can check the allocated resources (memory and CPU) for the running Minikube virtual machine by using: 17 | 18 | #### **On Linux/Mac with Docker as a driver:** 19 | 20 | ```bash 21 | docker inspect minikube | grep -E '"Memory":|"NanoCpus":' 22 | ``` 23 | 24 | This will display the memory (in bytes) and CPU settings (in nanoseconds) of the Minikube Docker container. 25 | 26 | #### **On Linux/Mac/Windows with VirtualBox as a driver:** 27 | If you're using VirtualBox as the driver, use the following command to check the VM details: 28 | 29 | ```bash 30 | VBoxManage showvminfo minikube | grep -E 'Memory size|CPU count' 31 | ``` 32 | 33 | This will show the memory size (in MB) and CPU count allocated to the Minikube VM. 34 | 35 | ### 4. **Use kubectl to Check Resource Limits of Minikube Components:** 36 | To see CPU and memory resource limits for Minikube system components, you can use `kubectl`: 37 | 38 | ```bash 39 | kubectl top nodes 40 | ``` 41 | 42 | This shows the current CPU and memory usage on the Minikube node (as well as other nodes if any are available). 43 | 44 | Alternatively, to check resource usage for pods: 45 | 46 | ```bash 47 | kubectl top pod -A 48 | ``` 49 | 50 | This command shows the CPU and memory usage of all the pods across all namespaces. 51 | 52 | ### 5. **Inspect with `minikube ssh` (if necessary):** 53 | If needed, you can SSH into the Minikube virtual machine and run typical Linux commands like `free -h` to check memory usage or `nproc` to see the CPU count: 54 | 55 | ```bash 56 | minikube ssh 57 | ``` 58 | 59 | Once inside the Minikube VM, run: 60 | - To check memory: 61 | ```bash 62 | free -h 63 | ``` 64 | - To check CPU count: 65 | ```bash 66 | nproc 67 | ``` -------------------------------------------------------------------------------- /34-minikube-in-commands.md: -------------------------------------------------------------------------------- 1 | After logging into the Minikube VM using `minikube ssh`, you can perform various operations with commands you can apply in the virtual machine. These operations are useful for managing the virtual machine (Linux-based) that Minikube runs on, monitoring system resources, and debugging. 2 | 3 | Here are some basic commands you can run inside and what they do: 4 | 5 | ### 1. **Checking System Information** 6 | - **To see the number of CPUs**: 7 | ```bash 8 | nproc 9 | ``` 10 | Shows the number of processors assigned to the virtual machine. 11 | 12 | - **To see memory (RAM) usage**: 13 | ```bash 14 | free -h 15 | ``` 16 | Shows the total, used, and free memory (RAM) of the system. 17 | 18 | - **To check disk usage**: 19 | ```bash 20 | df -h 21 | ``` 22 | Shows the usage status of disk partitions and remaining free space. 23 | 24 | ### 2. **Network and Internet Connection** 25 | - **To see the IP address**: 26 | ```bash 27 | ifconfig 28 | ``` 29 | Lists the IP addresses of the virtual machine's network interfaces. 30 | 31 | - **Connection test (Ping)**: 32 | ```bash 33 | ping 8.8.8.8 34 | ``` 35 | Tests whether the virtual machine has an internet connection. 36 | 37 | ### 3. **Checking Kubernetes Pods and Services** 38 | Since Minikube runs the Kubernetes node in a VM, you can also use `kubectl` commands inside the Minikube VM: 39 | 40 | - **To list pods**: 41 | ```bash 42 | kubectl get pods --all-namespaces 43 | ``` 44 | 45 | - **To list services**: 46 | ```bash 47 | kubectl get svc --all-namespaces 48 | ``` 49 | 50 | ### 4. **Monitoring System Performance** 51 | - **To monitor CPU and memory usage live**: 52 | ```bash 53 | top 54 | ``` 55 | Shows running processes, CPU and memory usage in real-time. 56 | 57 | ### 5. **Examining Log Files** 58 | You can access log files to get information about Kubernetes and other system services. 59 | 60 | - **To view system logs**: 61 | ```bash 62 | cat /var/log/syslog 63 | ``` 64 | You can read system logs. 65 | 66 | - **To view Kubernetes logs**: 67 | ```bash 68 | cat /var/log/kubelet.log 69 | ``` 70 | 71 | ### 6. **Package Management and Application Installation** 72 | The virtual machine is usually a small Linux distribution (e.g., Alpine). Therefore, you can install or remove software using the package management system. However, these operations may be limited as the virtual machine is typically lightweight and temporary. 73 | 74 | - **Updating installed packages (If package manager is available)**: 75 | ```bash 76 | sudo apt update && sudo apt upgrade 77 | ``` 78 | 79 | ### 7. **File Management** 80 | - **To see folder and file structure**: 81 | ```bash 82 | ls -lah 83 | ``` 84 | Shows detailed folder contents. 85 | 86 | - **To create a folder**: 87 | ```bash 88 | mkdir 89 | ``` 90 | 91 | - **To view file contents**: 92 | ```bash 93 | cat 94 | ``` 95 | 96 | ### 8. **Restarting Services** 97 | You can control and restart Kubernetes and other system services inside the Minikube VM. 98 | 99 | - **Restarting Kubernetes node**: 100 | ```bash 101 | sudo systemctl restart kubelet 102 | ``` 103 | 104 | - **Restarting Docker (If Minikube is using Docker)**: 105 | ```bash 106 | sudo systemctl restart docker 107 | ``` 108 | 109 | ### 9. **Connection Test Between Pods** 110 | - **To ping a pod**: 111 | ```bash 112 | ping 113 | ``` 114 | You can test if pods can access each other. 115 | 116 | ### 10. **Checking Kubernetes Cluster Status** 117 | - **To check Kubernetes node status**: 118 | ```bash 119 | kubectl get nodes 120 | ``` 121 | Lists the status of Kubernetes nodes. 122 | 123 | ### Notes: 124 | - The virtual machine may be temporary, so some changes you make may be lost when the Minikube virtual machine is restarted. 125 | - Some commands and operations may require sudo privileges. 126 | 127 | These commands allow you to perform various system management and Kubernetes management operations inside the Minikube virtual machine. -------------------------------------------------------------------------------- /35-linux-command.md: -------------------------------------------------------------------------------- 1 | Here are some basic commands you can use to learn about the Linux operating system and gather information about the system: 2 | 3 | ### 1. **System Information** 4 | - **Linux Distribution and Version**: 5 | ```bash 6 | lsb_release -a 7 | ``` 8 | This command shows the installed Linux distribution and its version. 9 | 10 | - **Kernel Version**: 11 | ```bash 12 | uname -r 13 | ``` 14 | Displays the version of the running Linux kernel. 15 | 16 | - **System Information**: 17 | ```bash 18 | uname -a 19 | ``` 20 | Shows general information about the running system (kernel name, version, architecture, etc.). 21 | 22 | ### 2. **Hardware Information** 23 | - **CPU Information**: 24 | ```bash 25 | lscpu 26 | ``` 27 | Provides information about the CPU. 28 | 29 | - **Memory Information**: 30 | ```bash 31 | free -h 32 | ``` 33 | Shows the total and available memory amount. 34 | 35 | - **Disk Information**: 36 | ```bash 37 | lsblk 38 | ``` 39 | Displays partitions on disks and disk usage status. 40 | 41 | ### 3. **File and Directory Management** 42 | - **View Current Directory**: 43 | ```bash 44 | pwd 45 | ``` 46 | Shows the full path of the directory you're in. 47 | 48 | - **List Files in Directory**: 49 | ```bash 50 | ls -l 51 | ``` 52 | Lists files in the current directory in detail. 53 | 54 | - **Change Directory**: 55 | ```bash 56 | cd 57 | ``` 58 | 59 | - **Create New Directory**: 60 | ```bash 61 | mkdir 62 | ``` 63 | 64 | - **Delete File**: 65 | ```bash 66 | rm 67 | ``` 68 | 69 | ### 4. **Getting Help and Information** 70 | - **Command Help**: 71 | ```bash 72 | man 73 | ``` 74 | Provides detailed information about a specific command (e.g., `man ls`). 75 | 76 | - **Command Usage Information**: 77 | ```bash 78 | --help 79 | ``` 80 | Gives brief information on how to use the command. 81 | 82 | ### 5. **System Status** 83 | - **View Running Processes**: 84 | ```bash 85 | ps aux 86 | ``` 87 | Lists all running processes in the system. 88 | 89 | - **View System Resource Usage**: 90 | ```bash 91 | top 92 | ``` 93 | Shows real-time CPU and memory usage of the system. 94 | 95 | ### 6. **Network Information** 96 | - **View Network Interfaces**: 97 | ```bash 98 | ip a 99 | ``` 100 | Shows network interfaces and IP addresses in the system. 101 | 102 | - **Connection Test**: 103 | ```bash 104 | ping 105 | ``` 106 | Performs a connection test to a specified address (e.g., `ping 8.8.8.8`). 107 | 108 | ### 7. **Software Management** 109 | - **Install Package** (on Debian-based systems): 110 | ```bash 111 | sudo apt install 112 | ``` 113 | 114 | - **Update Packages**: 115 | ```bash 116 | sudo apt update && sudo apt upgrade 117 | ``` 118 | 119 | ### 8. **Viewing Output Page by Page** 120 | - **View Output Page by Page with `less` or `more`**: 121 | ```bash 122 | | less 123 | ``` 124 | Used to read long outputs more comfortably. 125 | 126 | ### Conclusion 127 | These commands will help you perform basic operations and gather information about the system while working with the Linux operating system. To learn Linux better, you can try these commands and get more information from the man pages. -------------------------------------------------------------------------------- /40-kubectl-commands.md: -------------------------------------------------------------------------------- 1 | | **Command** | **Description** | 2 | |----------------------------------------------|-------------------------------------------------------------------| 3 | | `kubectl get pods` | List all pods in the current namespace. | 4 | | `kubectl get services` | List all services in the current namespace. | 5 | | `kubectl get deployments` | List all deployments in the current namespace. | 6 | | `kubectl describe pod ` | Display detailed information about a specific pod. | 7 | | `kubectl create -f ` | Create a resource defined in a YAML or JSON file. | 8 | | `kubectl apply -f ` | Apply changes to a resource defined in a YAML or JSON file. | 9 | | `kubectl delete pod ` | Delete a specific pod. | 10 | | `kubectl logs ` | Fetch logs from a specific pod. | 11 | | `kubectl exec -it -- /bin/bash` | Execute a command in a running pod (interactive shell). | 12 | | `kubectl scale deployment --replicas=` | Scale a deployment to a specified number of replicas. | 13 | | `kubectl port-forward :` | Forward one or more local ports to a pod. | 14 | | `kubectl get nodes` | List all nodes in the cluster. | 15 | | `kubectl get namespaces` | List all namespaces in the cluster. | 16 | | `kubectl config view` | View the current configuration and context. | 17 | | `kubectl top nodes` | Show metrics for nodes in the cluster (CPU/memory usage). | 18 | 19 | ### Usage 20 | 21 | To use these commands effectively, ensure you have `kubectl` installed and configured to communicate with your Kubernetes cluster. Always check the current context and namespace to avoid any confusion while managing your resources. 22 | 23 | ![](./images/kubernetes.drawio.png) 24 | -------------------------------------------------------------------------------- /50-pyhton-flesk-expose-deploy.md: -------------------------------------------------------------------------------- 1 | To run a Python application on Minikube, you'll follow a series of steps that involve setting up your Minikube environment, creating a Docker image for your Python application, and deploying that image to Minikube. 2 | 3 | ### Step 1: Start Minikube 4 | 5 | 1. **Open your terminal** and start Minikube: 6 | ```bash 7 | minikube start 8 | ``` 9 | 10 | 2. **Verify the status** of Minikube: 11 | ```bash 12 | minikube status 13 | ``` 14 | 15 | ### Step 2: Create a Simple Python Application 16 | 17 | 1. **Create a directory for your application**: 18 | ```bash 19 | mkdir my-python-app 20 | cd my-python-app 21 | ``` 22 | 23 | 2. **Create a Python file** (e.g., `app.py`): 24 | ```python 25 | # app.py 26 | from flask import Flask 27 | 28 | app = Flask(__name__) 29 | 30 | @app.route('/') 31 | def hello_world(): 32 | return 'Hello, World!' 33 | 34 | if __name__ == '__main__': 35 | app.run(host='0.0.0.0', port=8080) 36 | ``` 37 | 38 | 3. **Create a requirements file** (`requirements.txt`) for dependencies: 39 | ``` 40 | Flask==2.1.2 41 | ``` 42 | 43 | ### Step 3: Create a Dockerfile 44 | 45 | 1. **Create a `Dockerfile`** in the same directory: 46 | ```dockerfile 47 | # Dockerfile 48 | FROM python:3.9-slim 49 | 50 | WORKDIR /app 51 | COPY requirements.txt requirements.txt 52 | RUN pip install -r requirements.txt 53 | COPY . . 54 | 55 | CMD ["python", "app.py"] 56 | ``` 57 | 58 | ### Step 4: Build the Docker Image 59 | 60 | 1. **Set the Docker environment to Minikube**: 61 | ```bash 62 | eval $(minikube docker-env) 63 | ``` 64 | 65 | 2. **Build the Docker image**: 66 | ```bash 67 | docker build -t my-python-app . 68 | ``` 69 | 70 | ### Step 5: Create a Kubernetes Deployment 71 | 72 | 1. **Create a Kubernetes deployment file** (`deployment.yaml`): 73 | ```yaml 74 | apiVersion: apps/v1 75 | kind: Deployment 76 | metadata: 77 | name: my-python-app 78 | spec: 79 | replicas: 1 80 | selector: 81 | matchLabels: 82 | app: my-python-app 83 | template: 84 | metadata: 85 | labels: 86 | app: my-python-app 87 | spec: 88 | containers: 89 | - name: my-python-app 90 | image: my-python-app 91 | ports: 92 | - containerPort: 8080 93 | ``` 94 | 95 | 2. **Apply the deployment**: 96 | ```bash 97 | kubectl apply -f deployment.yaml 98 | ``` 99 | 100 | ### Step 6: Expose the Application 101 | 102 | 1. **Expose the deployment to access it externally**: 103 | ```bash 104 | kubectl expose deployment my-python-app --type=NodePort --port=8080 105 | ``` 106 | 107 | 2. **Get the URL to access your app**: 108 | ```bash 109 | minikube service my-python-app --url 110 | ``` 111 | 112 | ### Step 7: Access Your Application 113 | 114 | - Open your browser and navigate to the URL obtained from the previous command. You should see "Hello, World!" displayed. 115 | 116 | This command provides dev environment port and ip information 117 | ```bash 118 | minikube -p minikube docker-env 119 | ``` 120 | 121 | ### Conclusion 122 | 123 | You have successfully set up a simple Python application running in Minikube. You can now develop and test more complex applications using this setup. 124 | -------------------------------------------------------------------------------- /51-check-environment-curl-nodeport.md: -------------------------------------------------------------------------------- 1 | To test your Kubernetes service for your Python application using `curl`, follow these steps: 2 | 3 | ### Step 1: Ensure the Service is Running 4 | 5 | First, make sure your service is up and running. You can check the status of your service by running: 6 | 7 | ```bash 8 | kubectl get services 9 | ``` 10 | 11 | This command will show you the services currently available, including their types and ports. 12 | 13 | ### Step 2: Get the NodePort 14 | 15 | If you used the `NodePort` type for your service, you need to get the assigned port for your service. You can do this by inspecting your service: 16 | 17 | ```bash 18 | kubectl get service my-python-app 19 | ``` 20 | 21 | Look for the `NodePort` value in the output. It will look something like this: 22 | 23 | ``` 24 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 25 | my-python-app NodePort 10.96.0.1 8080:30001/TCP 5m 26 | ``` 27 | 28 | In this case, `30001` is the NodePort. 29 | 30 | ### Step 3: Get the Node IP Address 31 | 32 | You need the IP address of the node where your Minikube is running. You can obtain it with the following command: 33 | 34 | ```bash 35 | minikube ip 36 | ``` 37 | 38 | This command will return an IP address, such as `192.168.99.100`. 39 | 40 | ### Step 4: Test the Service Using `curl` 41 | 42 | Now that you have the Node IP address and the NodePort, you can test your service. Use the following `curl` command: 43 | 44 | ```bash 45 | curl http://: 46 | ``` 47 | 48 | For example, if your Node IP is `192.168.99.100` and your NodePort is `30001`, the command would look like this: 49 | 50 | ```bash 51 | curl http://192.168.99.100:30001 52 | ``` 53 | 54 | ### Step 5: Check the Response 55 | 56 | If everything is working correctly, you should receive a response from your Python application. Depending on your application's implementation, this could be a JSON response, HTML, or plain text. 57 | 58 | ### Summary of Commands 59 | 60 | Here’s a summary of the commands you will need: 61 | 62 | ```bash 63 | # Check existing services 64 | kubectl get services 65 | 66 | # Get the specific service details 67 | kubectl get service my-python-app 68 | 69 | # Get the Minikube IP address 70 | minikube ip 71 | 72 | # Test the service with curl 73 | curl http://: 74 | ``` 75 | 76 | ### Additional Tips 77 | 78 | - If you encounter any issues, double-check that your deployment and service are correctly configured. 79 | - Review the logs of your deployment for any errors that might indicate problems: 80 | 81 | ```bash 82 | kubectl logs deployment/my-python-app 83 | ``` -------------------------------------------------------------------------------- /53-codespace-stoped-restart-minikube.md: -------------------------------------------------------------------------------- 1 | If you've taken a break and come back to see that your Codespace has stopped, here’s how to resolve the issue step by step: 2 | 3 | ### Step-by-Step Instructions 4 | 5 | 1. **Refresh the Page:** 6 | - First, refresh the Codespace page to check if the issue is resolved after the stop. 7 | 8 | 2. **Restart Minikube:** 9 | - To ensure a stable environment, run the following commands to stop and restart Minikube: 10 | ```bash 11 | minikube stop 12 | minikube start 13 | ``` 14 | 15 | 3. **Check for Deleted Docker Images:** 16 | - Since the public image you pushed to Docker Hub (`docker.io`) was deleted, you will need to push it again. 17 | 18 | 4. **Navigate to Your Project Directory:** 19 | - Go to the working directory where your `my-python-app` project is located: 20 | ```bash 21 | cd my-python-app 22 | ``` 23 | 24 | 5. **Rebuild Your Docker Image:** 25 | - Compile and build your image again: 26 | ```bash 27 | docker build -t my-python-app . 28 | ``` 29 | 30 | 6. **Tag the Image for Docker Hub:** 31 | - Tag the Docker image using your Docker Hub username and the name of the app: 32 | ```bash 33 | docker tag my-python-app docker.io/tuncerkaraarslan/my-python-app:latest 34 | ``` 35 | 36 | ``` 37 | docker push docker.io/tuncerkaraarslan/my-python-app:latest 38 | ``` 39 | 40 | ``` 41 | kubectl set image deployment/my-python-app my-python-app=docker.io docker.io/tuncerkaraarslan/my-python-app:latest 42 | ``` 43 | 44 | 7. **Push the Image to Docker Hub:** 45 | 46 | - Docker Hub re login: 47 | ``` 48 | docker logout 49 | docker login docker.login 50 | ``` 51 | 52 | Create a Kubernetes secret for Docker registry credentials: 53 | ``` 54 | kubectl create secret docker-registry regcred \ 55 | --docker-username=tuncerkaraarslan \ 56 | --docker-password= \ 57 | --docker-email=tuncer.karaarslan@gmail.com 58 | ``` 59 | 60 | - Push the image to Docker Hub: 61 | ```bash 62 | docker push docker.io/tuncerkaraarslan/my-python-app:latest 63 | ``` 64 | 65 | 8. **Redeploy the Application in Minikube:** 66 | - Update your Kubernetes deployment with the new image: 67 | ```bash 68 | kubectl set image deployment/my-python-app my-python-app=docker.io/tuncerkaraarslan/my-python-app:latest 69 | ``` 70 | 71 | 9. **Verify the Status:** 72 | - Ensure that your deployment is running smoothly: 73 | ```bash 74 | kubectl get pods 75 | kubectl get services 76 | ``` 77 | 78 | 10. **Check Logs if Needed:** 79 | - If you encounter further issues, check the logs to diagnose: 80 | ```bash 81 | kubectl logs deployment/my-python-app 82 | ``` 83 | 84 | ``` 85 | kubectl describe pod 86 | ``` 87 | 88 | By following these steps, your environment should be restored and the `my-python-app` container should be up and running again in Minikube. -------------------------------------------------------------------------------- /80-practice/01/01-create-a-container.md: -------------------------------------------------------------------------------- 1 | # Work 1 2 | 3 | ## Create a docker image 4 | 5 | - create html folder 6 | - create index.html file into html folder 7 | -create Dockerfile 8 | 9 | - docker build -t sbm-nginx-app-1 . 10 | 11 | - docker images 12 | 13 | - docker run -d -p 8081:80 sbm-nginx-app-1 14 | 15 | open the browser with: http://localhost:8081 16 | 17 | ## If the image is to be deleted 18 | 19 | - docker images 20 | 21 | - docker rmi sbm-nginx-app-1 22 | 23 | ## If you want to check running docker containers 24 | 25 | - docker ps -a 26 | 27 | - docker stop [container-id] 28 | 29 | - docker rm [container-id] -------------------------------------------------------------------------------- /80-practice/01/Dockerfile: -------------------------------------------------------------------------------- 1 | # Nginx resmi imajını temel al 2 | FROM nginx:latest 3 | 4 | # HTML dosyalarını Nginx'in varsayılan dizinine kopyala 5 | COPY ./html /usr/share/nginx/html 6 | 7 | # Konteynerin 80 portunu dışarıya aç 8 | EXPOSE 80 9 | -------------------------------------------------------------------------------- /80-practice/01/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Sample HTML File 7 | 31 | 32 | 33 |
34 |

SBM SBM SBM Practice Projects - Example Day 2

35 |
36 |
37 |
38 |

SBM Sample Project 1 - some changed

39 |

This is a sample HTML file created to demonstrate the structure of an HTML document. You can use this as a template for your own web pages.

40 |
41 |
42 |

Useful Links

43 |

Check out W3Schools for more tutorials on web development.

44 |
45 |
46 |

Sample Image

47 | Sample Image 48 |
49 |
50 |
51 |

© 2024 My Sample HTML Page

52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /80-practice/02/01-create-a-container.md: -------------------------------------------------------------------------------- 1 | # Work 2 2 | 3 | ## Create a docker image 4 | 5 | - create html folder 6 | - create index.html file into html folder 7 | -create Dockerfile 8 | 9 | - docker build -t sbm-nginx-app-2 . 10 | 11 | - docker images 12 | 13 | - docker run -d -p 8082:82 sbm-nginx-app-2 14 | 15 | - docker ps -a 16 | 17 | - docker cp nginx.conf 533d349e4c37:/etc/nginx/nginx.conf 18 | 19 | - docker logs 533d349e4c37 20 | 21 | - docker restart 533d349e4c37 22 | 23 | - docker exec -it 533d349e4c37 /bin/bash 24 | 25 | 26 | open the browser with: http://localhost:8082 27 | 28 | ## If the image is to be deleted 29 | 30 | - docker images 31 | 32 | - docker rmi sbm-nginx-app-2 33 | 34 | ## If you want to check running docker containers 35 | 36 | - docker ps -a 37 | 38 | - docker stop [container-id] 39 | 40 | - docker rm [container-id] -------------------------------------------------------------------------------- /80-practice/02/Dockerfile: -------------------------------------------------------------------------------- 1 | # Nginx resmi imajını temel al 2 | FROM nginx:latest 3 | 4 | # HTML dosyalarını Nginx'in varsayılan dizinine kopyala 5 | COPY ./html /usr/share/nginx/html 6 | 7 | # Konteynerin 80 portunu dışarıya aç 8 | EXPOSE 82 9 | -------------------------------------------------------------------------------- /80-practice/02/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Sample HTML File 7 | 31 | 32 | 33 |
34 |

SBM Practice Projects

35 |
36 |
37 |
38 |

SBM Sample Project 2

39 |

This is a sample HTML file created to demonstrate the structure of an HTML document. You can use this as a template for your own web pages.

40 |
41 |
42 |

Useful Links

43 |

Check out W3Schools for more tutorials on web development.

44 |
45 |
46 |

Sample Image

47 | Sample Image 48 |
49 |
50 |
51 |

© 2024 My Sample HTML Page

52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /80-practice/02/nginx.conf: -------------------------------------------------------------------------------- 1 | # /etc/nginx/nginx.conf 2 | worker_processes 1; 3 | 4 | events { 5 | worker_connections 1024; 6 | } 7 | 8 | http { 9 | server { 10 | listen 82; 11 | server_name localhost; 12 | 13 | location / { 14 | root /usr/share/nginx/html; 15 | index index.html index.htm; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /80-practice/03/01-hub-upload.md: -------------------------------------------------------------------------------- 1 | # Upload to Hub 2 | 3 | - docker logout 4 | 5 | - docker login 6 | 7 | - docker tag sbm-nginx-app-2 tuncerkaraarslan/sbm-nginx-app-2:0.2 8 | 9 | - docker push tuncerkaraarslan/sbm-nginx-app-2:0.2 10 | -------------------------------------------------------------------------------- /80-practice/04/01-create-pod.md: -------------------------------------------------------------------------------- 1 | # creating pod service with kubectl 2 | 3 | - cd code 4 | 5 | - kubectl get pods 6 | 7 | - kubectl get svc 8 | 9 | - kubens sbm-dev 10 | 11 | - kubectl apply -f nginx-pod.yaml 12 | 13 | - kubectl get pods 14 | 15 | - kubectl apply -f nginx-service.yaml 16 | 17 | - kubectl get svc 18 | 19 | - kubectl logs nginx-pod 20 | 21 | - kubectl port-forward service/nginx-service 8082:80 22 | 23 | - html://localhost:8082 24 | -------------------------------------------------------------------------------- /80-practice/04/code/nginx-pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: nginx-pod 5 | labels: 6 | app: sbm-nginx 7 | spec: 8 | containers: 9 | - name: sbm-nginx 10 | image: tuncerkaraarslan/sbm-nginx-app-2:0.2 11 | ports: 12 | - containerPort: 80 13 | -------------------------------------------------------------------------------- /80-practice/04/code/nginx-service-2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | selector: 7 | app: sbm-nginx 8 | ports: 9 | - protocol: TCP 10 | port: 80 11 | targetPort: 80 12 | nodePort: 30080 # Belirli bir NodePort tanımlaması 13 | type: NodePort 14 | 15 | 16 | -------------------------------------------------------------------------------- /80-practice/04/code/nginx-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | selector: 7 | app: sbm-nginx 8 | ports: 9 | - protocol: TCP 10 | port: 80 11 | targetPort: 80 12 | type: NodePort 13 | -------------------------------------------------------------------------------- /80-practice/04/code/nginx.conf: -------------------------------------------------------------------------------- 1 | # /etc/nginx/nginx.conf 2 | worker_processes 1; 3 | 4 | events { 5 | worker_connections 1024; 6 | } 7 | 8 | http { 9 | server { 10 | listen 82; 11 | server_name localhost; 12 | 13 | location / { 14 | root /usr/share/nginx/html; 15 | index index.html index.htm; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /80-practice/05/code/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: sbm-nginx-app 5 | spec: 6 | replicas: 2 # ReplicaSet 2 olarak ayarlandı 7 | selector: 8 | matchLabels: 9 | app: sbm-nginx-app 10 | template: 11 | metadata: 12 | labels: 13 | app: sbm-nginx-app 14 | spec: 15 | containers: 16 | - name: sbm-nginx-app 17 | image: tuncerkaraarslan/sbm-nginx-app:0.3 18 | ports: 19 | - containerPort: 80 # Nginx'in default portu 20 | -------------------------------------------------------------------------------- /80-practice/05/code/ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: app1-ingress 5 | namespace: sbm-dev # Eğer farklı bir namespace kullanıyorsanız burayı değiştirin. 6 | annotations: 7 | nginx.ingress.kubernetes.io/rewrite-target: / 8 | spec: 9 | rules: 10 | - host: app1.sbm.gov.tr 11 | http: 12 | paths: 13 | - path: / 14 | pathType: Prefix 15 | backend: 16 | service: 17 | name: sbm-nginx-service # Yönlendireceğiniz servis adı 18 | port: 19 | number: 91 # Servis port numarası 20 | -------------------------------------------------------------------------------- /80-practice/05/code/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: sbm-nginx-service 5 | spec: 6 | selector: 7 | app: sbm-nginx-app # Deployment ile eşleşen label 8 | type: NodePort # NodePort tipi ile dış erişim sağlanır 9 | ports: 10 | - port: 91 # Servisin dinleyeceği port 11 | targetPort: 80 # Pod'daki container'ın dinlediği port 12 | nodePort: 30000 # Bu port, node üzerinde dışarıdan erişilebilir -------------------------------------------------------------------------------- /80-practice/05/reamde.md: -------------------------------------------------------------------------------- 1 | # publish with deployment 2 | 3 | ``` 4 | apiVersion: apps/v1 5 | kind: Deployment 6 | metadata: 7 | name: sbm-nginx-app 8 | spec: 9 | replicas: 5 # ReplicaSet 5 olarak ayarlandı 10 | selector: 11 | matchLabels: 12 | app: sbm-nginx-app 13 | template: 14 | metadata: 15 | labels: 16 | app: sbm-nginx-app 17 | spec: 18 | containers: 19 | - name: sbm-nginx-app 20 | image: tuncerkaraarslan/sbm-nginx-app:0.3 21 | ports: 22 | - containerPort: 80 # Nginx'in default portu 23 | 24 | ``` 25 | -------------------------------------------------------------------------------- /90-works-with-sbm/01/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:latest 2 | 3 | COPY ./html /usr/share/nginx/html 4 | COPY ./nginx.conf /etc/nginx/nginx.conf 5 | 6 | EXPOSE 88 7 | -------------------------------------------------------------------------------- /90-works-with-sbm/01/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | My Website 7 | 8 | 9 | 10 |
11 |

Welcome to My Website - SBM

12 | 20 |
21 | 22 |
23 |
24 |

Home

25 |

This is the home section of the website.

26 |
27 | 28 |
29 |

About

30 |

This section contains information about us.

31 |
32 | 33 |
34 |

Services

35 |

Here are the services we offer.

36 |
37 | 38 |
39 |

Contact

40 |

Contact us through this section.

41 |
42 |
43 | 44 |
45 |

© 2024 My Website. All rights reserved.

46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /90-works-with-sbm/01/nginx.conf: -------------------------------------------------------------------------------- 1 | # /etc/nginx/nginx.conf 2 | worker_processes 1; 3 | 4 | events { 5 | worker_connections 1024; 6 | } 7 | 8 | http { 9 | server { 10 | listen 88; 11 | server_name localhost; 12 | 13 | location / { 14 | root /usr/share/nginx/html; 15 | index index.html index.htm; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /demon/01-command-list.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, a **DaemonSet** ensures that a copy of a specific Pod runs on all (or a subset of) Nodes in a cluster. Here’s a list of common `kubectl` commands related to managing DaemonSets, along with their descriptions: 2 | 3 | ### Common `kubectl` Commands for DaemonSets 4 | 5 | 1. **List DaemonSets** 6 | ```bash 7 | kubectl get daemonsets 8 | ``` 9 | - Lists all DaemonSets in the current namespace. 10 | 11 | 2. **Describe a DaemonSet** 12 | ```bash 13 | kubectl describe daemonset 14 | ``` 15 | - Provides detailed information about a specific DaemonSet, including its Pods, events, and configuration. 16 | 17 | 3. **Create a DaemonSet from a YAML File** 18 | ```bash 19 | kubectl apply -f 20 | ``` 21 | - Creates a DaemonSet using the configuration defined in a YAML file. 22 | 23 | 4. **Delete a DaemonSet** 24 | ```bash 25 | kubectl delete daemonset 26 | ``` 27 | - Deletes a specified DaemonSet. 28 | 29 | 5. **Get DaemonSet YAML/JSON** 30 | ```bash 31 | kubectl get daemonset -o yaml 32 | ``` 33 | - Retrieves the DaemonSet configuration in YAML format. 34 | 35 | ```bash 36 | kubectl get daemonset -o json 37 | ``` 38 | - Retrieves the DaemonSet configuration in JSON format. 39 | 40 | 6. **Edit a DaemonSet** 41 | ```bash 42 | kubectl edit daemonset 43 | ``` 44 | - Opens the DaemonSet configuration in your default text editor for inline editing. 45 | 46 | 7. **Get Pods Managed by a DaemonSet** 47 | ```bash 48 | kubectl get pods --selector=app= 49 | ``` 50 | - Lists all Pods that are part of the specified DaemonSet by using a label selector. 51 | 52 | 8. **Scale a DaemonSet** 53 | ```bash 54 | kubectl scale daemonset --replicas= 55 | ``` 56 | - This command will not typically change the number of Pods in a DaemonSet (as DaemonSets typically run one Pod per Node), but it can be used for other scenarios. 57 | 58 | 9. **Get Events Related to a DaemonSet** 59 | ```bash 60 | kubectl get events --field-selector involvedObject.name= 61 | ``` 62 | - Displays events related to a specific DaemonSet, which can help in troubleshooting issues. 63 | 64 | ### Example of DaemonSet Creation 65 | 66 | Here’s an example of how to create a DaemonSet using a YAML file: 67 | 68 | 1. **Create a DaemonSet YAML file (e.g., `my-daemonset.yaml`)**: 69 | ```yaml 70 | apiVersion: apps/v1 71 | kind: DaemonSet 72 | metadata: 73 | name: my-daemonset 74 | spec: 75 | selector: 76 | matchLabels: 77 | app: my-daemon 78 | template: 79 | metadata: 80 | labels: 81 | app: my-daemon 82 | spec: 83 | containers: 84 | - name: my-daemon-container 85 | image: my-daemon-image 86 | ports: 87 | - containerPort: 8080 88 | ``` 89 | 90 | 2. **Apply the DaemonSet**: 91 | ```bash 92 | kubectl apply -f my-daemonset.yaml 93 | ``` 94 | 95 | ### Summary 96 | 97 | These commands provide a comprehensive toolkit for managing DaemonSets in Kubernetes. DaemonSets are essential for running background tasks, logging agents, or monitoring agents across all Nodes in the cluster. If you have any specific questions or need further details on any command, feel free to ask! -------------------------------------------------------------------------------- /images/kubernetes.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/images/kubernetes.drawio.png -------------------------------------------------------------------------------- /images/minikube-start-error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/images/minikube-start-error.png -------------------------------------------------------------------------------- /images/my-app-image-on-docker-io.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/images/my-app-image-on-docker-io.png -------------------------------------------------------------------------------- /minikube-linux-amd64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TuncerKARAARSLAN-VB/kubernetes-rancher-on-codespaces/648f6c415fa1b627c2c41fdd77dbf114d1c24e18/minikube-linux-amd64 -------------------------------------------------------------------------------- /my-python-app/Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile 2 | FROM python:3.9-slim 3 | 4 | WORKDIR /app 5 | COPY requirements.txt requirements.txt 6 | RUN pip install -r requirements.txt 7 | COPY . . 8 | 9 | CMD ["python", "app.py"] 10 | -------------------------------------------------------------------------------- /my-python-app/app.py: -------------------------------------------------------------------------------- 1 | # app.py 2 | from flask import Flask 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/') 7 | def hello_world(): 8 | return 'Hello, World!' 9 | 10 | if __name__ == '__main__': 11 | app.run(host='0.0.0.0', port=8080) 12 | -------------------------------------------------------------------------------- /my-python-app/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: my-python-app 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: my-python-app 10 | template: 11 | metadata: 12 | labels: 13 | app: my-python-app 14 | spec: 15 | containers: 16 | - name: my-python-app 17 | image: my-python-app 18 | ports: 19 | - containerPort: 8080 20 | -------------------------------------------------------------------------------- /my-python-app/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.1.2 2 | -------------------------------------------------------------------------------- /service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | type: NodePort 7 | ports: 8 | - port: 80 9 | targetPort: 80 10 | nodePort: 30001 # İsteğe bağlı: Belirli bir NodePort numarası 11 | selector: 12 | app: nginx 13 | 14 | --------------------------------------------------------------------------------