Lorem ipsum...
7 |This is DevOps class.
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /8-k8s/FAQ/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # PodDisruptionBudget (PDB) in Kubernetes 4 | 5 | A `PodDisruptionBudget` (PDB) in Kubernetes is a policy that sets limits on the number of Pods of a replicated application that can be simultaneously down among a set of Pods. It helps ensure that a specified minimum number of Pods are always available during voluntary disruptions, such as when performing cluster maintenance (e.g., node upgrades, resizes). 6 | 7 | ## Key Concepts 8 | 9 | - **MinAvailable**: Specifies the minimum number of Pods that should remain available during the disruption. 10 | - **MaxUnavailable**: Defines the maximum number of Pods that can be unavailable during the disruption. 11 | 12 | ## Usage 13 | 14 | PDBs are particularly useful in production environments to maintain application availability during operations that require Pod eviction, like node maintenance. 15 | 16 | ## Example 17 | 18 | A simple PDB might look like this: 19 | 20 | ```yaml 21 | apiVersion: policy/v1 22 | kind: PodDisruptionBudget 23 | metadata: 24 | name: myapp-pdb 25 | spec: 26 | minAvailable: 2 27 | selector: 28 | matchLabels: 29 | app: myapp 30 | ``` 31 | 32 | --- 33 | 34 | # Finding Configuration Files in Kubernetes 35 | 36 | Kubernetes configuration files are YAML or JSON files that define how resources should be created and managed within the Kubernetes cluster. These files can specify configurations for pods, services, volumes, and more. Here's how you can find and manage these configuration files. 37 | 38 | ## Locations of Configuration Files 39 | 40 | ### System-Wide Configuration 41 | 42 | - **Kubernetes Master Node**: 43 | - `/etc/kubernetes/manifests`: Contains static pod manifests for the Kubernetes control plane components (apiserver, controller-manager, scheduler, etc.). 44 | - `/etc/kubernetes/admin.conf`, `/etc/kubernetes/kubelet.conf`, and `/etc/kubernetes/controller-manager.conf`: Configuration files for accessing the Kubernetes API. 45 | 46 | - **Kubelet**: 47 | - `/var/lib/kubelet/config.yaml`: The primary configuration file for the kubelet. 48 | 49 | - **Kubeadm**: 50 | - `/etc/kubernetes/kubeadm-config.yaml`: The configuration file used by `kubeadm init` and `kubeadm join`. 51 | 52 | ### User-Defined Resource Configurations 53 | 54 | - **Application Specific**: Typically, the configuration files for your applications (pods, deployments, services, etc.) are not stored on the cluster nodes. Instead, they are managed by users and stored wherever is convenient for version control, such as in a Git repository. 55 | 56 | --- 57 | 58 | # Kubernetes Storage and Stateful Workloads Explained 59 | 60 | Understanding Persistent Volumes (PV), Persistent Volume Claims (PVC), and StatefulSets is crucial for managing stateful applications in Kubernetes. Here's a surface-level overview of these concepts without diving into specific commands. 61 | 62 | ## Persistent Volumes (PV) 63 | 64 | **Persistent Volumes** are a way for users to manage durable storage in Kubernetes. PVs are resources in the cluster that provision storage, such as disks, that persist beyond the lifecycle of individual pods. Administrators typically create PVs to represent available storage in the cluster. 65 | 66 | ### Key Points: 67 | 68 | - **Cluster Resource**: PVs are a cluster-level resource, meaning they are not tied to a specific namespace. 69 | - **Storage Abstraction**: Provides an abstraction over underlying storage systems, supporting various storage backends like NFS, iSCSI, cloud storage services, and more. 70 | - **Lifecycle Independent**: PVs exist independently of pods, ensuring data persists even when pods are deleted or moved. 71 | 72 | ## Persistent Volume Claims (PVC) 73 | 74 | **Persistent Volume Claims** are requests for storage by users. PVCs specify size, access modes (e.g., read/write), and sometimes specific storage class requirements. Kubernetes matches a PVC to an available PV and binds them together. 75 | 76 | ### Key Points: 77 | 78 | - **User Request**: PVCs allow users to request specific sizes and types of storage. 79 | - **Dynamic Provisioning**: If no suitable PV exists, a new one can be dynamically provisioned according to the requested storage class. 80 | - **Binding**: A PVC is bound to a single PV, creating a one-to-one relationship that reserves the PV for the PVC's use. 81 | 82 | ## StatefulSets 83 | 84 | **StatefulSets** are used to manage stateful applications, providing stable, unique network identifiers, stable persistent storage, and ordered, graceful deployment and scaling. 85 | 86 | ### Key Points: 87 | 88 | - **Stable Identity**: Each pod in a StatefulSet has a unique ordinal index and stable network identity. 89 | - **Ordered Operations**: Pods are created, scaled, and deleted in a predictable order, important for stateful applications like databases that require careful management of replicas. 90 | - **Persistent Storage**: StatefulSets can use PVCs to provide each pod with its persistent storage, ensuring data persists across pod rescheduling and restarts. 91 | 92 | ### Conclusion 93 | 94 | While PVs and PVCs provide the mechanisms for handling persistent storage in Kubernetes, StatefulSets allow for the management of stateful applications, leveraging PVs and PVCs to ensure data persistence. Together, these components enable the deployment and management of complex, stateful applications within a Kubernetes cluster. 95 | 96 | ## Script Explanation 97 | 98 | This guide explains the components of the script that creates Kubernetes resources, including Persistent Volumes (PVs), Persistent Volume Claims (PVCs), and a StatefulSet. 99 | 100 | ## Components 101 | 102 | ### Persistent Volume (PV) 103 | 104 | - **What it Does**: Creates a PV named `example-pv` with a capacity of 1Gi and a storage class of `standard`. 105 | - **Storage Method**: Utilizes `hostPath` for storage, which mounts a directory from the host. This approach is primarily for testing purposes on a single-node cluster. 106 | 107 | ### Persistent Volume Claim (PVC) 108 | 109 | - **What it Does**: Generates a PVC named `example-pvc` that requests 1Gi of storage with the same storage class, `standard`. 110 | - **Binding**: This PVC is designed to bind to the previously created PV, `example-pv`. 111 | 112 | ### StatefulSet 113 | 114 | - **What it Does**: Constructs a StatefulSet named `example-statefulset` with 2 replicas. 115 | - **Configuration**: Each pod within the StatefulSet mounts the PVC created by the `volumeClaimTemplates`. 116 | - **Use Case**: Provides a simple example that employs an Nginx container to deliver content stored on the persistent volume. 117 | 118 | ## How to Run 119 | 120 | 1. **Save the Script**: Store the script in a file, for instance, `create-pv-pvc-statefulset.sh`. 121 | 2. **Make Executable**: 122 | 123 | ``` 124 | 125 | chmod +x create-pv-pvc-statefulset.sh 126 | create-pv-pvc-statefulset.sh 127 | 128 | ``` 129 | --- 130 | 131 | # Using Vault in Jenkins 132 | 133 | HashiCorp Vault is a tool for secrets management, allowing you to securely store and access sensitive data like passwords, tokens, and keys. Integrating Vault with Jenkins can significantly enhance the security of your CI/CD pipelines by providing a secure way to handle credentials and other sensitive information. 134 | 135 | ## Benefits of Integrating Vault with Jenkins 136 | 137 | - **Security**: Keeps sensitive data out of your build logs and source code. 138 | - **Centralization**: Manages all your secrets in one place, making them easier to rotate, revoke, and keep track of. 139 | - **Auditing**: Vault offers detailed audit logs, allowing you to track access to secrets, which is invaluable for compliance and security. 140 | 141 | ## How to Use Vault with Jenkins 142 | 143 | ### Step 1: Install Vault Plugin in Jenkins 144 | 145 | First, you need to install the [HashiCorp Vault Plugin](https://plugins.jenkins.io/hashicorp-vault-plugin/) for Jenkins. This can be done through the "Manage Jenkins" > "Manage Plugins" menu in the Jenkins UI. 146 | 147 | ### Step 2: Configure Vault in Jenkins 148 | 149 | After installing the plugin, configure Jenkins to communicate with your Vault server: 150 | 151 | 1. Go to "Manage Jenkins" > "Configure System". 152 | 2. Find the Vault section and add a new Vault configuration. 153 | 3. Enter your Vault Server URL and the Vault Credential. 154 | 155 | ### Step 3: Set Up Vault Credentials 156 | 157 | Vault credentials in Jenkins can be set up as follows: 158 | 159 | 1. Navigate to "Credentials" in Jenkins. 160 | 2. Choose the appropriate scope and click "Add Credentials". 161 | 3. Select "Vault Token" or the appropriate credential type. 162 | 4. Enter your Vault Token and other details as necessary. 163 | 164 | ### Step 4: Accessing Secrets in Jenkins Jobs 165 | 166 | To access Vault secrets in your Jenkins jobs: 167 | 168 | 1. In your job configuration, add a "Build Environment" step. 169 | 2. Select "Vault Secrets" and configure the Vault Key/Values you wish to inject into the build environment. 170 | 3. Use the injected environment variables in your build steps. 171 | 172 | ## Best Practices 173 | 174 | - **Least Privilege**: Grant Jenkins access only to the secrets it needs, nothing more. 175 | - **Audit**: Regularly review access logs and rotate secrets. 176 | - **Secure Communication**: Ensure communication between Jenkins and Vault is over HTTPS to prevent eavesdropping. 177 | 178 | ## Conclusion 179 | 180 | Integrating Vault with Jenkins allows you to manage and inject secrets into your CI/CD pipelines securely. By centralizing secret management, you not only improve the security posture of your development environment but also make managing and rotating secrets much more manageable. 181 | 182 | -------------------------------------------------------------------------------- /8-k8s/FAQ/vol-k8s.ymal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Create a Persistent Volume 4 | cat <This is a paragraph in Dev Branch.
18 | 19 |we are learning about git Merge
20 | 21 | 22 | 23 | 24 | 25 | 26 | hi 27 | -------------------------------------------------------------------------------- /vs-code-installation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt update -y 3 | sudo apt install software-properties-common apt-transport-https wget -y 4 | wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - 5 | sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" 6 | sudo apt install code -y 7 | --------------------------------------------------------------------------------