From 11304414680d7e58ced562c25a862fd5a85c2ee7 Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Fri, 7 Feb 2025 15:03:26 +0330 Subject: [PATCH 001/116] added docker stack file --- .../Docker/docker-stack-example.yml | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Containerization & Orchestration/Docker/docker-stack-example.yml diff --git a/Containerization & Orchestration/Docker/docker-stack-example.yml b/Containerization & Orchestration/Docker/docker-stack-example.yml new file mode 100644 index 0000000..d492724 --- /dev/null +++ b/Containerization & Orchestration/Docker/docker-stack-example.yml @@ -0,0 +1,74 @@ +version: "3.8" + +services: + web: + image: nginx:alpine + ports: + - "80:80" + deploy: + # Service mode: use "replicated" for a set number of replicas, + # or "global" to run one instance on every node. + mode: replicated + + # Number of container replicas to run (only applicable in replicated mode) + replicas: 3 + + # Rolling update configuration (applies when updating the service) + update_config: + # Number of containers to update at the same time + parallelism: 2 + # Delay between updating groups of containers (e.g., "10s" for 10 seconds) + delay: 10s + # Action to take if an update fails: rollback, pause, or continue + failure_action: rollback + # Time to monitor each updated container before proceeding to the next batch + monitor: 10s + # Maximum failure ratio (0.0 to 1.0) acceptable during the update + max_failure_ratio: 0.3 + + # Rollback configuration (applies if a deployment needs to be undone) + rollback_config: + parallelism: 1 + delay: 10s + # Action to take if rollback fails + failure_action: pause + monitor: 10s + max_failure_ratio: 0.2 + + # Restart policy for containers in the service + restart_policy: + # Restart condition can be "none", "on-failure", or "any" + condition: on-failure + # Delay between restart attempts + delay: 5s + # Maximum number of restart attempts before considering the container as failed + max_attempts: 3 + # Time window used to evaluate restart attempts (e.g., "120s") + window: 120s + + # Resource constraints and reservations for containers + resources: + limits: + # Maximum number of CPUs the container can use (as a fraction or whole number) + cpus: "0.50" + # Maximum memory (e.g., "50M" for 50 megabytes) + memory: 50M + reservations: + # Guaranteed minimum CPUs for the container + cpus: "0.25" + # Guaranteed minimum memory + memory: 20M + + # Placement constraints and preferences to control which nodes run the service + placement: + # Constraints ensure that only nodes meeting certain conditions are eligible. + constraints: + - node.role == manager + - node.labels.region == us-east + # Preferences allow you to influence (but not enforce) distribution. + preferences: + - spread: node.labels.az + + # Custom metadata labels for the service + labels: + com.example.description: "Sample web service using all deploy parameters" From 55347bfd59175cb87600b950a43305da548d184b Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Wed, 12 Feb 2025 21:08:15 +0330 Subject: [PATCH 002/116] Update Kuber Doc --- .../Kubernetes/3-Commands.md | 198 +++++++++++------- 1 file changed, 121 insertions(+), 77 deletions(-) diff --git a/Containerization & Orchestration/Kubernetes/3-Commands.md b/Containerization & Orchestration/Kubernetes/3-Commands.md index 5c36378..2041bd5 100755 --- a/Containerization & Orchestration/Kubernetes/3-Commands.md +++ b/Containerization & Orchestration/Kubernetes/3-Commands.md @@ -1,8 +1,12 @@ +Below is an improved version of your Kubernetes Command Reference. This revision enhances clarity, fixes typos, organizes related commands into logical sections, and standardizes formatting for readability. +--- # Kubernetes Command Reference -This document provides a reference for common `kubectl` commands used for managing Kubernetes clusters. Use the examples and explanations below to help manage nodes, namespaces, pods, deployments, and more. +This document provides a concise reference for common `kubectl` commands used to manage Kubernetes clusters. Whether you’re managing nodes, namespaces, pods, deployments, or autoscaling, the examples below will help you perform everyday tasks with ease. + +--- ## Table of Contents @@ -10,6 +14,9 @@ This document provides a reference for common `kubectl` commands used for managi - [Table of Contents](#table-of-contents) - [General Commands](#general-commands) - [Node Management](#node-management) + - [Listing Nodes](#listing-nodes) + - [Labeling Nodes](#labeling-nodes) + - [Node Maintenance (Cordon/Drain)](#node-maintenance-cordondrain) - [Namespace Management](#namespace-management) - [Pod Management](#pod-management) - [Listing Pods](#listing-pods) @@ -18,9 +25,10 @@ This document provides a reference for common `kubectl` commands used for managi - [API Resources and Documentation](#api-resources-and-documentation) - [Logs and Pod Information](#logs-and-pod-information) - [Applying YAML Files](#applying-yaml-files) - - [Managing Nodes and Labels](#managing-nodes-and-labels) - [Viewing Cluster Resources](#viewing-cluster-resources) - [ReplicaSet and Deployment Management](#replicaset-and-deployment-management) + - [Scaling and Rollouts](#scaling-and-rollouts) + - [Autoscaling](#autoscaling) - [Additional Information](#additional-information) --- @@ -29,6 +37,8 @@ This document provides a reference for common `kubectl` commands used for managi - **List API Resources** + Display all available API resources along with their short names: + ```bash kubectl api-resources ``` @@ -37,34 +47,65 @@ This document provides a reference for common `kubectl` commands used for managi ## Node Management -- **Show all nodes** +### Listing Nodes + +- **Show All Nodes** ```bash - kubectl get node + kubectl get nodes ``` -- **Set a label on a node** +### Labeling Nodes + +- **Set a Custom Label on a Node** ```bash - kubectl label nodes kubernetes.io/= + kubectl label node kubernetes.io/= ``` + > **Note:** Replace ``, ``, and `` with your desired values. + +### Node Maintenance (Cordon/Drain) + +- **Cordon a Node** + Prevent new pods from being scheduled on the node. + + ```bash + kubectl cordon + ``` + +- **Uncordon a Node** + Mark the node as schedulable again. + + ```bash + kubectl uncordon + ``` + +- **Drain a Node** + Evict all pods from the node (excluding those managed by DaemonSets). + + ```bash + kubectl drain --ignore-daemonsets --delete-local-data + ``` + + > **Warning:** Draining a node will evict running pods. Ensure this action is planned to avoid service disruption. + --- ## Namespace Management -- **List all namespaces** +- **List All Namespaces** ```bash kubectl get namespaces - # or the abbreviated version: + # Or use the shorthand: kubectl get ns ``` -- **Create a custom namespace** +- **Create a New Namespace** ```bash - kubectl create ns + kubectl create namespace ``` --- @@ -73,104 +114,103 @@ This document provides a reference for common `kubectl` commands used for managi ### Listing Pods -- **List pods in the default namespace** +- **List Pods in the Default Namespace** ```bash - kubectl get pod + kubectl get pods ``` -- **List pods with detailed information (wide output) in the default namespace** +- **List Pods with Detailed Information (Wide Output)** ```bash - kubectl get pod -o wide + kubectl get pods -o wide ``` -- **List pods with detailed information in a specific namespace** +- **List Pods in a Specific Namespace** ```bash - kubectl get pod -o wide -n + kubectl get pods -o wide -n ``` ### Running a Pod -- **Run a new pod** +> **Note:** While `kubectl run` is a versatile command, note that in recent Kubernetes versions it is primarily used for running single pods (not deployments). For more complex configurations, consider using YAML manifests. - Use the following command structure to run a pod with various options: +- **Basic Example:** ```bash - kubectl run { - --image=, # Container image to use - --port=, # Port that the container exposes - -n , # Namespace in which to run the pod - --env="KEY=VALUE", # Environment variables for the container - --command, # Treat the following arguments as the command - --replicas=, # Number of pod replicas to create - --labels="key=value,key2=value2", # Labels to assign to the pod(s) - --dry-run=client, # Print the object without creating it - --restart=, # Pod restart policy - --overrides='', # JSON override for the generated object - --image-pull-policy=, # Image pull policy (Always, IfNotPresent, Never) - --limits=cpu=,memory=, # Resource limits for the container - --requests=cpu=,memory= # Resource requests for the container - } + kubectl run --image= --port= -n ``` - - **Example:** +- **Advanced Example with Multiple Options:** - ```bash - kubectl run mypod --image=nginx --port=80 -n mynamespace \ - --env="ENV_VAR_NAME=VALUE" --command -- nginx -g "daemon off;" \ - --replicas=3 --labels="app=myapp,env=prod" --dry-run=client \ - --restart=Always --overrides='{"spec": {"containers": [{"name": "nginx", "image": "nginx"}]}}' \ - --image-pull-policy=IfNotPresent --limits=cpu=100m,memory=256Mi \ - --requests=cpu=50m,memory=128Mi - ``` + ```bash + kubectl run mypod --image=nginx --port=80 -n mynamespace \ + --env="ENV_VAR_NAME=VALUE" --command -- nginx -g "daemon off;" \ + --restart=Always --dry-run=client \ + --labels="app=myapp,env=prod" \ + --limits=cpu=100m,memory=256Mi --requests=cpu=50m,memory=128Mi + ``` + + **Common Options Explained:** + + - `--image`: Container image to use. + - `--port`: Port exposed by the container. + - `-n` or `--namespace`: Namespace in which to run the pod. + - `--env`: Set environment variables. + - `--command`: Treat the following arguments as the command to run. + - `--restart`: Pod restart policy (`Always`, `OnFailure`, or `Never`). + - `--labels`: Assign labels to the pod. + - `--dry-run`: Validate the command without creating the pod. + - `--limits` and `--requests`: Define resource limits and requests for the container. ### Deleting a Pod -- **Delete a pod in a custom namespace** +- **Delete a Pod in a Specific Namespace** ```bash - kubectl delete pod -n + kubectl delete pod -n ``` --- ## API Resources and Documentation -- **Get documentation for an API resource** +- **Get Detailed Documentation for an API Resource** ```bash kubectl explain ``` - - *Example:* + *Example:* - ```bash - kubectl explain pod - ``` + ```bash + kubectl explain pod + ``` --- ## Logs and Pod Information -- **Stream logs for a running pod** +- **Stream Logs for a Running Pod** ```bash kubectl logs -f -n ``` -- **Get detailed state and log information for a pod** +- **Get Detailed Information About a Pod** ```bash - kubectl describe pod -n + kubectl describe pod -n ``` --- ## Applying YAML Files -- **Apply configuration from a YAML file to a specific namespace** +- **Apply a Configuration from a YAML File** + + Apply a YAML configuration to a specific namespace: ```bash kubectl apply -f -n @@ -178,59 +218,65 @@ This document provides a reference for common `kubectl` commands used for managi --- -## Managing Nodes and Labels - -- **Label a node with a custom key-value pair** - - ```bash - kubectl label nodes kubernetes.io/= - ``` - ---- - ## Viewing Cluster Resources -- **Display all resources loaded in a namespace** +- **Display All Resources in a Namespace** ```bash kubectl get all -n ``` -- **Display replica sets, pods, and deployments in a specific namespace** +- **Display ReplicaSets, Pods, and Deployments in a Specific Namespace** ```bash - kubectl get rs,pod,deployment -n + kubectl get rs,pods,deployments -n ``` --- ## ReplicaSet and Deployment Management +### Scaling and Rollouts + - **Scale a ReplicaSet** ```bash - kubectl scale rs -n --replicas= + kubectl scale rs --replicas= -n ``` -- **View rollout history of a deployment** +- **View Rollout History of a Deployment** ```bash - kubectl rollout history deployment -n + kubectl rollout history deployment -n ``` -- **View details of a specific revision in a deployment's rollout history** +- **View Details of a Specific Revision** ```bash - kubectl rollout history deployment -n --revision + kubectl rollout history deployment -n --revision= ``` -- **Roll back a deployment to a specific revision** +- **Roll Back a Deployment to a Specific Revision** ```bash - kubectl rollout undo deployment -n --to-revision= + kubectl rollout undo deployment -n --to-revision= ``` - > **Note:** The command for rolling back to a specific revision is `kubectl rollout undo` rather than using `--to-revision` with `kubectl rollout history`. +### Autoscaling + +- **Autoscale a Deployment** + + Automatically scale a deployment based on CPU utilization: + + ```bash + kubectl autoscale deployment -n --cpu-percent= --min= --max= + ``` + +- **View Horizontal Pod Autoscalers (HPA)** + + ```bash + kubectl get hpa -n + ``` --- @@ -238,6 +284,4 @@ This document provides a reference for common `kubectl` commands used for managi - **Static Manifest Files** - All YAML files located under `/etc/kubernetes/manifests/` are automatically loaded after a server reboot. - ---- + Any YAML files placed in `/etc/kubernetes/manifests/` are automatically loaded when the kubelet starts (for example, after a server reboot). From d831f0e72f711f923263aac110ae4d3e394ef376 Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Thu, 13 Feb 2025 00:24:16 +0330 Subject: [PATCH 003/116] Added Wordload files --- .../Kubernetes/workloads/cronjob.yaml | 20 +++++++++++++ .../Kubernetes/workloads/deployment.yaml | 28 +++++++++++++++++++ .../Kubernetes/workloads/ds.yml | 19 +++++++++++++ .../Kubernetes/workloads/job.yaml | 15 ++++++++++ .../Kubernetes/workloads/namespace.yaml | 5 ++++ .../Kubernetes/workloads/pod.yaml | 23 +++++++++++++++ .../Kubernetes/workloads/replicaset.yml | 18 ++++++++++++ 7 files changed, 128 insertions(+) create mode 100644 Containerization & Orchestration/Kubernetes/workloads/cronjob.yaml create mode 100644 Containerization & Orchestration/Kubernetes/workloads/deployment.yaml create mode 100644 Containerization & Orchestration/Kubernetes/workloads/ds.yml create mode 100644 Containerization & Orchestration/Kubernetes/workloads/job.yaml create mode 100644 Containerization & Orchestration/Kubernetes/workloads/namespace.yaml create mode 100644 Containerization & Orchestration/Kubernetes/workloads/pod.yaml create mode 100644 Containerization & Orchestration/Kubernetes/workloads/replicaset.yml diff --git a/Containerization & Orchestration/Kubernetes/workloads/cronjob.yaml b/Containerization & Orchestration/Kubernetes/workloads/cronjob.yaml new file mode 100644 index 0000000..b8396e3 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/cronjob.yaml @@ -0,0 +1,20 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: cronjob1 + namespace: ns-test +spec: + schedule: "* * * * *" + jobTemplate: + spec: + template: + spec: + containers: + - name: mycronjob + image: debian + command: + - /bin/bash + - -c + - "echo 'Hello, CronJob!'" + restartPolicy: Never + diff --git a/Containerization & Orchestration/Kubernetes/workloads/deployment.yaml b/Containerization & Orchestration/Kubernetes/workloads/deployment.yaml new file mode 100644 index 0000000..fa20bc0 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/deployment.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-deployment + namespace: ns-test + labels: + name: deployment-test +spec: + replicas: 2 + selector: + matchLabels: + name: app1 + template: + metadata: + labels: + name: app1 + spec: + containers: + - name: nginx-deployment + image: nginx:1.26 + resources: + limits: + cpu: "400m" + memory: "512Mi" + requests: + cpu: "200m" + memory: "128Mi" + diff --git a/Containerization & Orchestration/Kubernetes/workloads/ds.yml b/Containerization & Orchestration/Kubernetes/workloads/ds.yml new file mode 100644 index 0000000..9ab75a1 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/ds.yml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: daemonset-test + namespace: ns-test +spec: + selector: + matchLabels: + name: node-exporter + template: + metadata: + labels: + name: node-exporter + spec: + containers: + - name: node-exporter + image: prom/node-exporter + + diff --git a/Containerization & Orchestration/Kubernetes/workloads/job.yaml b/Containerization & Orchestration/Kubernetes/workloads/job.yaml new file mode 100644 index 0000000..67bd525 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/job.yaml @@ -0,0 +1,15 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: job1 + namespace: ns-test +spec: + template: + spec: + containers: + - name: job-container + image: debian + command: + - echo + - "hello world" + restartPolicy: Never diff --git a/Containerization & Orchestration/Kubernetes/workloads/namespace.yaml b/Containerization & Orchestration/Kubernetes/workloads/namespace.yaml new file mode 100644 index 0000000..0b8d1d8 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/namespace.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: ns-test + diff --git a/Containerization & Orchestration/Kubernetes/workloads/pod.yaml b/Containerization & Orchestration/Kubernetes/workloads/pod.yaml new file mode 100644 index 0000000..66dae37 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/pod.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Pod +metadata: + namespace: ns-test + name: pod-tests + labels: + var1: var1_value + var2: var2_value + app.kubernetes.io/var3: var3_value + app.kubernetes.io/var4: var4_value +spec: + containers: + - name: nginx + image: nginx + resources: + limits: + memory: "150Mi" + cpu: "500m" + requests: + memory: "100Mi" + cpu: "200m" + nodeSelector: + kubernetes.io/hostname: kuber-2 diff --git a/Containerization & Orchestration/Kubernetes/workloads/replicaset.yml b/Containerization & Orchestration/Kubernetes/workloads/replicaset.yml new file mode 100644 index 0000000..b7eaf4b --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/replicaset.yml @@ -0,0 +1,18 @@ +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: app1 + namespace: ns-test +spec: + replicas: 3 + selector: + matchLabels: + app.kubernetes.io/name: app1 + template: + metadata: + labels: + app.kubernetes.io/name: app1 + spec: + containers: + - name: nginx + image: nginx From e182881068a1d12c3b85df58a6931a0f03785647 Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Sat, 15 Feb 2025 17:28:07 +0330 Subject: [PATCH 004/116] added some file and updated --- .../Kubernetes/3-Commands.md | 49 ++++++++++++------- .../workloads/deployment-with-service.yaml | 23 +++++++++ .../Kubernetes/workloads/service.yaml | 15 ++++++ 3 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 Containerization & Orchestration/Kubernetes/workloads/deployment-with-service.yaml create mode 100644 Containerization & Orchestration/Kubernetes/workloads/service.yaml diff --git a/Containerization & Orchestration/Kubernetes/3-Commands.md b/Containerization & Orchestration/Kubernetes/3-Commands.md index 2041bd5..4c9ce9d 100755 --- a/Containerization & Orchestration/Kubernetes/3-Commands.md +++ b/Containerization & Orchestration/Kubernetes/3-Commands.md @@ -1,10 +1,10 @@ -Below is an improved version of your Kubernetes Command Reference. This revision enhances clarity, fixes typos, organizes related commands into logical sections, and standardizes formatting for readability. +Below is an enhanced version of your Kubernetes Command Reference. This revision further refines the structure, improves consistency, and adds a few extra sections for clarity and ease of use. --- # Kubernetes Command Reference -This document provides a concise reference for common `kubectl` commands used to manage Kubernetes clusters. Whether you’re managing nodes, namespaces, pods, deployments, or autoscaling, the examples below will help you perform everyday tasks with ease. +This guide provides a concise reference for common `kubectl` commands used to manage Kubernetes clusters. Whether you’re managing nodes, namespaces, pods, deployments, or autoscaling, the examples below will help you perform everyday tasks with confidence. --- @@ -22,21 +22,21 @@ This document provides a concise reference for common `kubectl` commands used to - [Listing Pods](#listing-pods) - [Running a Pod](#running-a-pod) - [Deleting a Pod](#deleting-a-pod) - - [API Resources and Documentation](#api-resources-and-documentation) - - [Logs and Pod Information](#logs-and-pod-information) + - [API Resources \& Documentation](#api-resources--documentation) + - [Logs \& Pod Information](#logs--pod-information) - [Applying YAML Files](#applying-yaml-files) - [Viewing Cluster Resources](#viewing-cluster-resources) - - [ReplicaSet and Deployment Management](#replicaset-and-deployment-management) + - [ReplicaSet \& Deployment Management](#replicaset--deployment-management) - [Scaling and Rollouts](#scaling-and-rollouts) - [Autoscaling](#autoscaling) + - [Port Forwarding](#port-forwarding) - [Additional Information](#additional-information) --- ## General Commands -- **List API Resources** - +- **List API Resources** Display all available API resources along with their short names: ```bash @@ -88,7 +88,7 @@ This document provides a concise reference for common `kubectl` commands used to kubectl drain --ignore-daemonsets --delete-local-data ``` - > **Warning:** Draining a node will evict running pods. Ensure this action is planned to avoid service disruption. + > **Warning:** Draining a node will evict running pods. Ensure that you plan this action to avoid service disruption. --- @@ -98,7 +98,7 @@ This document provides a concise reference for common `kubectl` commands used to ```bash kubectl get namespaces - # Or use the shorthand: + # Or the shorthand: kubectl get ns ``` @@ -134,7 +134,7 @@ This document provides a concise reference for common `kubectl` commands used to ### Running a Pod -> **Note:** While `kubectl run` is a versatile command, note that in recent Kubernetes versions it is primarily used for running single pods (not deployments). For more complex configurations, consider using YAML manifests. +> **Note:** The `kubectl run` command is best suited for running single pods. For more complex deployments, consider using YAML manifests. - **Basic Example:** @@ -174,7 +174,7 @@ This document provides a concise reference for common `kubectl` commands used to --- -## API Resources and Documentation +## API Resources & Documentation - **Get Detailed Documentation for an API Resource** @@ -190,7 +190,7 @@ This document provides a concise reference for common `kubectl` commands used to --- -## Logs and Pod Information +## Logs & Pod Information - **Stream Logs for a Running Pod** @@ -234,7 +234,7 @@ This document provides a concise reference for common `kubectl` commands used to --- -## ReplicaSet and Deployment Management +## ReplicaSet & Deployment Management ### Scaling and Rollouts @@ -264,8 +264,7 @@ This document provides a concise reference for common `kubectl` commands used to ### Autoscaling -- **Autoscale a Deployment** - +- **Autoscale a Deployment** Automatically scale a deployment based on CPU utilization: ```bash @@ -280,8 +279,24 @@ This document provides a concise reference for common `kubectl` commands used to --- +## Port Forwarding + +Sometimes you need to access a service or pod directly from your local machine. Use the following command to forward a port: + +```bash +kubectl port-forward -n svc/ : +``` + +> **Example:** Forward local port 8080 to port 80 of the service named `my-service` in the `mynamespace` namespace: +> +> ```bash +> kubectl port-forward -n mynamespace svc/my-service 8080:80 +> ``` + +--- + ## Additional Information -- **Static Manifest Files** - +- **Static Manifest Files** Any YAML files placed in `/etc/kubernetes/manifests/` are automatically loaded when the kubelet starts (for example, after a server reboot). + diff --git a/Containerization & Orchestration/Kubernetes/workloads/deployment-with-service.yaml b/Containerization & Orchestration/Kubernetes/workloads/deployment-with-service.yaml new file mode 100644 index 0000000..912d9a0 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/deployment-with-service.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-deployment + namespace: ns-test + labels: + name: deployment-test + app: nginx +spec: + replicas: 2 + selector: + matchLabels: + name: app1 + app: nginx + template: + metadata: + labels: + name: app1 + app: nginx + spec: + containers: + - name: nginx-deployment + image: nginx:1.26 diff --git a/Containerization & Orchestration/Kubernetes/workloads/service.yaml b/Containerization & Orchestration/Kubernetes/workloads/service.yaml new file mode 100644 index 0000000..e2cf24d --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx + namespace: ns-test + labels: + app: nginx +spec: + type: NodePort # ClusterIP Or LoadBalancer + selector: + app: nginx + ports: + - name: http + port: 80 + targetPort: 80 From 91faa030faea18e4abf20d0755dbf8a05c178471 Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Wed, 9 Apr 2025 14:59:32 +0200 Subject: [PATCH 005/116] update kuber doc --- Containerization & Orchestration/Kubernetes/3-Commands.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Containerization & Orchestration/Kubernetes/3-Commands.md b/Containerization & Orchestration/Kubernetes/3-Commands.md index 4c9ce9d..c28e7cf 100755 --- a/Containerization & Orchestration/Kubernetes/3-Commands.md +++ b/Containerization & Orchestration/Kubernetes/3-Commands.md @@ -1,7 +1,3 @@ -Below is an enhanced version of your Kubernetes Command Reference. This revision further refines the structure, improves consistency, and adds a few extra sections for clarity and ease of use. - ---- - # Kubernetes Command Reference This guide provides a concise reference for common `kubectl` commands used to manage Kubernetes clusters. Whether you’re managing nodes, namespaces, pods, deployments, or autoscaling, the examples below will help you perform everyday tasks with confidence. From 5e3d651660736ee41f02baa60f11661d9d6b8d3d Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Wed, 9 Apr 2025 15:24:55 +0200 Subject: [PATCH 006/116] added nfs document --- Storage/NFS/setup.md | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Storage/NFS/setup.md diff --git a/Storage/NFS/setup.md b/Storage/NFS/setup.md new file mode 100644 index 0000000..7af2176 --- /dev/null +++ b/Storage/NFS/setup.md @@ -0,0 +1,121 @@ +# 📡 NFS Server & Client Setup Guide (Ubuntu) + +Easily set up a Network File System (NFS) for sharing files between Linux systems on the same network. + +--- + +## 🖥️ Server Configuration (Ubuntu) + +### 1. Install NFS Kernel Server + +Install the required package: + +```bash +sudo apt update +sudo apt install nfs-kernel-server +``` + +### 2. Create a Shared Directory + +Replace `` with your preferred path: + +```bash +sudo mkdir -p +sudo chown nobody:nogroup +sudo chmod 777 +``` + +> ✅ *Best practice:* Use a dedicated directory for NFS shares, e.g., `/srv/nfs/shared`. + +### 3. Configure NFS Exports + +Create an exports configuration file: + +```bash +sudo vim /etc/exports.d/shared.exports +``` + +Add the following line (update paths and IPs accordingly): + +``` + (rw,sync,no_root_squash,no_subtree_check) +``` + +> 💡 **Notes:** +> - ``: Full path to the directory you want to share +> - ``: IP address of the client allowed to access the share + +### 4. Apply Export Changes + +```bash +sudo exportfs -ra +``` + +### 5. Enable and Restart NFS Service + +```bash +sudo systemctl enable nfs-server +sudo systemctl restart nfs-server +``` + +--- + +## 💻 Client Configuration (Ubuntu) + +### 1. Install NFS Client Packages + +```bash +sudo apt update +sudo apt install nfs-common rpcbind +``` + +### 2. Create a Mount Point + +Choose a local directory to mount the share (e.g., `/mnt/nfs`): + +```bash +sudo mkdir -p +sudo chmod 777 +``` + +### 3. Mount the NFS Share (Temporary) + +```bash +sudo mount -t nfs : +``` + +> Example: +> `sudo mount -t nfs 192.168.0.10:/srv/nfs/shared /mnt/nfs` + +### 4. Enable Auto-Mount at Boot + +Edit the fstab file: + +```bash +sudo vim /etc/fstab +``` + +Add this line: + +``` +: nfs defaults 0 0 +``` + +> Example: +> `192.168.0.10:/srv/nfs/shared /mnt/nfs nfs defaults 0 0` + +### 5. Verify and Reload Mounts + +```bash +sudo mount -a +``` + +--- + +## ✅ Final Checklist + +- 🔄 NFS server and client packages installed +- 📁 Shared and mount directories properly set +- 🔐 Permissions and access IPs correctly configured +- ⚙️ Auto-mount enabled with `/etc/fstab` + From 92e3749529347089e7596b0ddc853c11927dfaf3 Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Fri, 16 May 2025 00:15:52 +0330 Subject: [PATCH 007/116] docker doc: update swarm doc --- .../Docker/5-Docker-Swarm.md | 172 +++++++++++------- 1 file changed, 104 insertions(+), 68 deletions(-) diff --git a/Containerization & Orchestration/Docker/5-Docker-Swarm.md b/Containerization & Orchestration/Docker/5-Docker-Swarm.md index 1f19db3..cdc471d 100755 --- a/Containerization & Orchestration/Docker/5-Docker-Swarm.md +++ b/Containerization & Orchestration/Docker/5-Docker-Swarm.md @@ -1,89 +1,85 @@ -# Docker Swarm Documentation +# 📦 Docker Swarm Documentation -This guide covers key commands and workflows for managing a Docker Swarm cluster. It includes information on initializing the cluster, node management, service management, and best practices to ensure your cluster remains operational. +Comprehensive guide to managing a **Docker Swarm** cluster. This document includes core commands, workflows, and best practices for maintaining a healthy and operational environment. --- -## Table of Contents +## 📚 Table of Contents -1. [Cluster Health & Manager Count](#cluster-health--manager-count) -2. [Example Workflow: Setting Up Nginx](#example-workflow-setting-up-nginx) -3. [Cluster Initialization and Management](#cluster-initialization-and-management) -4. [Node Management](#node-management) -5. [Service Management](#service-management) -6. [Join Tokens](#join-tokens) +1. [🔧 Cluster Health & Manager Count](#-cluster-health--manager-count) +2. [🚀 Example Workflow: Setting Up Nginx](#-example-workflow-setting-up-nginx) +3. [⚙️ Cluster Initialization and Management](#️-cluster-initialization-and-management) +4. [🖥️ Node Management](#️-node-management) +5. [🛠️ Service Management](#️-service-management) +6. [🔑 Join Tokens & Node Configuration](#-join-tokens--node-configuration) --- -## Cluster Health & Manager Count +## 🔧 Cluster Health & Manager Count -To maintain a healthy and functional Docker Swarm cluster, **the number of manager nodes must exceed 50% of the total nodes**. If the manager nodes fall below 51% of the cluster, the system will lose quorum and become non-operational. Always monitor your manager count to ensure high availability. +A Docker Swarm cluster requires a **majority of manager nodes** to be functional for quorum. + +> **Best Practice:** Always maintain **more than 50%** manager nodes online. Losing quorum will render the cluster non-operational. --- -## Example Workflow: Setting Up Nginx +## 🚀 Example Workflow: Setting Up Nginx -When deploying services such as Nginx, the typical workflow in Docker Swarm is: +Docker Swarm handles service deployment through several internal components: -1. **API**: Handle incoming requests. -2. **Allocator**: Distribute workload to available nodes. -3. **Dispatcher**: Manage task assignments. -4. **Scheduler**: Ensure tasks run on the optimal nodes. +1. **API** – Receives service requests. +2. **Allocator** – Determines resource allocation. +3. **Dispatcher** – Assigns tasks to nodes. +4. **Scheduler** – Places tasks on optimal nodes. -This workflow ensures that your service is efficiently distributed and scaled across the cluster. +This process ensures resilient and efficient service distribution. --- -## Cluster Initialization and Management +## ⚙️ Cluster Initialization and Management -### Create Cluster +### 🔹 Initialize Cluster -Initialize a new Docker Swarm cluster: ```bash docker swarm init ``` -This command sets up the current node as the manager of a new cluster. -### Create Cluster with a Specific Interface +### 🔹 Initialize with Specific Interface -Specify an IP address or interface name when initializing the cluster: ```bash -docker swarm init --advertise-addr +docker swarm init --advertise-addr ``` -This ensures that the node advertises the correct network interface for other nodes to join. -### Join Cluster +### 🔹 Join Existing Cluster -Add a node to an existing Docker Swarm cluster: ```bash docker swarm join ``` -### Leave Cluster +### 🔹 Leave Cluster -Remove a node from the cluster: ```bash docker swarm leave ``` -### Unlock Locked Manager +### 🔹 Unlock a Manager Node -Unlock a manager node that has been locked: ```bash docker swarm unlock ``` --- -## Node Management +## 🖥️ Node Management -### List Nodes +### 🔸 List Nodes -View the status and details of all nodes in your cluster: ```bash docker node ls ``` + **Example Output:** + ``` ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION 8yw8jrjeqczaci0qkuy060g09 * docker-1 Ready Active Leader 24.0.5 @@ -92,101 +88,141 @@ kd3ujmt1ey3pw6v9189fouxfa docker-3 Ready Active Reachable tm1msy58ztcltt36rs1lb76p7 docker-4 Down Active 24.0.5 ``` -### Remove Node +### 🔸 Remove a Node -Remove a node from the cluster by specifying its ID: ```bash docker node rm ``` -**Example:** + +### 🔸 Promote to Manager + ```bash -docker node rm tm1msy58ztcltt36rs1lb76p7 +docker node promote ``` -### Promote Node to Manager +### 🔸 Inspect a Node -Upgrade a worker node to a manager node: ```bash -docker node promote +docker node inspect ``` -**Example:** + +### 🔸 Change Node Role + ```bash -docker node promote v4gvf7xenw0izmxgvhr6hb2rj +docker node update --role manager +docker node update --role worker +``` + +### 🔸 Change Node Availability + +```bash +docker node update --availability active +docker node update --availability pause +docker node update --availability drain +``` + +### 🔸 Add or Remove Labels + +**Add:** + +```bash +docker node update --label-add env=development +docker node update --label-add env=testing +``` + +**Remove:** + +```bash +docker node update --label-rm env= +docker node update --label-rm env +``` + +**Use label constraints in service deployment:** + +```yaml +deploy: + placement: + constraints: + - node.labels.env == development ``` -This command promotes the specified node, enabling it to participate in cluster management decisions. --- -## Service Management +## 🛠️ Service Management -### Show Task Status on Cluster +### 🔹 Show Tasks on a Node -Display the status of tasks running on each node: ```bash docker node ps ``` -### List Services +### 🔹 List All Services -List all services currently running in the cluster: ```bash docker service ls ``` -### Create Service +### 🔹 Create a New Service -Create a new service with the specified name and Docker image: ```bash docker service create --name ``` -### Scale Service +### 🔹 Scale a Service -Adjust the number of replicas for an existing service: ```bash docker service scale = ``` + **Example:** + ```bash docker service scale nginx=5 ``` -This command scales the `nginx` service to 5 replicas. -### Inspect Service +### 🔹 Inspect a Service -View detailed information about a specific service: ```bash docker service inspect ``` -### Create Service with Replicas and Environment Variables +### 🔹 Create Service with Replicas, Env Vars, and Port Mapping -Launch a new service with multiple replicas, environment variables, and port publishing: ```bash -docker service create --name --replicas --env --publish : +docker service create \ + --name \ + --replicas \ + --env \ + --publish : \ + ``` + **Example:** + ```bash -docker service create --name nginx --replicas 3 --env MY_ENV_VAR=value --publish 8080:80 nginx +docker service create \ + --name nginx \ + --replicas 3 \ + --env MY_ENV_VAR=value \ + --publish 8080:80 \ + nginx ``` -This creates an `nginx` service with 3 replicas, sets the environment variable `MY_ENV_VAR` to `value`, and maps port 8080 on the host to port 80 in the container. --- -## Join Tokens +## 🔑 Join Tokens & Node Configuration -To securely add new nodes to the swarm, use the join tokens provided by Docker Swarm. +Securely add nodes to your Swarm using join tokens. -### Get Worker Join Token +### 🔹 Get Worker Token -Display the token required for a node to join as a worker: ```bash docker swarm join-token worker ``` -### Get Manager Join Token +### 🔹 Get Manager Token -Display the token required for a node to join as a manager: ```bash docker swarm join-token manager ``` + From 4ef37b9655a1545cda0c8ac4b39997d465afe556 Mon Sep 17 00:00:00 2001 From: RadinPirouz <75082987+RadinPirouz@users.noreply.github.com> Date: Fri, 16 May 2025 15:37:50 +0330 Subject: [PATCH 008/116] Update README.md --- README.md | 117 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 80 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 22d8b10..b07ff94 100755 --- a/README.md +++ b/README.md @@ -1,56 +1,99 @@ -# Linux Documents +# 🐧 Linux Documents -Welcome to the Linux Documents repository! This collection serves as a comprehensive resource for various Linux-related configurations, setups, and management scripts. It is designed to assist system administrators, developers, and enthusiasts in deploying and managing different services and applications on Linux-based systems. +A curated collection of scripts, configuration files, and guides for managing and configuring Linux-based systems. This personal repository serves as a comprehensive knowledge base to simplify deployment, automation, monitoring, security, and much more. -## Table of Contents +--- -### Configuration Management & Automation -- [Ansible](https://github.com/RadinPirouz/linux-documents/tree/main/Configuration%20Management%20%26%20Automation/Ansible) -- [CronJob](https://github.com/RadinPirouz/linux-documents/tree/main/Configuration%20Management%20%26%20Automation/CronJob) +## 📂 Repository Structure -### Web Development & Frameworks -- [Django](https://github.com/RadinPirouz/linux-documents/tree/main/Web%20Development%20%26%20Frameworks/Django) -- [LaravelAPI](https://github.com/RadinPirouz/linux-documents/tree/main/Web%20Development%20%26%20Frameworks/LaravelAPI) -- [LaravelOnNginx](https://github.com/RadinPirouz/linux-documents/tree/main/Web%20Development%20%26%20Frameworks/LaravelOnNginx) +### ⚙️ Configuration Management & Automation +- [Ansible](./Configuration%20Management%20&%20Automation/Ansible) +- [CronJob](./Configuration%20Management%20&%20Automation/CronJob) -### Containerization & Orchestration -- [Docker](https://github.com/RadinPirouz/linux-documents/tree/main/Containerization%20%26%20Orchestration/Docker) -- [Kubernetes](https://github.com/RadinPirouz/linux-documents/tree/main/Containerization%20%26%20Orchestration/Kubernetes) +### 🐳 Containerization & Orchestration +- [Docker](./Containerization%20&%20Orchestration/Docker) +- [Kubernetes](./Containerization%20&%20Orchestration/Kubernetes) -### Monitoring & Logging -- [Grafana](https://github.com/RadinPirouz/linux-documents/tree/main/Monitoring%20%26%20Logging/Grafana) -- [Librenms](https://github.com/RadinPirouz/linux-documents/tree/main/Monitoring%20%26%20Logging/Librenms) -- [Netdata](https://github.com/RadinPirouz/linux-documents/tree/main/Monitoring%20%26%20Logging/Netdata) -- [Zabbix](https://github.com/RadinPirouz/linux-documents/tree/main/Monitoring%20%26%20Logging/Zabbix) +### 🗄️ Databases +- [Postgresql](./Databases/Postgresql) -### Networking & Security -- [Iptables](https://github.com/RadinPirouz/linux-documents/tree/main/Networking%20%26%20Security/Iptables) -- [Nmap](https://github.com/RadinPirouz/linux-documents/tree/main/Networking%20%26%20Security/Nmap) -- [Nginx](https://github.com/RadinPirouz/linux-documents/tree/main/Networking%20%26%20Security/Nginx) -- [FileSharing](https://github.com/RadinPirouz/linux-documents/tree/main/Networking%20%26%20Security/FileSharing) +### ⚡ Caching +- [Redis](./Caching/redis) -### Bots & Automation Tools -- [TelegramBot](https://github.com/RadinPirouz/linux-documents/tree/main/Bots%20%26%20Automation%20Tools/TelegramBot) +### 💻 Code Management +- [Git](./Code%20Management/Git) -### System Management -- [Kernel](https://github.com/RadinPirouz/linux-documents/tree/main/System%20Management/Kernel) +### 🔀 High Availability +- [Ha-Proxy](./High%20Availability/Ha-Proxy) -### Miscellaneous -- [Info](https://github.com/RadinPirouz/linux-documents/tree/main/Miscellaneous/Info) +### 📊 Monitoring & Logging +- [Grafana](./Monitoring%20&%20Logging/Grafana) +- [Librenms](./Monitoring%20&%20Logging/Librenms) +- [Netdata](./Monitoring%20&%20Logging/Netdata) +- [Zabbix](./Monitoring%20&%20Logging/Zabbix) -## Getting Started +### 🔐 Networking & Security +- [iptables](./Security%20&%20Networking/Iptables) +- [Nmap](./Security%20&%20Networking/Nmap) +- [Nginx](./Security%20&%20Networking/Nginx) +- [FileSharing](./Security%20&%20Networking/FileSharing) -To get started, navigate to the corresponding directory and follow the instructions provided in the README or script files. Each directory contains configuration files, setup guides, and examples to help you implement and manage the specific service or tool. +### 📦 Storage +- [NFS](./Storage/NFS) -## Contributing +### 🧠 System & Kernel Management +- [Kernel](./System%20&%20Kernel%20Management/Kernel) -We welcome contributions! If you have improvements, bug fixes, or additional configurations to share, please fork the repository and submit a pull request. Follow the existing structure and provide clear documentation for any new additions. +### 🌐 Web Development & Frameworks +- [Django](./Web%20Development%20&%20Frameworks/Django) +- [Laravel API Setup](./Web%20Development%20&%20Frameworks/LaravelAPI) +- [Laravel on Nginx](./Web%20Development%20&%20Frameworks/LaravelOnNginx) -## Contact +### 🔁 Web Servers & Reverse Proxies +- [Nginx](./Web%20Servers%20&%20Reverse%20Proxies/Nginx) -For questions, suggestions, or issues, please open an issue on GitHub or contact the repository owner. +### 🤖 Bots & Automation Tools +- [TelegramBot](./Bots%20&%20Automation%20Tools/TelegramBot) -Happy managing! +### 📝 Miscellaneous +- [Info](./Info) -[GitHub Repository Link](https://github.com/RadinPirouz/linux-documents) +--- +## 🚀 Getting Started + +```bash +git clone https://github.com/RadinPirouz/linux-documents.git +cd linux-documents +``` + +- Explore each folder for setup guides, scripts, and configuration examples. +- Follow individual READMEs or documentation inside each directory before running any scripts. + +--- + +## 📌 Notes +- Tested on **Debian/Ubuntu** and **CentOS/RHEL**-based distributions. +- Always review and test configurations in a staging environment before applying to production. + +--- + +## 🤝 Contributing + +Contributions are welcome! 🛠️ +1. Fork the repository. +2. Create a new branch (`git checkout -b feature/YourFeature`). +3. Commit your changes (`git commit -m "Add new config for X"`). +4. Push to the branch (`git push origin feature/YourFeature`). +5. Open a Pull Request. 🙌 + +Please ensure your code is tested and documented. +--- + +## 📬 Contact + +Questions or feedback? 📫 +- Telegram: [@RadinPirouz](https://t.me/RadinPirouz) +- GitHub Issues: Open an issue in this repo + +⭐ If you find this repository useful, don’t forget to give it a star! From d761d87e16c2a44689d98b19181d10be606f9f6a Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Wed, 28 May 2025 20:18:02 +0330 Subject: [PATCH 009/116] added lpic --- Linux/LPIC1/directorys.md | 59 +++++++++++++++++++++++++++++++++++++++ Linux/LPIC1/runlevels.md | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 Linux/LPIC1/directorys.md create mode 100644 Linux/LPIC1/runlevels.md diff --git a/Linux/LPIC1/directorys.md b/Linux/LPIC1/directorys.md new file mode 100644 index 0000000..d28cf19 --- /dev/null +++ b/Linux/LPIC1/directorys.md @@ -0,0 +1,59 @@ +# 📁 Linux Directory Structure & Basic Commands + +This document provides an overview of important Linux directories, their types, and essential file management commands. + +--- + +## 📂 Directory Types + +| Type | Description | +| ----------- | ----------------------------------------------------------------------------------- | +| **Virtual** | Do not reside on disk; dynamically generated by the system (e.g., `/proc`, `/sys`). | +| **Normal** | Standard directories that store files and data on disk. | + +--- + +## 🗂️ Common Linux Directories + +| Directory | Type | Description | +| --------- | ------- | ----------------------------------------------------------- | +| `/etc` | Normal | System configuration files | +| `/opt` | Normal | Optional or third-party software packages | +| `/bin` | Normal | Essential binary executables for all users | +| `/sbin` | Normal | System binaries, typically for administrative tasks | +| `/lib` | Normal | Shared libraries and kernel modules | +| `/home` | Normal | User home directories | +| `/proc` | Virtual | Kernel and process information (virtual files) | +| `/srv` | Normal | Data for services provided by the system (e.g., web, FTP) | +| `/sys` | Virtual | Kernel devices and system information | +| `/usr` | Normal | Secondary hierarchy: programs, libraries, and documentation | +| `/var` | Normal | Variable data: logs, mail, print spool, temporary files | +| `/dev` | Virtual | Device files (e.g., disk, USB, terminals) | +| `/mnt` | Normal | Mount point for temporary filesystems | +| `/boot` | Normal | Boot loader files, kernel images | + +--- + +## 🛠️ Basic File & Directory Commands + +| Command | Description | +| ------- | ---------------------------------------- | +| `cd` | Change directory | +| `ls` | List directory contents | +| `rm` | Remove files or directories | +| `mkdir` | Create a new directory | +| `touch` | Create an empty file or update timestamp | +| `cp` | Copy files or directories | +| `mv` | Move or rename files or directories | + +### 📘 Examples + +```bash +cd /etc # Navigate to /etc directory +ls -l # List files in long format +rm file.txt # Delete file.txt +mkdir new_folder # Create a directory named 'new_folder' +touch file.txt # Create a new empty file +cp file1.txt file2.txt # Copy file1.txt to file2.txt +mv file.txt /home/user/ # Move file.txt to another directory +``` diff --git a/Linux/LPIC1/runlevels.md b/Linux/LPIC1/runlevels.md new file mode 100644 index 0000000..16eaa31 --- /dev/null +++ b/Linux/LPIC1/runlevels.md @@ -0,0 +1,59 @@ +# Linux Runlevels Guide + +This document outlines the standard runlevels for **Red Hat** and **Debian**-based systems. Runlevels are used by `init` systems to define different states or modes of operation for the system. + +--- + +## 📊 Runlevels Overview + +| Runlevel | Description | Red Hat | Debian | +| -------- | ------------------------------------ | ------------ | --------------- | +| 0 | Halt | ✅ Supported | ✅ Supported | +| 1 | Single User Mode | ✅ Supported | ✅ Supported | +| 2 | Multi-user (No Network) | ❌ (HaveNet) | ✅ Supported | +| 3 | Multi-user (Network, No GUI) | ✅ Supported | ✅ Supported | +| 4 | Custom/User Defined | ✅ Supported | ✅ Supported | +| 5 | Multi-user (GUI Mode) / Halt *(err)* | ❌ (GUI Mode) | ❌ (Halt/Error?) | +| 6 | Reboot | ✅ Supported | ✅ Supported | + +> 💡 **Note**: +> +> * On **Red Hat**, runlevel 5 typically starts the system with a graphical user interface (GUI). +> * On **Debian**, runlevel 5 is often unused or reserved for custom setups. +> * Runlevel behavior can be customized depending on system configuration. + +--- + +## 🔧 Commands + +### Check Current Runlevel + +```bash +runlevel +``` + +### Change Runlevel + +```bash +telinit +``` + +or + +```bash +init +``` + +> ⚠️ Changing runlevels may stop or restart services. Use with caution, especially on production systems. + +--- + +## 📚 Additional Tips + +* Modern Linux systems (especially systemd-based) may not rely on traditional runlevels. Instead, they use *targets*. Example: + + ```bash + systemctl get-default + systemctl isolate graphical.target + ``` + From 2ce50f4aa9bc9c5fb2fc1a462e05f657fa8a6ccf Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Wed, 28 May 2025 21:44:45 +0330 Subject: [PATCH 010/116] added apt doc --- Linux/LPIC1/1-runlevels.md | 84 +++++++++++++++++++ .../LPIC1/{directorys.md => 2-directorys.md} | 0 Linux/LPIC1/3-package-managers.md | 75 +++++++++++++++++ Linux/LPIC1/runlevels.md | 59 ------------- 4 files changed, 159 insertions(+), 59 deletions(-) create mode 100644 Linux/LPIC1/1-runlevels.md rename Linux/LPIC1/{directorys.md => 2-directorys.md} (100%) create mode 100644 Linux/LPIC1/3-package-managers.md delete mode 100644 Linux/LPIC1/runlevels.md diff --git a/Linux/LPIC1/1-runlevels.md b/Linux/LPIC1/1-runlevels.md new file mode 100644 index 0000000..876423d --- /dev/null +++ b/Linux/LPIC1/1-runlevels.md @@ -0,0 +1,84 @@ +# 🐧 Linux Runlevels Guide + +This guide provides a concise overview of traditional **runlevels** in Linux systems, particularly for **Red Hat** and **Debian**-based distributions. Runlevels define specific states of system operation, historically managed by the `init` system. + +--- + +## 🔄 System Boot Sequence + +```plaintext +BIOS → Bootloader → Kernel → init +``` + +* **BIOS**: Performs hardware checks via **POST** (Power-On Self Test). +* **Bootloader**: Loads the kernel. +* **Kernel**: Initializes system and mounts the root filesystem. +* **init**: Launches system processes based on the selected runlevel. + +--- + +## 📊 Runlevels Comparison + +| Runlevel | Description | Red Hat | Debian | +| -------- | ----------------------------------- | ---------------- | --------------- | +| 0 | Halt / Shutdown | ✅ Supported | ✅ Supported | +| 1 | Single-User Mode | ✅ Supported | ✅ Supported | +| 2 | Multi-User (No Network) | ❌ (Includes Net) | ✅ Supported | +| 3 | Multi-User (Network, No GUI) | ✅ Supported | ✅ Supported | +| 4 | User-Defined / Custom | ✅ Supported | ✅ Supported | +| 5 | GUI Mode / *(Halt on some systems)* | ✅ GUI Mode | ⚠️ Custom/Halt? | +| 6 | Reboot | ✅ Supported | ✅ Supported | + +> 💡 **Notes**: +> • **Runlevel 5** on Red Hat typically launches a full graphical environment (GUI). +> • On Debian, runlevels 2–5 are often configured identically and can be customized. +> • Runlevel behavior is configurable via `/etc/inittab` (SysVinit systems). + +--- + +## 🔧 Useful Commands + +### ✅ Check Current Runlevel + +```bash +runlevel +``` + +### 🔁 Change Runlevel + +```bash +telinit +``` + +or + +```bash +init +``` + +> ⚠️ **Caution**: Switching runlevels may stop services or terminate user sessions. Use carefully on production systems. + +--- + +## 🚀 Modern Systems: systemd Targets + +Most modern Linux distributions use **systemd**, which replaces runlevels with **targets**. + +| Runlevel | systemd Target | +| -------- | ------------------- | +| 0 | `poweroff.target` | +| 1 | `rescue.target` | +| 3 | `multi-user.target` | +| 5 | `graphical.target` | +| 6 | `reboot.target` | + +### 📌 Common systemd Commands + +```bash +# Show default target +systemctl get-default + +# Change to graphical mode +systemctl isolate graphical.target +``` + diff --git a/Linux/LPIC1/directorys.md b/Linux/LPIC1/2-directorys.md similarity index 100% rename from Linux/LPIC1/directorys.md rename to Linux/LPIC1/2-directorys.md diff --git a/Linux/LPIC1/3-package-managers.md b/Linux/LPIC1/3-package-managers.md new file mode 100644 index 0000000..88b7c2d --- /dev/null +++ b/Linux/LPIC1/3-package-managers.md @@ -0,0 +1,75 @@ +# 📦 Linux Libraries & Package Management + +This guide provides a quick overview of **library types**, **package sources**, and **Debian-based package management** commands using `apt`. + +--- + +## 📚 Library Types + +Linux supports two main types of libraries: + +1. **Static Libraries (`.a`)** + - Linked at **compile-time** + - Included in the final binary + - Larger file size, faster execution + +2. **Shared Libraries (`.so`)** + - Linked at **run-time** + - Saved separately from the binary + - Saves space and allows updates without recompiling + +--- + +## 📦 Package Sources + +### ✅ Official Packages +Provided and maintained by the distribution (e.g., Debian, Ubuntu, Red Hat). + +### 🌐 Third-Party Packages +Created by external developers or organizations. Use with caution and verify trustworthiness. + +--- + +## 🏬 Linux Package Managers + +### 📦 Debian-based Systems +- **Package Manager**: `apt` +- **Low-level Tool**: `dpkg` +- **Package Format**: `.deb` + +### 📦 Red Hat-based Systems +- **Package Manager**: `yum` or `dnf` (newer) +- **Low-level Tool**: `rpm` +- **Package Format**: `.rpm` + +--- + +## 🌍 Package Mirrors + +Mirrors are alternative download sources for package repositories, often closer geographically for faster updates. + +To sync with package mirrors and get the latest updates: + +```bash +sudo apt update +``` + +--- + +## 🔧 Common `apt` Commands + +| Command | Description | +|--------------------------|---------------------------------------| +| `apt update` | Refresh package lists | +| `apt upgrade` | Upgrade all installed packages | +| `apt list` | List packages | +| `apt show ` | Show details of a package | +| `apt install ` | Install a new package | +| `apt reinstall `| Reinstall an existing package | +| `apt remove ` | Remove a package (keep config files) | +| `apt purge ` | Remove package **and** config files | +| `apt-cache search `| Search for a package | +| `apt autoremove` | Remove unused dependencies | + +> 🔐 Use `sudo` before these commands when required. + diff --git a/Linux/LPIC1/runlevels.md b/Linux/LPIC1/runlevels.md deleted file mode 100644 index 16eaa31..0000000 --- a/Linux/LPIC1/runlevels.md +++ /dev/null @@ -1,59 +0,0 @@ -# Linux Runlevels Guide - -This document outlines the standard runlevels for **Red Hat** and **Debian**-based systems. Runlevels are used by `init` systems to define different states or modes of operation for the system. - ---- - -## 📊 Runlevels Overview - -| Runlevel | Description | Red Hat | Debian | -| -------- | ------------------------------------ | ------------ | --------------- | -| 0 | Halt | ✅ Supported | ✅ Supported | -| 1 | Single User Mode | ✅ Supported | ✅ Supported | -| 2 | Multi-user (No Network) | ❌ (HaveNet) | ✅ Supported | -| 3 | Multi-user (Network, No GUI) | ✅ Supported | ✅ Supported | -| 4 | Custom/User Defined | ✅ Supported | ✅ Supported | -| 5 | Multi-user (GUI Mode) / Halt *(err)* | ❌ (GUI Mode) | ❌ (Halt/Error?) | -| 6 | Reboot | ✅ Supported | ✅ Supported | - -> 💡 **Note**: -> -> * On **Red Hat**, runlevel 5 typically starts the system with a graphical user interface (GUI). -> * On **Debian**, runlevel 5 is often unused or reserved for custom setups. -> * Runlevel behavior can be customized depending on system configuration. - ---- - -## 🔧 Commands - -### Check Current Runlevel - -```bash -runlevel -``` - -### Change Runlevel - -```bash -telinit -``` - -or - -```bash -init -``` - -> ⚠️ Changing runlevels may stop or restart services. Use with caution, especially on production systems. - ---- - -## 📚 Additional Tips - -* Modern Linux systems (especially systemd-based) may not rely on traditional runlevels. Instead, they use *targets*. Example: - - ```bash - systemctl get-default - systemctl isolate graphical.target - ``` - From a7509c6285a99de4ed2671633bb0edbdac41944f Mon Sep 17 00:00:00 2001 From: radinpirouz Date: Tue, 3 Jun 2025 14:30:55 +0330 Subject: [PATCH 011/116] dpkg doc --- Code Management/Git/Gitlab/Gitlab-CI/1.md | 0 .../Git/Gitlab/Gitlab-CI/gitlab-ci.yaml | 25 +++++ Linux/LPIC1/4-dpkg.md | 94 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 Code Management/Git/Gitlab/Gitlab-CI/1.md create mode 100644 Code Management/Git/Gitlab/Gitlab-CI/gitlab-ci.yaml create mode 100644 Linux/LPIC1/4-dpkg.md diff --git a/Code Management/Git/Gitlab/Gitlab-CI/1.md b/Code Management/Git/Gitlab/Gitlab-CI/1.md new file mode 100644 index 0000000..e69de29 diff --git a/Code Management/Git/Gitlab/Gitlab-CI/gitlab-ci.yaml b/Code Management/Git/Gitlab/Gitlab-CI/gitlab-ci.yaml new file mode 100644 index 0000000..8ae436c --- /dev/null +++ b/Code Management/Git/Gitlab/Gitlab-CI/gitlab-ci.yaml @@ -0,0 +1,25 @@ +job1: + stage: hello_stage + script: echo "Hi :)" + +job2: + stage: hello_stage + script: echo "Hello :)" + +job3: + stage: hello_stage + script: echo "How Are You :)" + needs: + - job2 + +Build_job1: + stage: build_stage + script: echo "Building Code" + needs: + - job3 + tags: + - build_runner + +stages: + - hello_stage + - build_stage \ No newline at end of file diff --git a/Linux/LPIC1/4-dpkg.md b/Linux/LPIC1/4-dpkg.md new file mode 100644 index 0000000..7537c59 --- /dev/null +++ b/Linux/LPIC1/4-dpkg.md @@ -0,0 +1,94 @@ + +# 📦 `dpkg` – Debian Package Manager + +`dpkg` is the package manager for Debian-based Linux distributions. It is used to install, remove, and manage `.deb` packages directly. + +### 📘 Basic Syntax + +```bash +dpkg [