├── .dockerignore ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug.yaml │ ├── config.yml │ ├── doc_issue.yaml │ ├── feature.yaml │ └── other.yaml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── publish-dockerhub.yml │ ├── publish-ghcr.yml │ └── releases.yml ├── .gitignore ├── .gitpod.yml ├── .nojekyll ├── ArgoCD ├── README.md └── YAML │ └── declarative.yml ├── Bash-Scripting ├── README.md └── Scripts │ ├── concepts │ ├── 1 echo.sh │ ├── 10 case.sh │ ├── 11 while.sh │ ├── 12 until.sh │ ├── 13 for.sh │ ├── 14 break-continue.sh │ ├── 15 function.sh │ ├── 2 read.sh │ ├── 3 variables.sh │ ├── 4 arguments.sh │ ├── 5 arguments2.sh │ ├── 6 athemetic.sh │ ├── 7 conditionals.sh │ ├── 8 conditionals1.sh │ └── 9 conditionals2.sh │ ├── crypto-price.sh │ ├── ip-alive-check.sh │ ├── ping.sh │ └── random-quote.sh ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DevSecOps └── README.md ├── Docker ├── Dockerfile │ └── Dockerfile.drupal ├── Prod-app-demo │ ├── .gitignore │ ├── Dockerfile │ ├── docker-compose.override.yml │ ├── docker-compose.prod.yml │ ├── docker-compose.test.yml │ ├── docker-compose.yml │ ├── psql-fake-password.txt │ └── themes │ │ └── themes-go-here ├── README.md ├── YAML │ ├── compose-template.yml │ ├── drupal-compose.yml │ ├── drupal-stack.yaml │ ├── sample1.yml │ ├── sample2.yml │ ├── secret-stack-1.yaml │ └── secret-stack.yml └── commands │ └── README.md ├── Dockerfile ├── Git ├── README.md └── commands │ └── README.md ├── GitHub-Actions ├── README.md └── Workflows │ ├── docker-image-dockerhub.yaml │ └── docker-image-ghcr.yaml ├── GitOps └── README.md ├── Helm └── README.md ├── Jenkins ├── Docker-setup │ ├── Dockerfile │ ├── README.md │ ├── dind.sh │ └── jenkins.sh ├── Jenkinsfile │ ├── Jenkinsfile │ ├── Jenkinsfile-multistage │ ├── Jenkinsfile-para │ └── script.groovy └── README.md ├── Kubernetes ├── README.md ├── YAML │ ├── Complete-app-setup │ │ ├── Drupal-postgres │ │ │ ├── drupal-deployment.yaml │ │ │ ├── drupal-ingress.yaml │ │ │ ├── drupal-service.yaml │ │ │ ├── psql-deployment.yaml │ │ │ ├── psql-secrets.yaml │ │ │ ├── psql-service.yaml │ │ │ ├── psql-volume.yaml │ │ │ └── psql-volumeclaim.yaml │ │ ├── Mongo │ │ │ ├── mongo-configmap.yaml │ │ │ ├── mongo-deployment.yaml │ │ │ ├── mongo-exp-deployment.yaml │ │ │ ├── mongo-secrets.yaml │ │ │ └── mongo-service.yaml │ │ └── Nginx │ │ │ ├── deployment.yaml │ │ │ ├── ingress.yaml │ │ │ └── service.yaml │ ├── Ingress │ │ ├── multiple-path.yaml │ │ └── tls-ingress.yaml │ ├── Multi-container-manifest │ │ ├── alpine.yaml │ │ └── curlimage.yaml │ ├── Recreate-strategy │ │ └── deployment.yaml │ ├── Rolling-update-strategy │ │ └── deployment.yaml │ ├── Secret + Config as volume │ │ ├── config.yaml │ │ ├── mosquitto.yaml │ │ └── secret.yaml │ ├── Volume │ │ ├── Nginx-app │ │ │ ├── nginx-volume.yaml │ │ │ ├── nginx-volumeclaim.yaml │ │ │ └── nginx.yaml │ │ └── nginx-local.yaml │ └── canray │ │ ├── deploy1.yaml │ │ ├── deploy2.yaml │ │ └── service.yaml └── commands │ └── README.md ├── Kubescape └── README.md ├── LICENSE ├── Lens └── README.md ├── Linux ├── README.md └── commands │ └── README.md ├── Networking ├── README.md └── commands │ └── README.md ├── Portainer └── README.md ├── Prometheus └── README.md ├── README.md ├── Validkube └── README.md ├── YAML ├── README.md └── syntax │ └── README.md ├── docker-compose.dev.yaml ├── docker-compose.yaml ├── favicon.png ├── index.html └── releases.json /.dockerignore: -------------------------------------------------------------------------------- 1 | .git* 2 | *.md 3 | !README.md 4 | .nojekyll 5 | .dockerignore 6 | LICENSE 7 | Dockerfile 8 | releases.json 9 | docker-compose.yml -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [Pradumnasaraf] 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.yaml: -------------------------------------------------------------------------------- 1 | name: 🐛 Bug 2 | description: Report an issue to help improve the project. 3 | title: '[BUG] ' 4 | labels: ['bug'] 5 | body: 6 | - type: textarea 7 | id: description 8 | attributes: 9 | label: Description 10 | description: A brief description of the question or issue, also include what you tried and what didn't work 11 | validations: 12 | required: true 13 | - type: textarea 14 | id: screenshots 15 | attributes: 16 | label: Screenshots 17 | description: Please add screenshots if applicable 18 | validations: 19 | required: false 20 | - type: textarea 21 | id: extra_information 22 | attributes: 23 | label: Additional information 24 | description: Is there anything else we should know about this bug report? 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/doc_issue.yaml: -------------------------------------------------------------------------------- 1 | name: 📄 Documentation 2 | description: Found an issue in the documentation? You can use this one! 3 | title: '[DOCS] ' 4 | labels: ['documentation'] 5 | body: 6 | - type: textarea 7 | id: description 8 | attributes: 9 | label: Description 10 | description: Description of the question or issue, also include what you tried and what didn't work 11 | validations: 12 | required: true 13 | - type: textarea 14 | id: screenshots 15 | attributes: 16 | label: Screenshots 17 | description: Screenshots if applicable 18 | validations: 19 | required: false 20 | - type: textarea 21 | id: extra_information 22 | attributes: 23 | label: Additional information 24 | description: Is there anything else we should know about this report? 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yaml: -------------------------------------------------------------------------------- 1 | name: 💡 General Feature Request 2 | description: Have a new idea/feature for my portfolio? Please suggest! 3 | title: '[FEATURE] ' 4 | labels: ['feature'] 5 | body: 6 | - type: textarea 7 | id: description 8 | attributes: 9 | label: Description 10 | description: Description of the enhancement you propose, also include what you tried and what worked. 11 | validations: 12 | required: true 13 | - type: textarea 14 | id: screenshots 15 | attributes: 16 | label: Screenshots 17 | description: Screenshots if applicable 18 | validations: 19 | required: false 20 | - type: textarea 21 | id: extra_information 22 | attributes: 23 | label: Additional information 24 | description: Is there anything else we should know about this feature request? 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other.yaml: -------------------------------------------------------------------------------- 1 | name: ❗ Other 2 | description: Use this for any other issues. Please do NOT create blank issues 3 | title: '[OTHER] ' 4 | labels: ['other'] 5 | body: 6 | - type: textarea 7 | id: issuedescription 8 | attributes: 9 | label: What would you like to share? 10 | description: Provide a clear and concise explanation of your issue. 11 | validations: 12 | required: true 13 | - type: textarea 14 | id: extra_information 15 | attributes: 16 | label: Additional information 17 | description: Is there anything else we should know about this report? 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## 🛠️ Fixes Issue 4 | 5 | 6 | 7 | 8 | 9 | ## 👨‍💻 Changes proposed 10 | 11 | 12 | 13 | ## ✔️ Check List (Check all the applicable boxes) 14 | 15 | 16 | 20 | 21 | - [ ] My code follows the code style of this project. 22 | - [ ] This PR does not contain plagiarized content. 23 | - [ ] The title of my pull request is a short description of the requested changes. 24 | 25 | ## 📄 Note to reviewers 26 | 27 | 28 | 29 | ## 📷 Screenshots -------------------------------------------------------------------------------- /.github/workflows/publish-dockerhub.yml: -------------------------------------------------------------------------------- 1 | name: Build and Publish Docker Image to DockerHub 2 | 3 | on: 4 | push: 5 | branches: ["main"] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - name: DockerHub Login 15 | uses: docker/login-action@v2.1.0 16 | with: 17 | username: ${{ secrets.DOCKERHUB_USERNAME }} 18 | password: ${{ secrets.DOCKERHUB_PASSWORD }} 19 | 20 | - name: Build the Docker image 21 | run: docker build . --file Dockerfile --tag ${{ secrets.DOCKERHUB_USERNAME }}/devops 22 | 23 | - name: Docker Push 24 | run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/devops 25 | -------------------------------------------------------------------------------- /.github/workflows/publish-ghcr.yml: -------------------------------------------------------------------------------- 1 | name: Create and publish a Docker image to GitHub Container Registry 2 | 3 | on: 4 | push: 5 | branches: ['main'] 6 | 7 | env: 8 | REGISTRY: ghcr.io 9 | IMAGE_NAME: ${{ github.repository }} 10 | 11 | jobs: 12 | build-and-push-image: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | contents: read 16 | packages: write 17 | 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v3 21 | 22 | - name: Log in to the Container registry 23 | uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 24 | with: 25 | registry: ${{ env.REGISTRY }} 26 | username: ${{ github.actor }} 27 | password: ${{ secrets.GITHUB_TOKEN }} 28 | 29 | - name: Extract metadata (tags, labels) for Docker 30 | id: meta 31 | uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 32 | with: 33 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 34 | 35 | - name: Build and push Docker image 36 | uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc 37 | with: 38 | context: . 39 | push: true 40 | tags: ghcr.io/pradumnasaraf/devops:latest 41 | labels: ${{ steps.meta.outputs.labels }} 42 | -------------------------------------------------------------------------------- /.github/workflows/releases.yml: -------------------------------------------------------------------------------- 1 | name: Releases 2 | on: 3 | push: 4 | branches: 5 | - main 6 | 7 | jobs: 8 | changelog: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - name: conventional Changelog Action 15 | id: changelog 16 | uses: TriPSs/conventional-changelog-action@v3.7.1 17 | with: 18 | github-token: ${{ secrets.PA_TOKEN }} 19 | version-file: './releases.json' 20 | 21 | - name: create release 22 | uses: actions/create-release@v1 23 | if: ${{ steps.changelog.outputs.skipped == 'false' }} 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.PA_TOKEN }} 26 | with: 27 | tag_name: ${{ steps.changelog.outputs.tag }} 28 | release_name: ${{ steps.changelog.outputs.tag }} 29 | body: ${{ steps.changelog.outputs.clean_changelog }} 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | tasks: 2 | - name: Start web server 3 | init: python -m http.server 8000 4 | ports: 5 | - port: 8000 6 | onOpen: open-browser 7 | 8 | github: 9 | prebuilds: 10 | master: true 11 | addBadge: true 12 | addCheck: true 13 | branches: true 14 | addComment: false 15 | pullRequests: true 16 | pullRequestsFromForks: true 17 | -------------------------------------------------------------------------------- /.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ayush7614/DevOps/34db69d7f13e2302d6b16f348232630219504a4c/.nojekyll -------------------------------------------------------------------------------- /ArgoCD/README.md: -------------------------------------------------------------------------------- 1 | ## ArgoCD 2 | 3 | - [ArgoCD](https://argoproj.github.io/cd) 4 | - [ArgoCD GitHub Repo](https://github.com/argoproj/argo-cd) 5 | 6 | ### Learning Resources 7 | 8 | - [GitOps Tech world with naina (Video)](https://youtu.be/MeU5_k9ssrs) 9 | - [GitOps Fundamentals (Course)](https://learning.codefresh.io/) 10 | 11 | > _"One the founding principles of GitOps - everything stored in Git."_ 12 | 13 | Argo CD is a popular GitOps controller. It is used to deploy applications to Kubernetes clusters. It is also used to manage the configuration of the cluster itself. It can be changed too. 14 | 15 | - For production we can use the [Autopilot](https://github.com/argoproj-labs/argocd-autopilot). For a tradational approach we can use the [Manifest directory](https://github.com/argoproj/argo-cd/tree/master/manifests) approach. Community [Helm](https://github.com/argoproj/argo-helm/tree/master/charts/argo-cd) charts are also available 16 | 17 |

Screenshot 2022-11-29 at 11 44 57 PM

18 | 19 | ### Installation 20 | 21 | - By applying the manifests . Refrence: [ArgoCD Installation](https://argoproj.github.io/argo-cd/getting_started/#1-install-argo-cd) 22 | 23 | ```bash 24 | kubectl create namespace argocd 25 | kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml 26 | ``` 27 | 28 | Default credentials: 29 | 30 | - Username: admin 31 | - Password : It can be found by running the following command 32 | 33 | ```bash 34 | kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d 35 | ``` 36 | 37 | ## Sync Policy - Features 38 | 39 |

Screenshot 2022-11-30 at 4 56 41 PM

40 | 41 | - **Auto Sync** - ArgoCD will automatically sync the application with the Git repository. This is done by polling the Git repository at a specified interval. 42 | 43 | - **Self Healing** - If the chnages are done directly to deployment/cluster, it will discard those chnages and keep the state as per the Git repository. For example, if someone chnange the replica count to two from 1 from the CLI, it will be changed back to 1. 44 | 45 | - **Auto Pruning** - ArgoCD will automatically delete the resources that are not present in the Git repository. By default, it will not. 46 | 47 | ## Progressive Delivery 48 | 49 | Progressive Delivery is the practice of deploying an application in a gradual manner allowing for minimum downtime and easy rollbacks. There are several forms of progressive delivery such as blue/green, canary, a/b and feature flags. 50 | 51 | - **Blue/Green** - Deploy the new version of the application to a new environment and then switch the traffic to the new environment. This is the most common form of progressive delivery. It is also the most complex to implement. It requires a lot of infrastructure and a lot of testing. 52 | 53 | - **Canary** - Deploy the new version of the application to a small subset of users. If the new version is working fine, then deploy it to the rest of the users. This is the most common form of progressive delivery. It is also the most complex to implement. It requires a lot of infrastructure and a lot of testing. 54 | 55 | - To make the whole setup declaritive way and make it infrastructure as we deploy ArgoCD Argo CD applications just like any other Kubernetes resource. This is also managed through a git repository. 56 | 57 | [Docs](https://argo-cd.readthedocs.io/en/stable/operator-manual/declarative-setup/) for reference. 58 | 59 | Samle YAML: 60 | 61 | ```YAML 62 | apiVersion: argoproj.io/v1alpha1 63 | kind: Application 64 | metadata: 65 | name: nginx-app # This is the name of the application 66 | namespace: argocd 67 | spec: 68 | destination: 69 | namespace: argocd # This is the namespace where the application will be deployed 70 | server: https://kubernetes.default.svc # This is the default server 71 | project: default 72 | source: 73 | path: ./manifest # This is the path where the manifest is present 74 | repoURL: https://github.com/sarafpradumna/argo-test # This is the repo where the manifest is present 75 | targetRevision: HEAD 76 | syncPolicy: 77 | automated: 78 | prune: true 79 | selfHeal: true 80 | allowEmpty: false #By default it is false 81 | syncOptions: 82 | - CreateNamespace=true # This will create namespace if not present 83 | ``` 84 | -------------------------------------------------------------------------------- /ArgoCD/YAML/declarative.yml: -------------------------------------------------------------------------------- 1 | apiVersion: argoproj.io/v1alpha1 2 | kind: Application 3 | metadata: 4 | name: nginx-app # This is the name of the application 5 | namespace: argocd 6 | spec: 7 | destination: 8 | namespace: argocd # This is the namespace where the application will be deployed 9 | server: https://kubernetes.default.svc # This is the default server 10 | project: default 11 | source: 12 | path: ./manifest # This is the path where the manifest is present 13 | repoURL: https://github.com/sarafpradumna/argo-test # This is the repo where the manifest is present 14 | targetRevision: HEAD 15 | syncPolicy: 16 | automated: 17 | prune: true 18 | selfHeal: true 19 | syncOptions: 20 | - CreateNamespace=true # This will create namespace if not present 21 | 22 | -------------------------------------------------------------------------------- /Bash-Scripting/README.md: -------------------------------------------------------------------------------- 1 | ## Bash Scripting 2 | 3 | - [Chmod Calculator](https://chmodcommand.com/) 4 | - [devhints](https://devhints.io/) 5 | - [jq](https://stedolan.github.io/jq/) 6 | 7 | ### Lerning Resources 8 | 9 | [You need to learn Bash Scripting right now playlist - NetworkChuck (Video)](https://youtube.com/playlist?list=PLIhvC56v63IKioClkSNDjW7iz-6TFvLwS) 10 | - [Devhints Bash Cheat Sheet](https://devhints.io/bash) 11 | 12 | 13 | 14 | We start by creating a file with the `.sh` extension. For example `script.sh`. Then we write the script in it. For example: 15 | 16 | Basic Script 17 | 18 | ```bash 19 | #!/bin/bash 20 | 21 | echo "Hello World" 22 | ``` 23 | 24 | We can run this by `bash script.sh` or `./script.sh`. But the second will only work if the script is executable (permission to execute). We can make it executable by `chmod +x script.sh`. Now we can run it by `./script.sh`. 25 | 26 | ### Shebang 27 | 28 | The first line of a bash script is called the shebang. It tells the system which interpreter to use to run the script. The shebang for bash is `#!/bin/bash`. The shebang for python is `#!/usr/bin/env python`. It vary from the langauge to language. 29 | 30 | ### Variables 31 | 32 | It is placeholder for a value. Just like any other programming language. We use $ to access the variable. Eg: `$NAME`. We can also use `${NAME}`. The braces are used to make sure that the variable is not mistaken for a command. 33 | 34 | ```bash 35 | #!/bin/bash 36 | 37 | # Variable Declaration 38 | NAME="John" 39 | 40 | # Variable Usage 41 | 42 | echo "My name is $NAME" 43 | echo "My name is ${NAME}" 44 | ``` 45 | 46 | NOTE: We can create variables by `NAME="John"` through CLI, we can't use in the script beacuse it is not exported. We can export it by `export NAME="John"`. Now we can use it in the script. 47 | 48 | But here is one more catch. If we exit the terminal and open a new one, the variable will be gone. To make it permanent, we can add it to the `.bashrc` file. It is a hidden file in the home directory. We can open it by `vi ~/.bashrc` or any other editor. We can add the variable to the file. Eg: `export NAME="John"`. 49 | 50 | ### User Input 51 | 52 | We can take input from the user using the `read` command. 53 | 54 | ```bash 55 | #!/bin/bash 56 | 57 | echo "Enter your name: " 58 | read NAME 59 | echo "Hello $NAME, nice to meet you!" 60 | ``` 61 | 62 | ### Arguments 63 | 64 | We can pass arguments to the script. The arguments are stored in the `$1`, `$2`, `$3` and so on. `$0` is the name of the script. 65 | 66 | Eg: `bash script.sh arg1 arg2` 67 | 68 | ```bash 69 | #!/bin/bash 70 | 71 | echo "First Argument: $1" 72 | ``` 73 | 74 | ### Arthemetic Operations 75 | 76 | We can do arthemetic operations in bash. We use the `(( ))` to do arthemetic operations. 77 | 78 | ```bash 79 | 80 | ```bash 81 | #!/bin/bash 82 | 83 | echo $(( 5 + 5 )) 84 | ``` 85 | 86 | #### Arthemetic Operators 87 | 88 | - `+` - Addition 89 | - `-` - Subtraction 90 | - `*` - Multiplication 91 | - `/` - Division 92 | - `%` - Modulus 93 | 94 | ### Conditional Statements 95 | 96 | We can use the `if` statement to check for a condition. The syntax is: 97 | 98 | ```bash 99 | #!/bin/bash 100 | 101 | if [ "$1" == "John" ] 102 | then 103 | echo "Hello John" 104 | exit 1 105 | elif [ "$1" == "Doe" ] 106 | then 107 | echo "Hello Doe" 108 | else 109 | echo "I don't know you" 110 | fi 111 | ``` 112 | 113 | ```bash 114 | if [$1 == "hello"],then echo "Hello World", fi 115 | ``` 116 | 117 | #### Comparison Operators 118 | 119 | - `==` - Equal to 120 | - `>` - Greater than 121 | - `<` - Less than 122 | - `>=` - Greater than or equal to 123 | - `<=` - Less than or equal to 124 | - `!=` - Not equal to 125 | - `-ge` - Greater than or equal to 126 | - `-le` - Less than or equal to 127 | 128 | #### Boolean Operators 129 | 130 | - `-a` - And 131 | - `-o` - Or 132 | - `!` - Not 133 | 134 | ### Loops 135 | 136 | We can use loops to repeat a set of commands. There are two types of loops in bash. `for` and `while`. The the body is enclosed in `do` and `done`. 137 | 138 | #### For Loop 139 | 140 | ```bash 141 | #!/bin/bash 142 | 143 | for i in 1 2 3 4 5 144 | do 145 | echo $i 146 | done 147 | ``` 148 | 149 | #### While Loop 150 | 151 | ```bash 152 | 153 | #!/bin/bash 154 | 155 | i=1 156 | while [ $i -le 5 ] 157 | do 158 | echo $i 159 | (( i++ )) 160 | done 161 | ``` 162 | 163 | #### Break and Continue 164 | 165 | We can use `break` and `continue` in loops. `break` will break the loop and `continue` will skip the current iteration. 166 | 167 | ```bash 168 | #!/bin/bash 169 | 170 | for i in 1 2 3 4 5 171 | do 172 | if [ $i -eq 3 ] 173 | then 174 | continue 175 | fi 176 | echo $i 177 | done 178 | ``` 179 | 180 | ### Functions 181 | 182 | We can create functions in bash. The syntax is: 183 | 184 | ```bash 185 | #!/bin/bash 186 | 187 | function sayHello() { 188 | echo "Hello World" 189 | } 190 | 191 | sayHello 192 | ``` 193 | 194 | 195 | - `exit 1` - Exit the script with an error (non-zero exit code). 196 | - $RANDOM gives a random number between 0 and 32767. 197 | - $SHELL gives the path of the shell. 198 | - $USER gives the username of the user. 199 | - $HOSTNAME gives the hostname of the machine. 200 | 201 | 202 | ### jq 203 | 204 | jq is a command-line JSON processor. It is used to parse JSON. It is used to extract data from JSON. It is used to transform JSON. It is used to generate JSON. 205 | 206 | #### Installation 207 | 208 | ```bash 209 | sudo apt install jq 210 | ``` 211 | 212 | #### Usage 213 | 214 | Format in JSON. 215 | 216 | ```bash 217 | echo '{"name": "John", "age": 30}' | jq 218 | ``` 219 | 220 | Will print out the the specified key. 221 | 222 | ```bash 223 | echo '{"name": "John", "age": 30}' | jq '.name' 224 | ``` 225 | 226 | 227 | -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/1 echo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Hi Mom" 4 | 5 | sleep 3 6 | 7 | echo "Hey Rahul" 8 | 9 | sleep 3 10 | 11 | echo "How are you?" 12 | 13 | sleep 3 14 | 15 | echo "I am fine" 16 | 17 | sleep 3 -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/10 case.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Pick a number from 1 to 3" 4 | read number 5 | 6 | case $number in 7 | 1) 8 | echo "You picked 1" 9 | name="One" 10 | ;; 11 | 2) 12 | echo "You picked 2" 13 | name="Two" 14 | ;; 15 | 3) 16 | echo "You picked 3" 17 | name="Three" 18 | ;; 19 | *) 20 | echo "You did not pick a number from 1 to 3" 21 | ;; 22 | esac 23 | 24 | echo "$name" 25 | 26 | -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/11 while.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | x=1 4 | 5 | while [[ $x -le 10 ]] 6 | do 7 | echo "The number is $x" 8 | # x=$(( $x + 1 )) 9 | (( x++ )) 10 | done 11 | -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/12 until.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | until [[ $number -eq 10 ]] 4 | do 5 | echo "The number is $number" 6 | read number 7 | done 8 | echo "You have entered 10" -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/13 for.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # for cups in 1 2 3 4 5 6 4 | for cups in {1..6} 5 | do 6 | echo "I have $cups cups of coffee" 7 | done -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/14 break-continue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | while true 4 | do 5 | read -p "Enter a number: " num 6 | if [[ $num -eq 10 ]]; then 7 | break 8 | elif [[ $num -eq 5 ]]; then 9 | continue 10 | fi 11 | echo "You have entered $num" 12 | done -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/15 function.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function hello { 4 | echo "Hello World" 5 | } 6 | 7 | hello 8 | -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/2 read.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Enter your name? " 4 | read name 5 | echo "Hi $name" -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/3 variables.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | name="Pradumna" 4 | 5 | echo "Hi $name" 6 | echo "You are looking good $name" -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/4 arguments.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | name=$1 4 | food=$2 5 | 6 | echo "Hi $name" 7 | echo "You like $food" 8 | -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/5 arguments2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | name=$1 4 | 5 | user=$(whoami) 6 | date=$(date +%F) 7 | whereami=$(pwd) 8 | 9 | echo "Good Morning $name" 10 | 11 | echo "You are curently logged in as $user and you are in the $whereami directory on $date" -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/6 athemetic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "what is your name?" 4 | 5 | read name 6 | 7 | echo "How old are you?" 8 | 9 | read age 10 | 11 | echo "Calculating your future..." 12 | sleep 3 13 | 14 | echo "Hey, $name, you will become millionare in $((($RANDOM % 15)+ $age)) years." -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/7 conditionals.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Hey, do you like coffee? (y/n)" 4 | 5 | read answer 6 | 7 | if [ $answer == "y" ]; then 8 | echo "Great, I like coffee too!" 9 | else 10 | echo "Oh, I see. I like coffee." 11 | fi -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/8 conditionals1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | beast=$(( $RANDOM % 2 )) 4 | 5 | echo "Your first besat approcahes. Prepare to fight!. Pick your weapon: (0)Sword (1)Gun" 6 | 7 | read weapon 8 | 9 | if [ $weapon == $beast ]; then 10 | echo "You have slain the beast!" 11 | else 12 | echo "You have been slain by the beast!" 13 | exit 1 14 | fi 15 | 16 | sleep 2 17 | 18 | echo "The fight is not over. You have been transported to a new location. Pick a number between 0 and 1" 19 | 20 | read number 21 | 22 | beast=$(( $RANDOM % 2 )) 23 | 24 | if [ $number == $beast -o $number == "cheat" ]; then 25 | if [ $USER == "pradumnasaraf" ]; then 26 | echo "You have slain the beast!" 27 | else 28 | echo "You have been slain by the beast!" 29 | exit 1 30 | fi 31 | else 32 | echo "You have been slain by the beast!" 33 | exit 1 34 | fi -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/concepts/9 conditionals2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | num=$1 4 | 5 | if [ $num -gt 0 ]; then 6 | echo "The number is positive" 7 | elif [ $num -lt 0 ]; then 8 | echo "The number is negative" 9 | else 10 | echo "The number is zero" 11 | fi -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/crypto-price.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | URL=https://api.coindcx.com/exchange/ticker 4 | 5 | curl -s $URL | jq '.[] | {ticker: .market, price: .last_price}' | jq -r '.ticker + " -> " + .price' -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/ip-alive-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -p "Enter the IP address to ping: " ip 4 | 5 | COUNTER=0 6 | 7 | while true 8 | do 9 | if ping -c 1 $ip > /dev/null; then 10 | echo "Hey, $ip is up!!" 11 | COUNTER=0 12 | break 13 | else 14 | COUNTER=$((COUNTER+1)) 15 | echo "$COUNTER) Hey, $ip is down!!" 16 | fi 17 | sleep 4 18 | done -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/ping.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for x in google.com yahoo.com facebook.com google.coom 4 | do 5 | if ping -c 1 $x > /dev/null 6 | then 7 | echo "$x is up" 8 | else 9 | echo "$x is down" 10 | fi 11 | done 12 | -------------------------------------------------------------------------------- /Bash-Scripting/Scripts/random-quote.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -p "How many quotes do you want to see? " NUM 4 | 5 | if [[ -z $NUM ]]; then 6 | echo "Please enter a number" 7 | exit 1 8 | elif [[ $NUM -eq 0 ]]; then 9 | echo "Please enter a number greater than 0" 10 | exit 1 11 | elif [[ $NUM -lt 0 ]]; then 12 | echo "Please enter a positive number" 13 | exit 1 14 | fi 15 | 16 | URL=https://api.quotable.io/random 17 | 18 | for (( i=1; i<=$NUM; i++ )) 19 | do 20 | curl -s $URL | jq -r .content 21 | sleep 1 22 | done 23 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.3.2](https://github.com/Pradumnasaraf/DevOps/compare/v1.3.1...v1.3.2) (2022-12-11) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * the broken path on hosted website ([f3494ae](https://github.com/Pradumnasaraf/DevOps/commit/f3494ae339ecc1473387942dfbc9862624c70c7a)) 7 | 8 | 9 | 10 | ## [1.3.1](https://github.com/Pradumnasaraf/DevOps/compare/v0.1.0...v1.3.1) (2022-11-18) 11 | 12 | 13 | ### Bug Fixes 14 | 15 | * extra spacing ([18360a9](https://github.com/Pradumnasaraf/DevOps/commit/18360a9b9371aeb78ff22bbb92443520d5dd2365)) 16 | 17 | 18 | 19 | # [0.1.0](https://github.com/Pradumnasaraf/DevOps/compare/753b1b7a5c1e8c40816946ee0d08a36f13675029...v0.1.0) (2022-10-17) 20 | 21 | 22 | ### Features 23 | 24 | * Added initial files ([753b1b7](https://github.com/Pradumnasaraf/DevOps/commit/753b1b7a5c1e8c40816946ee0d08a36f13675029)) 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | pradumnasaraf@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | > IMPORTANT **Note** 2 | > 3 | > **Pull Requests having no issue associated with them will not be accepted. Firstly get an issue assigned, whether it's already opened or raised by you, and then create a Pull Request.** 4 | 5 | ## 👨‍💻 Prerequisite 6 | 7 | #### Documention 8 | 9 | - [Git](https://git-scm.com/) 10 | - [Markdown](https://www.markdownguide.org/basic-syntax/) 11 | 12 | #### Code 13 | 14 | - [HTML](https://www.w3schools.com/html/) 15 | 16 | ## 💥 How to Contribute 17 | 18 | - Look at the existing [**Issues**](https://github.com/Pradumnasaraf/DevOps/issues) or [**create a new issue**](https://github.com/Pradumnasaraf/DevOps/issues/new/choose)! 19 | - [**Fork the Repo**](https://github.com/Pradumnasaraf/DevOps/fork). Then, create a branch for any issue that you are working on. Finally, commit your work. 20 | - Create a **[Pull Request](https://github.com/Pradumnasaraf/DevOps)** (_PR_), which will be promptly reviewed and given suggestions for improvements by the community. 21 | - Add screenshots or screen captures to your Pull Request to help us understand the effects of the changes proposed in your PR. 22 | -------------------------------------------------------------------------------- /DevSecOps/README.md: -------------------------------------------------------------------------------- 1 | ## DevSecOps 2 | 3 | It is a set of practices that combines software development (Dev) and information security (Sec) to shorten the systems development life cycle while providing continuous monitoring to ensure the delivery of secure software. 4 | 5 | - [DevSecOps](https://www.redhat.com/en/topics/devops/what-is-devsecops) -------------------------------------------------------------------------------- /Docker/Dockerfile/Dockerfile.drupal: -------------------------------------------------------------------------------- 1 | FROM drupal:9.3.13 2 | 3 | 4 | RUN apt-get update \ 5 | && apt-get install -y --no-install-recommends \ 6 | git \ 7 | && rm -rf /var/lib/apt/lists/* 8 | 9 | # this next part was corrected to be more clear on how you'd typically 10 | # customize your own theme. first you need to clone the theme into this repo 11 | # with something like downloading the lastest theme for bootstrap 12 | # https://www.drupal.org/project/bootstrap and extract into themes dir on host. 13 | # then you'll COPY it into image here: 14 | 15 | WORKDIR /var/www/html/core 16 | 17 | COPY ./themes ./themes 18 | 19 | WORKDIR /var/www/html 20 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/.gitignore: -------------------------------------------------------------------------------- 1 | sample-data 2 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM drupal:9.3.13 2 | 3 | 4 | RUN apt-get update \ 5 | && apt-get install -y --no-install-recommends \ 6 | git \ 7 | && rm -rf /var/lib/apt/lists/* 8 | 9 | WORKDIR /var/www/html/core 10 | 11 | COPY ./themes ./themes 12 | 13 | WORKDIR /var/www/html 14 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | 5 | drupal: 6 | build: . 7 | ports: 8 | - "8080:80" 9 | volumes: 10 | - drupal-modules:/var/www/html/modules 11 | - drupal-profiles:/var/www/html/profiles 12 | - drupal-sites:/var/www/html/sites 13 | - ./themes:/var/www/html/themes 14 | 15 | postgres: 16 | environment: 17 | - POSTGRES_PASSWORD_FILE=/run/secrets/psql-pw 18 | secrets: 19 | - psql-pw 20 | volumes: 21 | - drupal-data:/var/lib/postgresql/data 22 | 23 | volumes: 24 | drupal-data: 25 | drupal-modules: 26 | drupal-profiles: 27 | drupal-sites: 28 | drupal-themes: 29 | 30 | secrets: 31 | psql-pw: 32 | file: psql-fake-password.txt 33 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/docker-compose.prod.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | 5 | drupal: 6 | ports: 7 | - "80:80" 8 | volumes: 9 | - drupal-modules:/var/www/html/modules 10 | - drupal-profiles:/var/www/html/profiles 11 | - drupal-sites:/var/www/html/sites 12 | - drupal-themes:/var/www/html/themes 13 | 14 | postgres: 15 | environment: 16 | - POSTGRES_PASSWORD_FILE=/run/secrets/psql-pw 17 | secrets: 18 | - psql-pw 19 | volumes: 20 | - drupal-data:/var/lib/postgresql/data 21 | 22 | volumes: 23 | drupal-data: 24 | drupal-modules: 25 | drupal-profiles: 26 | drupal-sites: 27 | drupal-themes: 28 | 29 | secrets: 30 | psql-pw: 31 | external: true 32 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/docker-compose.test.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | 5 | drupal: 6 | image: custom-drupal 7 | build: . 8 | ports: 9 | - "80:80" 10 | 11 | postgres: 12 | environment: 13 | - POSTGRES_PASSWORD_FILE=/run/secrets/psql-pw 14 | secrets: 15 | - psql-pw 16 | volumes: 17 | # NOTE: this might be sample data you host in your CI server 18 | # so you can do integration testing with sample data 19 | # this may not work on Docker for Windows/Mac due to bind-mounting 20 | # database data across OSes, which doesn't always work 21 | # in those cases you should use named volumes 22 | - ./sample-data:/var/lib/postgresql/data 23 | secrets: 24 | psql-pw: 25 | file: psql-fake-password.txt 26 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | drupal: 5 | image: custom-drupal:latest 6 | 7 | postgres: 8 | image: postgres:14.3 9 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/psql-fake-password.txt: -------------------------------------------------------------------------------- 1 | mypasswd 2 | -------------------------------------------------------------------------------- /Docker/Prod-app-demo/themes/themes-go-here: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ayush7614/DevOps/34db69d7f13e2302d6b16f348232630219504a4c/Docker/Prod-app-demo/themes/themes-go-here -------------------------------------------------------------------------------- /Docker/README.md: -------------------------------------------------------------------------------- 1 | ## Docker 2 | 3 | ### Learning Resources 4 | 5 | - [Docker Mastery (Course)](https://www.udemy.com/course/docker-mastery/) 6 | - [FreeCodeCamp Docker (Video)](https://youtu.be/kTp5xUtcalw) 7 | 8 | ### ⚫ Docker Images 9 | 10 | - Images are made up of app binaries, dependencies, and metadata. Don't contain a full OS. 11 | - Images are a combination of multiple layers. 12 | - Each Image has its unique ID and a tag for a different version. 13 | 14 | ![Screenshot from 2022-11-02 11-57-19](https://user-images.githubusercontent.com/51878265/199414178-d59e8780-c140-4bf1-b27e-7e8f1c723afb.png) 15 | 16 | ### ⚫ Dockerfile 17 | 18 | > Commands: 19 | 20 | - `FROM` (base image) 21 | - `COPY` (copy files from local to the container) 22 | - `ARG` (pass arguments) 23 | - `ENV` (environment variable) 24 | - `RUN` (any arbitrary shell command) 25 | - `EXPOSE` (open port from container to virtual network) 26 | - `CMD` (command to run when the container starts) 27 | - `WORKDIR` (Create a dir where all the files will be copied and used.) 28 | 29 | To build an image from the **Dockerfile**, use this command 30 | 31 | ```bash 32 | docker build 33 | // docker build. 34 | ``` 35 | 36 | **Good Practice** 37 | 38 | - Copy the dependencies 1st and then copy the rest of the files. 39 | 40 | ```Dockerfile 41 | COPY package.json ./ 42 | RUN npm install 43 | COPY . ./ 44 | ``` 45 | 46 | ### ⚫ .dockerignore 47 | 48 | We have a file `.dockerignore` which is not required when we copy files into the container. 49 | 50 | ### ⚫ Docker Network 51 | 52 | - We need create custom bridge network to enable dns resolution between containers. It doesn't work with the default bridge network. 53 | 54 | - Host: Use the host network stack inside the container. The container will use the host's network interfaces. We don't need to expose ports. 55 | 56 | ### ⚫ Docker Volumes 57 | 58 | We need volume to Persist our data, like databases and user info, because containers can go up and down, and we need some way to preserve our data. 59 | 60 | We attach volume during run time 61 | 62 | ```bash 63 | docker run -v /path/in/container 64 | ``` 65 | 66 | **Named Volume** 67 | We can also name the volume otherwise it will generate the ID and be hard to track 68 | 69 | ```bash 70 | docker run -v : 71 | docker run -v myvolume:/src/public nginx 72 | ``` 73 | 74 | ### Bind Mounting 75 | 76 | A file or directory on the host machine is mounted into a container, i.e it will match the condition of the file system inside a container. 77 | 78 | ```bash 79 | docker run -v : 80 | docker run -v /app/content:/usr/share/nginx/html nginx 81 | docker run -v $(pwd):/user/html nginx 82 | ``` 83 | In compose, we dont have to give the `pwd` 84 | 85 | ```yaml 86 | volumes: 87 | - ./:/usr/share/nginx/html:ro 88 | - ./app:/usr/share/nginx/html/app:ro 89 | ``` 90 | 91 | ### ⚫ Docker Compose 92 | 93 | - Compose help us define and running multi-container Docker applications and configure relationships between containers 94 | - It also saves the hassle from entering the commands from the CLI. 95 | - We have to write the configs in the YAML file, by default the file name is `docker-compose.yml`. We can run/stop by `docker compose up/down` 96 | 97 | The Skeleton of Docker compose 98 | 99 | ```yaml 100 | services: # containers. same as docker run 101 | servicename: # a friendly name. this is also the DNS name inside the network 102 | image: # Optional if you use to build: 103 | command: # Optional, replace the default CMD specified by the image 104 | environment: # Optional, same as -e in docker run 105 | volumes: # Optional, same as -v in docker run 106 | servicename2: 107 | 108 | volumes: # Optional, same as docker volume create 109 | 110 | networks: # Optional, same as docker network create 111 | ``` 112 | 113 | Sample: 114 | 115 | ```yaml 116 | mongo: 117 | container_name: mongo 118 | image: mongo:4.0 119 | volumes: 120 | - mongo-db:/data/db 121 | networks: 122 | - my-net 123 | 124 | volumes: 125 | mongo-db: # named volume 126 | 127 | networks: 128 | my-net: 129 | driver: bridge 130 | ``` 131 | 132 | If any container depends on another container 133 | 134 | ```yaml 135 | depends_on: 136 | - mysql-primary 137 | ``` 138 | 139 | ## ⚫ Docker Swarm 140 | 141 | Docker Swarm is an orchestration management tool that runs on Docker applications. Container orchestration automates the deployment, management, scaling, and networking of containers 142 | 143 | - Docker Swarm is not enabled by default, we have enabled it by 144 | 145 | ```bash 146 | docker swarm init 147 | ``` 148 | 149 | - In this, we create services, instead of creating the container directly 150 | 151 | ### Docker service 152 | 153 | In swarm we don't create containers directly, instead, we create service and that creates a container for us. A service can run multiple nodes on several nodes. 154 | 155 | ![Screenshot from 2022-11-08 13-07-01](https://user-images.githubusercontent.com/51878265/200502631-b574f4fc-8a0c-4e6f-8493-6d666ec1db2e.png) 156 | 157 | ### Docker Stack 158 | 159 | When we have multiple services and to establish the relationship between them we use the stack, it is the same as compose file. 160 | Here we don't use `build:` object and there is new `deploy:` specific to swarm to like replicas, and secrets. 161 | 162 | ![Screenshot from 2022-11-04 13-34-28](https://user-images.githubusercontent.com/51878265/199923225-83fe75fc-406a-4d51-b2d4-15fb5ec6b4ee.png) 163 | 164 | ```yaml 165 | deploy: 166 | replicas: 3 167 | ``` 168 | We deploy stack files with this command 169 | 170 | ```bash 171 | docker stack deploy -c file.yml 172 | ``` 173 | 174 | ### Docker Secrets 175 | 176 | Docker Swarm supports secrets. We can pass ENV variables like SSH keys, Usernames, and passwords with help of that. We can pass secrets from the file or save the Docker secret. 177 | 178 | - We can create Docker secrets though CLI `external:` 179 | 180 | ```bash 181 | echo "" | docker secret create psql-pw - 182 | ``` 183 | 184 | or 185 | 186 | - Create a file with a password and then pass the path in the stack `file:` 187 | 188 | ```yaml 189 | services: 190 | postgres: 191 | image: postgres 192 | secrets: 193 | - post-pass 194 | - post-user 195 | environment: 196 | POSTGRES_PASSWORD_FILE: /run/secrets/post-pass 197 | POSTGRES_USER_FILE: /run/secrets/post-user 198 | 199 | secrets: 200 | post-pass: 201 | external: true 202 | post-user: 203 | file: ./post-user.txt 204 | ``` 205 | ## ⚫ Docker Healthcheck 206 | 207 | ```dockerfile 208 | HEALTHCHECK --interval=30s --timeout=3s \ 209 | CMD curl -f http://localhost/ || exit 1 210 | ``` 211 | 212 | ## ⚫ Private Docker Registry 213 | 214 | We can create a reg with the official [Registry image](https://hub.docker.com/_/registry) 215 | 216 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /Docker/YAML/compose-template.yml: -------------------------------------------------------------------------------- 1 | # version isn't needed as of 2020 for docker compose CLI. 2 | # All 2.x and 3.x features supported 3 | # Docker Swarm still needs a 3.x version 4 | # version: '3.9' 5 | 6 | services: # containers. same as docker run 7 | servicename: # a friendly name. this is also DNS name inside network 8 | image: # Optional if you use build: 9 | command: # Optional, replace the default CMD specified by the image 10 | environment: # Optional, same as -e in docker run 11 | volumes: # Optional, same as -v in docker run 12 | servicename2: 13 | 14 | volumes: # Optional, same as docker volume create 15 | 16 | networks: # Optional, same as docker network create 17 | -------------------------------------------------------------------------------- /Docker/YAML/drupal-compose.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '3.7' 3 | 4 | services: 5 | drupal: 6 | image: drupal 7 | ports: 8 | - "8080:80" 9 | volumes: 10 | - drupal-modules:/var/www/html/modules 11 | - drupal-profiles:/var/www/html/profiles 12 | - drupal-sites:/var/www/html/sites 13 | - drupal-themes:/var/www/html/themes 14 | postgres: 15 | image: postgres 16 | environment: 17 | - POSTGRES_PASSWORD=postgres 18 | 19 | volumes: 20 | drupal-modules: 21 | drupal-profiles: 22 | drupal-sites: 23 | drupal-themes: 24 | -------------------------------------------------------------------------------- /Docker/YAML/drupal-stack.yaml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | drupal: 5 | image: drupal 6 | ports: 7 | - "8080:80" 8 | volumes: 9 | - drupal-modules:/var/www/html/modules 10 | - drupal-profiles:/var/www/html/profiles 11 | - drupal-sites:/var/www/html/sites 12 | - drupal-themes:/var/www/html/themes 13 | deploy: 14 | replicas: 3 15 | 16 | postgres: 17 | image: postgres 18 | environment: 19 | - POSTGRES_PASSWORD=postgres 20 | deploy: 21 | replicas: 2 22 | 23 | 24 | volumes: 25 | drupal-modules: 26 | drupal-profiles: 27 | drupal-sites: 28 | drupal-themes: 29 | -------------------------------------------------------------------------------- /Docker/YAML/sample1.yml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | services: 3 | 4 | redis: 5 | image: redis:alpine 6 | networks: 7 | - frontend 8 | deploy: 9 | replicas: 1 10 | update_config: 11 | parallelism: 2 12 | delay: 10s 13 | restart_policy: 14 | condition: on-failure 15 | db: 16 | image: postgres:9.4 17 | volumes: 18 | - db-data:/var/lib/postgresql/data 19 | networks: 20 | - backend 21 | environment: 22 | - POSTGRES_HOST_AUTH_METHOD=trust 23 | deploy: 24 | placement: 25 | constraints: [node.role == manager] 26 | vote: 27 | image: bretfisher/examplevotingapp_vote 28 | ports: 29 | - 5000:80 30 | networks: 31 | - frontend 32 | depends_on: 33 | - redis 34 | deploy: 35 | replicas: 2 36 | update_config: 37 | parallelism: 2 38 | restart_policy: 39 | condition: on-failure 40 | result: 41 | image: bretfisher/examplevotingapp_result 42 | ports: 43 | - 5001:80 44 | networks: 45 | - backend 46 | depends_on: 47 | - db 48 | deploy: 49 | replicas: 1 50 | update_config: 51 | parallelism: 2 52 | delay: 10s 53 | restart_policy: 54 | condition: on-failure 55 | 56 | worker: 57 | image: bretfisher/examplevotingapp_worker 58 | networks: 59 | - frontend 60 | - backend 61 | depends_on: 62 | - db 63 | - redis 64 | deploy: 65 | mode: replicated 66 | replicas: 1 67 | labels: [APP=VOTING] 68 | restart_policy: 69 | condition: on-failure 70 | delay: 10s 71 | max_attempts: 3 72 | window: 120s 73 | placement: 74 | constraints: [node.role == manager] 75 | 76 | visualizer: 77 | image: bretfisher/visualizer 78 | ports: 79 | - 8080:8080 80 | stop_grace_period: 1m30s 81 | networks: 82 | - frontend 83 | volumes: 84 | - /var/run/docker.sock:/var/run/docker.sock 85 | deploy: 86 | placement: 87 | constraints: [node.role == manager] 88 | 89 | networks: 90 | frontend: 91 | backend: 92 | 93 | volumes: 94 | db-data: 95 | -------------------------------------------------------------------------------- /Docker/YAML/sample2.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | # NOTE: This example only works on x86_64 (amd64) 3 | # Percona doesn't yet publish arm64 (Apple Silicon M1) or arm/v7 (Raspberry Pi 32-bit) images 4 | 5 | services: 6 | ghost: 7 | image: ghost 8 | ports: 9 | - "80:2368" 10 | environment: 11 | - URL=http://localhost 12 | - NODE_ENV=production 13 | - MYSQL_HOST=mysql-primary 14 | - MYSQL_PASSWORD=mypass 15 | - MYSQL_DATABASE=ghost 16 | volumes: 17 | - ./config.js:/var/lib/ghost/config.js 18 | depends_on: 19 | - mysql-primary 20 | - mysql-secondary 21 | proxysql: 22 | # image only works on x86_64 (amd64) 23 | image: percona/proxysql 24 | environment: 25 | - CLUSTER_NAME=mycluster 26 | - CLUSTER_JOIN=mysql-primary,mysql-secondary 27 | - MYSQL_ROOT_PASSWORD=mypass 28 | 29 | - MYSQL_PROXY_USER=proxyuser 30 | - MYSQL_PROXY_PASSWORD=s3cret 31 | mysql-primary: 32 | # image only works on x86_64 (amd64) 33 | image: percona/percona-xtradb-cluster:5.7 34 | environment: 35 | - CLUSTER_NAME=mycluster 36 | - MYSQL_ROOT_PASSWORD=mypass 37 | - MYSQL_DATABASE=ghost 38 | - MYSQL_PROXY_USER=proxyuser 39 | - MYSQL_PROXY_PASSWORD=s3cret 40 | mysql-secondary: 41 | # image only works on x86_64 (amd64) 42 | image: percona/percona-xtradb-cluster:5.7 43 | environment: 44 | - CLUSTER_NAME=mycluster 45 | - MYSQL_ROOT_PASSWORD=mypass 46 | 47 | - CLUSTER_JOIN=mysql-primary 48 | - MYSQL_PROXY_USER=proxyuser 49 | - MYSQL_PROXY_PASSWORD=s3cret 50 | depends_on: 51 | - mysql-primary 52 | -------------------------------------------------------------------------------- /Docker/YAML/secret-stack-1.yaml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | 3 | services: 4 | postgres: 5 | image: postgres 6 | secrets: 7 | - post-pass 8 | - post-user 9 | environment: 10 | POSTGRES_PASSWORD_FILE: /run/secrets/post-pass 11 | POSTGRES_USER_FILE: /run/secrets/post-user 12 | 13 | secrets: 14 | post-pass: 15 | external: true 16 | post-user: 17 | file: ./post-user.txt 18 | -------------------------------------------------------------------------------- /Docker/YAML/secret-stack.yml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | 3 | services: 4 | psql: 5 | image: postgres 6 | secrets: 7 | - psql_user 8 | - psql_password 9 | environment: 10 | POSTGRES_PASSWORD_FILE: /run/secrets/psql_password 11 | POSTGRES_USER_FILE: /run/secrets/psql_user 12 | 13 | secrets: 14 | psql_user: 15 | file: ./psql_user.txt 16 | psql_password: 17 | file: ./psql_password.txt 18 | -------------------------------------------------------------------------------- /Docker/commands/README.md: -------------------------------------------------------------------------------- 1 | ### Docker Basic 2 | 3 | - To check Docker vesrion 4 | 5 | ``` 6 | docker version 7 | ``` 8 | 9 | - To check all the available images 10 | 11 | ```bash 12 | docker images 13 | ``` 14 | 15 | - Pull/Downlaod the image from the Docker registry to local machine. 16 | 17 | ```bash 18 | docker pull 19 | //Eg: docker run nginx 20 | ``` 21 | 22 | - To run an container (It will 1st pull the image if not present in the local sytem) 23 | - NOTE: When we just provide the name of the image it will pull the lastest one, i.e `nginx:latest`. We can also specify the version `nginx:1.14` 24 | - Additioanly we can use flags 25 | 26 | - `--name `- To give a name to the container. 27 | - `-p `- To fowrad the port. 28 | - `-d` - To run in detached mode 29 | - `-it` - For interactive envirnoment 30 | - `-e` - For environment variable 31 | 32 | ```bash 33 | docker run 34 | //Eg: docker run nginx 35 | ``` 36 | 37 | - We can aslo pass a complete `.env` file 38 | 39 | ```bash 40 | --env-file 41 | Eg: --env-file ./.env 42 | ``` 43 | 44 | ### Docker Container 45 | 46 | - To stop a running container 47 | 48 | ```bash 49 | docker stop 50 | ``` 51 | 52 | - To resume a stopped container 53 | 54 | ```bash 55 | docker start 56 | ``` 57 | 58 | - To check the running processes inside a container. 59 | 60 | ```bash 61 | docker top 62 | ``` 63 | 64 | - To check stats of running container. 65 | 66 | ```bash 67 | docker stats 68 | ``` 69 | 70 | - Check the config and info of a container. 71 | 72 | ```bash 73 | docker stats 74 | //Eg: docker inspect mynginx 75 | ``` 76 | 77 | - Check all the container running. 78 | 79 | ```bash 80 | docker ps 81 | or 82 | docker container ls 83 | ``` 84 | 85 | - To start and interactive session and get inside the container. 86 | 87 | - NOTE: every image does not support `bash` so we use `sh` 88 | 89 | ``` 90 | docker exec -it bash/sh 91 | ``` 92 | 93 | - To check which ports has been exposed and forwarded 94 | 95 | ```bash 96 | docker port 97 | ``` 98 | 99 | - To check all the stopped container 100 | 101 | ```bash 102 | docker ps -a 103 | ``` 104 | 105 | - Check logs of a container 106 | 107 | ```bash 108 | docker logs 109 | ``` 110 | 111 | - Delete all the stopped container 112 | 113 | ```bash 114 | docker container prune -f 115 | ``` 116 | - Auto cleanup when t 117 | 118 | ```bash 119 | docker container run —rm 120 | ``` 121 | 122 | ### Docker Network 123 | 124 | - Check list of avilable networks. 125 | 126 | ```bash 127 | docker network ls 128 | ``` 129 | 130 | - Inspect a network components, like which container are attached to that network. 131 | 132 | ```bash 133 | docker network inspect 134 | ``` 135 | 136 | - Run a container on a certian network/own careted network 137 | 138 | ``` 139 | docker run --network 140 | ``` 141 | 142 | ``` 143 | docker inspect --format "{{.NetworkSettings.IPAddress}}" 144 | ``` 145 | 146 | ### Docker Images 147 | 148 | - Remove an image 149 | 150 | ```bash 151 | docker rmi -f 152 | ``` 153 | 154 | - Remove all the images at once 155 | 156 | ```bash 157 | docker rmi $(docker images -q) 158 | ``` 159 | 160 | - To inspect an image layers and other info 161 | 162 | ```bash 163 | docker inspect 164 | ``` 165 | 166 | - Check the image layers formation 167 | 168 | ```bash 169 | docker history 170 | ``` 171 | 172 | - Create a our own image with an existing image. 173 | 174 | ``` 175 | docker image tag 176 | docker image tag nginx pradumna/nginx:hello 177 | ``` 178 | 179 | ### Docker Volume 180 | 181 | - Create bind mount 182 | - Help to sync our local files with help of Docker container. 183 | 184 | 185 | - To sync our local machine changes with help of Docker volume (Bind mount) 186 | - `- v` is use to define volume, aslo we give another `-v` flag to override the changes so that it will not chnage in container. 187 | 188 | ```bash 189 | docker run -v : -p : -d --name docker-node docker-node 190 | docker 191 | ``` 192 | 193 | ```bash 194 | docker run -v : -v -p : -d --name docker-node docker-node 195 | ``` 196 | To make it read only so that when you add some files inside it, the container will not get created on your local machine use `-v port:port:ro` 197 | 198 | ### Docker Compose 199 | 200 | - Run docker compose file. 201 | Note: By default it finds for the file name `docker-compose.yaml`, to give file with other naming use `-f ` command 202 | 203 | ```bash 204 | docker compose up -d 205 | ``` 206 | 207 | ```bash 208 | docker compose down 209 | ``` 210 | 211 | - To rebuilt the new Image with thew new changes 212 | 213 | ```bash 214 | docker compose up --build 215 | ``` 216 | 217 | - Override the existing of compose file 218 | 219 | ```bash 220 | docker compose -f docker-compose.yaml -f docker-compose.dev.yaml 221 | ``` 222 | 223 | ### Docker Swam and Services 224 | 225 | - Initalize swarm 226 | 227 | ```bash 228 | docker swarm init 229 | ``` 230 | 231 | - Check all the node available 232 | 233 | ```bash 234 | docker node ls 235 | ``` 236 | 237 | - To add a node as a manager 238 | 239 | ```bash 240 | docker node update --role manager 241 | ``` 242 | 243 | - To create an overlay network 244 | 245 | ```bash 246 | docker network create -d overlay backend 247 | ``` 248 | 249 | - Create a service. Also we can add flags for further customiztaion. 250 | 251 | - `--name` - to give a service name 252 | - `--replicas` - to define how many running instance of the same image. 253 | - `-p` - for port forwarding 254 | 255 | ```bash 256 | docker service create -p 8080:80 --name vote --replicas 2 nginx 257 | ``` 258 | 259 | - To get all task containers running on different node 260 | 261 | ```bash 262 | docker service ps 263 | ``` 264 | 265 | > SERVICE UPDATE 266 | 267 | - To scale up the service (i.e increasing the no of replicas) 268 | 269 | ```bash 270 | docker service scale = 271 | docker service scale mynginx=5 272 | ``` 273 | 274 | - To update the image in running service 275 | 276 | ```bash 277 | docker service update --image 278 | docker service update --image mynginx:1.13.6 web 279 | ``` 280 | 281 | - To update the port 282 | 283 | We can't direclty update the port We have to add and remove the ports 284 | 285 | ``` 286 | docker service update --publish-rm 8080 --publish-add 808180 287 | docker service update --publish-rm 8080 --publish-add 808180 mynginx 288 | ``` 289 | 290 | ### Docker Stack 291 | 292 | - To deploy a stack file 293 | 294 | ```bash 295 | docker stack deploy -c 296 | ``` 297 | 298 | - To remove running stack 299 | 300 | ``` 301 | docker stack rm 302 | ``` 303 | 304 | - To check list of stacks running 305 | 306 | ``` 307 | docker stack ls 308 | ``` 309 | 310 | **STACK -> SERVICES -> TASKS -> CONTAINERS** 311 | 312 | - To check which services are running inside a staacks 313 | 314 | ``` 315 | docker stack services 316 | ``` 317 | 318 | - To check taks are running inside a stack 319 | 320 | ``` 321 | docker stack ps 322 | ``` 323 | 324 | > Registry 325 | 326 | ``` 327 | 127.0.0.0:5000/v2/_catalog 328 | ``` 329 | 330 | ### Tips and Short hands 331 | 332 | - Run the command with the container creation 333 | 334 | ```bash 335 | doc run 336 | // Eg: `doc run ubuntu:16.04 echo hey` 337 | ``` 338 | 339 | 340 | - Creating our Own image and container. 341 | 342 | ``` 343 | Step 1 - create Dockerfile 344 | Step 2 - docker build -t myimage:1.0 (-t for tag) 345 | Step 3 - docker run 346 | ``` 347 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.23.2 2 | WORKDIR /usr/share/nginx/html 3 | COPY . . 4 | EXPOSE 80 -------------------------------------------------------------------------------- /Git/README.md: -------------------------------------------------------------------------------- 1 | # Git is free and open source software for distributed version control. Official [website](https://git-scm.com/) 2 | 3 | ## Online Resources 4 | 5 | - [learngitbranching.js.org](https://learngitbranching.js.org/) 6 | - [gitexplorer.com](https://gitexplorer.com/) 7 | 8 | ## Local Resources 9 | 10 | - Use `--help` option with any command to get to know how to use the command: 11 | 12 | ```bash 13 | git push --help 14 | ``` 15 | -------------------------------------------------------------------------------- /Git/commands/README.md: -------------------------------------------------------------------------------- 1 | # Git commands 2 | 3 | ## **Add** 4 | 5 | - New changes 6 | 7 | ```bash 8 | git add # To add a specific file 9 | 10 | git add . # To add all the files in the current directory 11 | ``` 12 | 13 | - New branch 14 | 15 | ```bash 16 | git branch # and remain in the current branch 17 | 18 | git checkout -b # and switch to the new branch 19 | 20 | git checkout -b # From another branch 21 | 22 | ``` 23 | 24 | - New remote repository 25 | 26 | ```bash 27 | git remote add 28 | ``` 29 | 30 | - Annotated tag 31 | 32 | ```bash 33 | git tag -a v1.4 -m "my version 1.4" 34 | git push --tags 35 | ``` 36 | 37 | ## **Cherry-pick** 38 | 39 | - An commit from the origin branch into my working branch 40 | 41 | ```bash 42 | git cherry-pick 43 | ``` 44 | 45 | ## **Push** 46 | 47 | - Push changes to remote repo 48 | 49 | ```bash 50 | git push 51 | ``` 52 | 53 | - force the push even if it results in a non-fast-forward merge 54 | 55 | ```bash 56 | git push --force # Use the flag in case you know what you’re doing. 57 | ``` 58 | 59 | - Push all of your local branches to the specified remote. 60 | 61 | ```bash 62 | git push --all 63 | ``` 64 | 65 | ## **Clone** 66 | 67 | - Existing repo into a new directory 68 | 69 | ```bash 70 | git clone # Replace "directory" with the directory you want 71 | ``` 72 | 73 | - Existing repo into the current directory 74 | 75 | ```bash 76 | git clone . # The current directory is represented with a "." 77 | ``` 78 | 79 | - existing repo along with submodules into the current directory 80 | 81 | ```bash 82 | git clone --recurse-submodules . 83 | ``` 84 | 85 | - submodules after cloning the existing repo 86 | 87 | ```bash 88 | git submodule update --init --recursive 89 | ``` 90 | 91 | ## **Commit** 92 | 93 | - commit all local changes in tracked files 94 | 95 | ```bash 96 | git commit -a 97 | ``` 98 | 99 | - commit all staged changes 100 | 101 | ```bash 102 | git commit -m # Replace with your commit message. 103 | ``` 104 | 105 | ## **Compare two commits** 106 | 107 | - and output results in the terminal 108 | 109 | ```bash 110 | git diff # the sha hash of the commits you want to compare. 111 | ``` 112 | 113 | - and output result to a file 114 | 115 | ```bash 116 | git diff > diff.txt 117 | ``` 118 | 119 | ## **Configure** 120 | 121 | - name and email address 122 | 123 | ```bash 124 | git config --global user.name "username" 125 | 126 | git config --global user.email "email address" 127 | # Your username and email address should be the same as the one used with your git hosting provider i.e. github, bitbucket etc 128 | ``` 129 | 130 | - default editor 131 | 132 | ```bash 133 | git config --global core.editor "vim" 134 | # Use "code --wait" to set VS Code as default editor 135 | ``` 136 | 137 | - external diff tool 138 | 139 | ```bash 140 | git config --global diff.external "meld" 141 | # You can change "meld" to "emerge" or "kompare" 142 | ``` 143 | 144 | - default merge tool 145 | 146 | ```bash 147 | git config --global merge.tool "meld" 148 | # You can change "meld" to "emerge", "gvimdiff", "kdiff3", "vimdiff", and "tortoisemerge" 149 | ``` 150 | 151 | - color 152 | 153 | ```bash 154 | git config --global color.ui auto # Enables colorization of CLI output 155 | ``` 156 | 157 | - add the GPG key 158 | 159 | ```bash 160 | git config --global user.signingkey 161 | # If you’re taking work from others on the internet and want to verify that commits are actually from a trusted source. 162 | ``` 163 | 164 | ## **Delete** 165 | 166 | - Branch 167 | 168 | ```bash 169 | git branch -D 170 | ``` 171 | 172 | - Tag 173 | 174 | ```bash 175 | git tag -d v 176 | ``` 177 | 178 | - Remote 179 | 180 | ```bash 181 | git remote rm 182 | ``` 183 | 184 | - Untracked files 185 | 186 | ```bash 187 | git clean - 188 | # replace - with: 189 | # -i for interactive command 190 | # -n to preview what will be removed 191 | # -f to remove forcefully 192 | # -d to remove directories 193 | # -X to remove ignored files 194 | ``` 195 | 196 | - Files from index 197 | 198 | ```bash 199 | git rm --cached 200 | ``` 201 | 202 | - Local branches that don't exist at remote 203 | 204 | ```bash 205 | git remote prune 206 | 207 | ``` 208 | 209 | ## **Merge** 210 | 211 | - Another branch to current branch 212 | 213 | ```bash 214 | git merge 215 | ``` 216 | 217 | - Merge a single file from one branch to another. 218 | 219 | ```bash 220 | git checkout --patch 221 | ``` 222 | 223 | ## **Modify** 224 | 225 | - last/latest commit message 226 | 227 | ```bash 228 | git commit --amend 229 | ``` 230 | 231 | - Repo's remote url 232 | 233 | ```bash 234 | git remote set-url # is your remote name e.g origin 235 | ``` 236 | 237 | - Change date and time of the commit 238 | 239 | ```bash 240 | git commit --amend --date="YYYY-MM-DD HH:MM:SS 241 | ``` 242 | 243 | ## **Pull** 244 | 245 | - Pull the specified remote’s copy of the current branch and merge it into local 246 | 247 | ```bash 248 | git pull 249 | ``` 250 | 251 | - Gives output during a pull (displays the pulled content and the merge details) 252 | 253 | ```bash 254 | git pull --verbose 255 | ``` 256 | 257 | - Pull changes and prevent merge conflicts 258 | 259 | ```bash 260 | git pull --ff-only # applies the remote changes only if they can be fast-forwarded 261 | ``` 262 | 263 | ## **Rebase** 264 | 265 | - An origin branch into working branch 266 | 267 | ```bash 268 | git pull --rebase origin 269 | ``` 270 | 271 | - Local branch into my working branch 272 | 273 | ```bash 274 | git rebase 275 | ``` 276 | 277 | - And skip commits 278 | 279 | ```bash 280 | git rebase --skip 281 | # In case of conflicts use this command to discard of your own changes in the current commit 282 | # and apply the changes from an incoming branch 283 | ``` 284 | 285 | - And continue after resolving conflicts 286 | 287 | ```bash 288 | git rebase --continue 289 | # Use it whenever conflicts detected therefore you can resolve these conflicts manually and use this command to continue your rebase operation 290 | ``` 291 | 292 | ## **Rename** 293 | 294 | - Branch 295 | 296 | ```bash 297 | git branch -m # while working in the branch 298 | git branch -m # from outside the branch 299 | ``` 300 | 301 | - Remote 302 | 303 | ```bash 304 | git remote rename 305 | ``` 306 | 307 | ## **Reset** 308 | 309 | - a specific commit 310 | 311 | ```bash 312 | git revert # Get a commit hash by using `git log` 313 | ``` 314 | 315 | - a specific file 316 | 317 | ```bash 318 | git checkout / 319 | ``` 320 | 321 | - To last commit 322 | 323 | ```bash 324 | git reset --hard 325 | ``` 326 | 327 | - To last commit on remote branch 328 | 329 | ```bash 330 | git reset --hard / 331 | ``` 332 | 333 | - Remove/reset all commits 334 | 335 | ```bash 336 | git update-ref -d HEAD 337 | ``` 338 | 339 | ## **Squash** 340 | 341 | - commits in pull request into single commit 342 | 343 | ```bash 344 | git rebase -i 345 | ``` 346 | 347 | - last n number of commit into one 348 | 349 | ```bash 350 | git reset --soft HEAD~N # N for number of commits you want to squash 351 | git add . 352 | git commit -m 353 | ``` 354 | 355 | ## **Stash** 356 | 357 | - Create stash (Tracked and Untracked files) 358 | 359 | ```bash 360 | git stash 361 | ``` 362 | 363 | - Create a new branch and apply stash 364 | 365 | ```bash 366 | git stash branch 367 | ``` 368 | 369 | - Delete 370 | 371 | ```bash 372 | git stash clear # all stashed changes 373 | git stash drop # specific stash 374 | ``` 375 | 376 | - View the contents of a stash 377 | 378 | ```bash 379 | git stash show -p #Leave stash ID to see the latest stash 380 | ``` 381 | 382 | - Apply 383 | 384 | ```bash 385 | git stash apply 386 | git stash apply # stash id can be gotten when you run git stash list 387 | git stash pop # Stash id optional. Add it if you want to apply and delete a specific stash otherwise leave to pop the latest stash 388 | ``` 389 | 390 | - View list of stashed changes 391 | 392 | ```bash 393 | git stash list 394 | ``` 395 | 396 | ## **View** 397 | 398 | - Status of project 399 | 400 | ```bash 401 | git status 402 | ``` 403 | 404 | - Commit(s) log 405 | 406 | ```bash 407 | git log # View all logs 408 | git log -n # for last n number of commits 409 | # to exit you have to press (q) 410 | ``` 411 | 412 | - uncommitted changes 413 | 414 | ```bash 415 | git diff 416 | ``` 417 | 418 | - Committed changes 419 | 420 | ```bash 421 | git diff 422 | ``` 423 | 424 | - repo's remote url 425 | 426 | ```bash 427 | git remote -v 428 | ``` 429 | 430 | - repo's remote url 431 | 432 | ```bash 433 | git branch # The active branch is prefixed with * 434 | ``` 435 | 436 | - repo's remote url 437 | 438 | ```bash 439 | git tag 440 | ``` 441 | -------------------------------------------------------------------------------- /GitHub-Actions/README.md: -------------------------------------------------------------------------------- 1 | ## GitHub Actions 2 | 3 | GitHub Actions is a feature that allows you to automate your software development workflows. You can write individual tasks, called actions, and combine them to create a custom workflow. Workflows are custom automated processes that you can set up in your repository to build, test, package, release, or deploy any code project on GitHub. 4 | 5 | ### Resources 6 | 7 | - [GitHub Actions]( https://docs.github.com/en/actions ) 8 | - [GitHub Actions: Getting Started]( https://docs.github.com/en/actions/learn-github-actions/introduction-to-github-actions ) 9 | 10 | 11 | ### Overview 12 | 13 | - [Docs](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) 14 | 15 | - **Workflow** - A workflow is a configurable automated process made up of one or more jobs. Workflows are defined in `.yml` files in the `.github/workflows` directory of your repository. 16 | 17 | - **Jobs** - A job is a set of steps that execute on the same runner. Runner is a server that has the GitHub Actions runner application installed. 18 | 19 | - **Steps** - A step is an individual task that can run commands or actions like `actions/checkout@v2`. Each step in a job executes on the same runner, allowing for direct file sharing. 20 | 21 | > Summary: The workflow is a set of jobs and each job is a set of steps. Each step can be an action or a shell command. 22 | 23 | Basic worflow file. 24 | 25 | ```yaml 26 | name: CI # name of the workflow 27 | 28 | on: [push] # triggers the workflow on push or pull request events but only for the master branch 29 | 30 | jobs: 31 | build: # name of the job 32 | runs-on: ubuntu-latest # runs-on is the type of machine to run the job on - runner 33 | steps: # steps are the individual tasks that make up a job 34 | 35 | - uses: actions/checkout@v2 36 | - name: Run a one-line script # name is the name of the step 37 | run: echo Hello, world! 38 | ``` 39 | 40 | - **Action** - An action is a custom application for the GitHub Actions platform that performs a complex but frequently repeated task. 41 | 42 | - **Event** - An event is a specific activity that triggers a workflow. For example, activity that occurs on GitHub, such as opening a pull request or pushing a commit. 43 | 44 | ### Triggers 45 | 46 | The `on` keyword is used to trigger the workflow. You can use the following events to trigger a workflow. 47 | 48 | - [Docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows) 49 | 50 | ```yaml 51 | on: 52 | push: 53 | branches: [ master ] 54 | pull_request: 55 | branches: [ master ] 56 | ``` 57 | 58 | ### GitHub context 59 | 60 | The `github` context is available to you in any workflow or action you create on GitHub. You can use the context to get information about the workflow run, the repository, the event that triggered the workflow run, and more. 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /GitHub-Actions/Workflows/docker-image-dockerhub.yaml: -------------------------------------------------------------------------------- 1 | name: Build and Publish Docker Image to DockerHub 2 | 3 | on: 4 | push: 5 | branches: ["main"] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - name: DockerHub Login 15 | uses: docker/login-action@v2.1.0 16 | with: 17 | username: ${{ secrets.DOCKERHUB_USERNAME }} 18 | password: ${{ secrets.DOCKERHUB_PASSWORD }} 19 | 20 | - name: Build the Docker image 21 | run: docker build . --file Dockerfile --tag ${{ secrets.DOCKERHUB_USERNAME }}/opensource-api 22 | 23 | - name: Docker Push 24 | run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/opensource-api -------------------------------------------------------------------------------- /GitHub-Actions/Workflows/docker-image-ghcr.yaml: -------------------------------------------------------------------------------- 1 | name: Create and publish a Docker image to GitHub Container Registry (GHCR) 2 | 3 | on: 4 | push: 5 | branches: ['main'] 6 | 7 | env: 8 | REGISTRY: ghcr.io 9 | IMAGE_NAME: ${{ github.repository }} 10 | 11 | jobs: 12 | build-and-push-image: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | contents: read 16 | packages: write 17 | 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v3 21 | 22 | - name: Log in to the Container registry 23 | uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 24 | with: 25 | registry: ${{ env.REGISTRY }} 26 | username: ${{ github.actor }} 27 | password: ${{ secrets.GITHUB_TOKEN }} 28 | 29 | - name: Extract metadata (tags, labels) for Docker 30 | id: meta 31 | uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 32 | with: 33 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 34 | 35 | - name: Build and push Docker image 36 | uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc 37 | with: 38 | context: . 39 | push: true 40 | tags: ghcr.io/pradumnasaraf/opensource-api:latest 41 | labels: ${{ steps.meta.outputs.labels }} -------------------------------------------------------------------------------- /GitOps/README.md: -------------------------------------------------------------------------------- 1 | ## GitOps 2 | 3 | GitOps is a way of managing Kubernetes clusters using Git as the source of truth. 4 | 5 | ### Benefits of GitOps 6 | 7 | - History of changes to the cluster is stored in Git 8 | - Rollback to a previous version of the cluster is easy 9 | - Changes to the cluster can be reviewed before they are applied 10 | - Changes to the cluster can be tested before they are applied 11 | - Changes to the cluster can be automated 12 | 13 | ### GitOps Tools 14 | 15 | - [ArgoCD](../ArgoCD/README.md) is a git controller that can be used to deploy applications to a Kubernetes cluster. 16 | -------------------------------------------------------------------------------- /Helm/README.md: -------------------------------------------------------------------------------- 1 | Helm is Package manager for Kubernetes. 2 | 3 | ### Resources 4 | 5 | - [Helm Docs](https://helm.sh/) 6 | 7 | 8 | ### Using a Helm Chart 9 | 10 | - Once we install the helm to the system, we have to add a chart repository, like prometheus, Ingress-nginx and [more](https://artifacthub.io/packages/search?kind=0) 11 | 12 | Eg: 13 | 14 | ```bash 15 | helm repo add 16 | helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ 17 | ``` 18 | 19 | - To check list of charts we can install 20 | 21 | ```bash 22 | helm search repo kubernetes-dashboard 23 | ``` 24 | 25 | - To install a chart 26 | 27 | ``` 28 | helm install kubernetes-dashboard/kubernetes-dashboard 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /Jenkins/Docker-setup/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jenkins/jenkins:2.375.1 2 | USER root 3 | RUN apt-get update && apt-get install -y lsb-release 4 | RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \ 5 | https://download.docker.com/linux/debian/gpg 6 | RUN echo "deb [arch=$(dpkg --print-architecture) \ 7 | signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \ 8 | https://download.docker.com/linux/debian \ 9 | $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list 10 | RUN apt-get update && apt-get install -y docker-ce-cli 11 | USER jenkins 12 | RUN jenkins-plugin-cli --plugins "blueocean:1.26.0 docker-workflow:563.vd5d2e5c4007f" -------------------------------------------------------------------------------- /Jenkins/Docker-setup/README.md: -------------------------------------------------------------------------------- 1 | ## Steps 2 | 3 | - https://www.jenkins.io/doc/book/installing/docker/ 4 | 5 | #### Create a network 6 | 7 | ``` 8 | docker network create jenkins 9 | ``` 10 | 11 | #### Install Docker in Docker 12 | 13 | ```sh 14 | docker run \ 15 | --name jenkins-docker \ 16 | --rm \ 17 | --detach \ 18 | --privileged \ 19 | --network jenkins \ 20 | --network-alias docker \ 21 | --env DOCKER_TLS_CERTDIR=/certs \ 22 | --volume jenkins-docker-certs:/certs/client \ 23 | --volume jenkins-data:/var/jenkins_home \ 24 | --publish 2376:2376 \ 25 | docker:dind \ 26 | --storage-driver overlay2 27 | ``` 28 | 29 | ### Create a custom Jenkins image with Dockerfile 30 | 31 | 32 | ```Dockerfile 33 | FROM jenkins/jenkins:2.375.1 34 | USER root 35 | RUN apt-get update && apt-get install -y lsb-release 36 | RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \ 37 | https://download.docker.com/linux/debian/gpg 38 | RUN echo "deb [arch=$(dpkg --print-architecture) \ 39 | signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \ 40 | https://download.docker.com/linux/debian \ 41 | $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list 42 | RUN apt-get update && apt-get install -y docker-ce-cli 43 | USER jenkins 44 | RUN jenkins-plugin-cli --plugins "blueocean:1.26.0 docker-workflow:563.vd5d2e5c4007f" 45 | ``` 46 | 47 | ### Build the image 48 | 49 | ```sh 50 | docker build -t myjenkins-blueocean:2.375.1-1 . 51 | ``` 52 | 53 | ### Run the image 54 | 55 | ```sh 56 | docker run \ 57 | --name jenkins-blueocean \ 58 | --restart=on-failure \ 59 | --detach \ 60 | --network jenkins \ 61 | --env DOCKER_HOST=tcp://docker:2376 \ 62 | --env DOCKER_CERT_PATH=/certs/client \ 63 | --env DOCKER_TLS_VERIFY=1 \ 64 | --publish 8080:8080 \ 65 | --publish 50000:50000 \ 66 | --volume jenkins-data:/var/jenkins_home \ 67 | --volume jenkins-docker-certs:/certs/client:ro \ 68 | myjenkins-blueocean:2.375.1-1 69 | ``` 70 | 71 | ### Get the initial password 72 | 73 | ```sh 74 | docker exec jenkins-blueocean cat /var/jenkins_home/secrets/initialAdminPassword 75 | ``` 76 | 77 | -------------------------------------------------------------------------------- /Jenkins/Docker-setup/dind.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker run \ 4 | --name jenkins-docker \ 5 | --detach \ 6 | --privileged \ 7 | --network jenkins \ 8 | --network-alias docker \ 9 | --env DOCKER_TLS_CERTDIR=/certs \ 10 | --volume jenkins-docker-certs:/certs/client \ 11 | --volume jenkins-data:/var/jenkins_home \ 12 | --publish 2376:2376 \ 13 | docker:dind \ 14 | --storage-driver overlay2 -------------------------------------------------------------------------------- /Jenkins/Docker-setup/jenkins.sh: -------------------------------------------------------------------------------- 1 | docker run \ 2 | --name jenkins-blueocean \ 3 | --restart=on-failure \ 4 | --detach \ 5 | --network jenkins \ 6 | --env DOCKER_HOST=tcp://docker:2376 \ 7 | --env DOCKER_CERT_PATH=/certs/client \ 8 | --env DOCKER_TLS_VERIFY=1 \ 9 | --publish 8080:8080 \ 10 | --publish 50000:50000 \ 11 | --volume jenkins-data:/var/jenkins_home \ 12 | --volume jenkins-docker-certs:/certs/client:ro \ 13 | myjenkins-blueocean:2.375.1-1 -------------------------------------------------------------------------------- /Jenkins/Jenkinsfile/Jenkinsfile: -------------------------------------------------------------------------------- 1 | def gv 2 | pipeline{ 3 | agent any 4 | stages{ 5 | stage('init Groovy Script'){ 6 | steps{ 7 | script{ 8 | gv = load 'script.groovy' 9 | } 10 | } 11 | } 12 | stage('Build'){ 13 | steps{ 14 | script{ 15 | gv.buildApp() 16 | } 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Jenkins/Jenkinsfile/Jenkinsfile-multistage: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | stages { 4 | stage('Build') { 5 | steps { 6 | sh 'docker build -t jenkins-docker .' 7 | } 8 | } 9 | stage('Test') { 10 | steps { 11 | sh 'docker run jenkins-docker' 12 | } 13 | } 14 | stage('Deploy') { 15 | steps { 16 | sh 'docker push jenkins-docker' 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Jenkins/Jenkinsfile/Jenkinsfile-para: -------------------------------------------------------------------------------- 1 | pipeline{ 2 | agent any 3 | parameters{ // Parameters are defined here 4 | booleanParam(name: 'executeTest', defaultValue: true, description: 'Execute Test?') 5 | } 6 | stages{ 7 | stage('Check'){ 8 | stage { 9 | expression(){ 10 | params.executeTest == true 11 | } 12 | } 13 | steps{ 14 | echo "Execute Test: ${params.executeTest}" // Accessing the parameters by params.{parameter_name} 15 | sh 'docker run jenkins-docker' 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Jenkins/Jenkinsfile/script.groovy: -------------------------------------------------------------------------------- 1 | def testApp() { 2 | sh 'echo "Test"' 3 | } 4 | def buildApp() { 5 | sh 'echo "Build"' 6 | } 7 | def deployApp() { 8 | sh 'echo "Deploy"' 9 | } 10 | 11 | return this 12 | -------------------------------------------------------------------------------- /Jenkins/README.md: -------------------------------------------------------------------------------- 1 | ## Jenkins 2 | 3 | Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. 4 | 5 | ### Resources 6 | 7 | - [official website](https://www.jenkins.io/) 8 | - [official documentation](https://www.jenkins.io/doc/) 9 | - [Jenkins Docker Image](https://hub.docker.com/r/jenkins/jenkins) 10 | - [Pipeline Syntax](https://www.jenkins.io/doc/book/pipeline/syntax/) 11 | 12 | #### Learning Resources 13 | 14 | - [Jenkins Docker Installation (docs)](https://www.jenkins.io/doc/book/installing/docker/) 15 | - [Jenkins Tutorial - TechWorld with Nana (video)](https://www.youtube.com/playlist?list=PLy7NrYWoggjw_LIiDK1LXdNN82uYuuuiC) 16 | - [Jenkins FreeCodeCamp (video)](https://youtu.be/f4idgaq2VqA) 17 | - [Jenkins Tutorial - Guru99 (video)](https://youtu.be/5XQOK0v_YRE) 18 | 19 | ## Jenkisfile - Pipeline as Code 20 | 21 | Insted of configuring the pipeline in the Jenkins UI, we can define the entire pipeline in a Jenkinsfile and check it into source control. The the file name is case sensitive and must be named `Jenkinsfile`. 22 | 23 | **This pipeline can be written in two ways:** 24 | 25 | ### Scripted Pipeline 26 | 27 | Scripted Pipeline is based on Groovy syntax. It is a general-purpose programming language with a syntax similar to Java, but with additional features that support common programming idioms. 28 | 29 | ```Jenkinsfile 30 | node { 31 | stage('Build') { 32 | sh 'npm install' 33 | echo 'Building..' 34 | } 35 | stage('Test') { 36 | echo 'Testing..' 37 | } 38 | stage('Deploy') { 39 | echo 'Deploying..' 40 | } 41 | } 42 | ``` 43 | 44 | ### Declarative Pipeline 45 | 46 | Declarative Pipeline is a new way of defining the entire pipeline using a simple and easy to understand structure. 47 | 48 | ```Jenkinsfile 49 | pipeline { 50 | agent any 51 | stages { 52 | stage('Build') { 53 | steps { 54 | sh npm install 55 | echo 'Building..' 56 | } 57 | } 58 | stage('Test') { 59 | steps { 60 | echo 'Testing..' 61 | } 62 | } 63 | stage('Deploy') { 64 | steps { 65 | echo 'Deploying..' 66 | } 67 | } 68 | } 69 | } 70 | ``` 71 | 72 | - **Pipeline**: The top-level directive that defines the entire pipeline. 73 | - **Agent**: The agent directive defines where the entire pipeline, or a specific stage, will execute in the Jenkins environment. 74 | - **Stages**: The stages directive defines the different stages in pipeline. 75 | - **Stage**: The stage directive defines a single stage in a pipeline. 76 | - **Steps**: The steps directive defines the steps to be executed in a stage. 77 | 78 | Post Step: 79 | 80 | The post section is used to define actions to be taken after the completion of the pipeline. It can be used to send notifications, sccess/failure messages, etc. 81 | 82 | ```Jenkinsfile 83 | stages{} 84 | post{ 85 | always { 86 | sh 'echo pipeline completed' 87 | } 88 | success { 89 | sh 'echo pipeline sucess' 90 | } 91 | failure { 92 | sh 'echo pipeline failed' 93 | } 94 | } 95 | ``` 96 | 97 | When: 98 | 99 | The when directive is used to control the flow of the pipeline based on the conditions. It can be used to skip stages, or entire pipelines, based on the conditions. 100 | 101 | ```Jenkinsfile 102 | when{ 103 | expression { BRANCH_NAME == 'main' } 104 | } 105 | ``` 106 | 107 | ``` 108 | stage('Building the image') { 109 | when{ 110 | expression { BRANCH_NAME == 'main' } 111 | } 112 | steps { 113 | sh 'docker build -t pradumnasaraf/devops:latest .' 114 | } 115 | } 116 | ``` 117 | 118 | ### Environment Variables and Credentials 119 | 120 | To check default environment variables in Jenkins, we can use the following URL: 121 | 122 | ``` 123 | http:///env-vars.html 124 | http://localhost:8080/env-vars.html 125 | ``` 126 | 127 | ### Buils Tools 128 | 129 | The tools directive is used to define the tools required for the pipeline. It can be used to define the JDK, Maven and Gradle tools. 130 | 131 | With the 1st approach we can directly use the tools and its commands in the pipeline. 132 | 133 | ```jenkinsfile 134 | tools { 135 | maven 'maven-3.6.3' 136 | jdk 'jdk-11' 137 | } 138 | ``` 139 | 140 | We can also follow wrapper approach to define the tools. 141 | 142 | ```jenkinsfile 143 | stage('Build') { 144 | steps { 145 | withMaven(maven: 'maven-3.6.3') { 146 | sh 'mvn clean install' 147 | } 148 | } 149 | } 150 | stage('Build') { 151 | steps { 152 | nodejs('node-12.18.3') { // nodejs is the name of the tool 153 | sh 'npm install' 154 | } 155 | } 156 | } 157 | ``` 158 | 159 | 160 | Note: The tools must be installed in Jenkins. To install the tools, go to `Manage Jenkins > Global Tool Configuration`. 161 | 162 | ### Parameters 163 | 164 | The parameters directive is used to define the parameters required for the pipeline. It can be used to define the parameters like string, boolean, choice, etc. we can check the parameters in the UI by clicking on the `Build with Parameters` button. 165 | 166 | ```jenkinsfile 167 | parameters { 168 | string(name: 'NAME', defaultValue: 'pradumnasaraf', description: 'Enter your name') 169 | booleanParam(name: 'DEBUG', defaultValue: true, description: 'Enable debug mode') 170 | choice(name: 'VERSION', choices: ['1.0', '2.0', '3.0'], description: 'Select version') 171 | } 172 | stage('Build') { 173 | steps { 174 | echo "Hello ${params.NAME}" //Accessing the parameters by params.{parameter_name} 175 | echo "Debug mode is ${params.DEBUG}" 176 | echo "Version is ${params.VERSION}" 177 | } 178 | } 179 | ``` 180 | 181 | Screenshot 2023-01-07 at 1 31 11 PM 182 | 183 | 184 | ### Triggers 185 | 186 | The triggers directive is used to define the triggers for the pipeline. Common way are, poll, github webhooks, etc. 187 | 188 | Screenshot 2023-01-08 at 12 40 23 AM 189 | 190 | 191 | 192 | #### Replay 193 | 194 | The replay option is used to re-run the pipeline. It is useful to test withou making/committing any changes to the code. 195 | 196 | Screenshot 2023-01-07 at 2 18 28 PM 197 | 198 | -------------------------------------------------------------------------------- /Kubernetes/README.md: -------------------------------------------------------------------------------- 1 | ## Kubernetes Learnings 2 | 3 | ## Playground (environment to test out Kubernetes) 4 | 5 | - [labs.play-with-k8s.com](https://labs.play-with-k8s.com/) 6 | - [killercoda.com/playgrounds](https://killercoda.com/playgrounds) 7 | 8 | ## Resources 9 | 10 | - [Docker Mastery: with Kubernetes +Swarm from a Docker Captain](https://www.udemy.com/course/docker-mastery/) Udemy course. 11 | - [BretFisher/udemy-docker-mastery](https://github.com/BretFisher/udemy-docker-mastery) GitHub repo. 12 | - Kubernetes official [docs](https://kubernetes.io/docs/home/) 13 | 14 | ## Tools arround k8s 15 | 16 | - [Validkube](https://validkube.com/) - Kubernetes Manifest file validator (check security, structure). 17 | - [Lens](https://k8slens.dev/) - Lens is the only IDE you need to manage Kubernetes clusters. It's free and open source. 18 | 19 | ## Kubernetes Components - architecture 20 | 21 | ![Kube-component](https://user-images.githubusercontent.com/51878265/197317939-d7e8ecbb-912c-4223-b64a-1c46cbac255f.png) 22 | 23 |
24 | Simpler Image 25 | 26 | 20200328170549 27 | 28 |
29 | 30 | ## Master Node 31 | 32 | - **API Server**: 33 | - **Etcd**: It stores the current state of the cluster. It's like a cluster brain. 34 | - **Scheduler**: Decide which worker node will be best to deploy the next pods, after examining the resources and other paras. It does not schedule it. 35 | - **Controller Manager**: Detect the current state of the cluster and keep the desired state of pods running. Follow requests when some things need to change/added to a worker node 36 | 37 | 38 | ## Worker Node 39 | 40 | - **Kubelet**: It is the entry point to the Kubernetes cluster. Help us communicate with different objects in the Cluster 41 | - **Kube Proxy**: Maintains network rules on the node, that allow network communication to your Pods from network sessions inside or outside of your cluster. 42 | - **Container Runtime** - Like Docker, ContainerD, etc. Which runs the container 43 | 44 | ## Imperative Vs Declarative 45 | 46 | - Imperative - When we give a command through CLI to run pod/deployment. For eg: `kubectl run nginx --image=nginx` 47 | 48 | - Declarative - Creating deployment through YAML file. 49 | 50 | ## Namespaces 51 | 52 | - Isolated environment, we can group resources separately like a database. Also, great for running different versions of the app. 53 | 54 | We can add namespace attribute in YAMl file to specify with one it belongs to 55 | 56 | ```yaml 57 | apiVersion: v1 58 | kind: ConfigMap 59 | metadata: 60 | name: mongodb-configmap 61 | namespace: my-namespace 62 | data: 63 | database_url: mongodb-service 64 | ``` 65 | 66 | We can create a namespace by 67 | 68 | ``` 69 | kubectl create namespace 70 | kubectl create namespace dev 71 | ``` 72 | 73 | ## Pod Lifecycle 74 | 75 | ![Pod-Lifecycle](https://user-images.githubusercontent.com/51878265/197347032-cb45f52d-bfae-4ce4-838c-4c3ba9b10fa3.PNG) 76 | 77 | 78 | ## Configuration files 79 | 80 | Generally, A K8s YAML config file contains 4 properties 81 | 82 | ```YAML 83 | apiVersion: # Which version of the API you are using 84 | kind: # What kind of object you are creating 85 | metadata: # Data about the object 86 | spec: # What you want the object to look like 87 | ``` 88 | 89 | #### Labels and selectors 90 | 91 | Labels are for identification 92 | 93 | ### Deployment 94 | 95 | ```yaml 96 | apiVersion: apps/v1 97 | kind: Deployment 98 | metadata: 99 | name: mongo-deployment 100 | labels: 101 | app: mongodb 102 | spec: 103 | replicas: 1 104 | selector: 105 | matchLabels: 106 | app: mongodb 107 | template: 108 | metadata: 109 | labels: 110 | app: mongodb 111 | spec: 112 | containers: 113 | - name: mongodb 114 | image: mongo 115 | ports: 116 | - containerPort: 27017 117 | env: 118 | - name: MONGO_INITDB_ROOT_USERNAME 119 | valueFrom: 120 | secretKeyRef: 121 | name: mongodb-secrets 122 | key: mongo-root-username 123 | - name: MONGO_INITDB_ROOT_PASSWORD 124 | valueFrom: 125 | secretKeyRef: 126 | name: mongodb-secrets 127 | key: mongo-root-password 128 | ``` 129 | 130 | ### Services 131 | 132 | Services are for internal communication of pods. It also helps give a pop static IP address. Contains routing rules. It also provide loadbalancing. 133 | 134 | #### Types of Services 135 | 136 | - **ClusterIP**: For inter communication of pods 137 | 138 | - **HeadLess**: It is a direct communication with a pod. No load blancing is required. So in this ClusterIp is none 139 | 140 | ```yaml 141 | spec: 142 | clusterIP: None 143 | ``` 144 | 145 | - **NodePort**: It allow external traffic to a fix port on each worker node. 146 | 147 | > By default and for convenience, the `targetPort` is set to the same value as the `port` field. 148 | 149 | ```yaml 150 | spec: 151 | type: NodePort 152 | ports: 153 | - port: 80 154 | targetPort: 80 155 | nodePort: 30007 # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767) 156 | ``` 157 | 158 | - **LoadBalancer**: Becomes accessile externally through cloud provider LoadBalancer. 159 | 160 | General service file. 161 | 162 | ```yaml 163 | apiVersion: v1 164 | kind: Service 165 | metadata: 166 | name: mongodb-service 167 | spec: 168 | selector: 169 | app: mongodb //Deployment app label 170 | ports: 171 | - protocol: TCP 172 | port: 27017 // Service Port 173 | targetPort: 27017 // Pod/Container Port 174 | ``` 175 | 176 | Multi-port service - In this we have to name the ports 177 | 178 | ```yaml 179 | ports: 180 | - name: mongogb 181 | protocol: TCP 182 | port: 27017 // Service Port 183 | targetPort: 27017 // Pod/Container Port 184 | - name: mongodb-exporter 185 | protocol: TCP 186 | port: 9216 187 | targetPort: 9216 188 | 189 | ``` 190 | 191 |

Screenshot 2022-11-28 at 2 15 57 PM

192 | 193 | - Port forwarding 194 | 195 | We can forward a port from a pod to our local machine 196 | 197 | ```bash 198 | kubectl port-forward : 199 | ``` 200 | 201 | or 202 | 203 | Note: In this case pod port is same as localhost port 204 | 205 | ```bash 206 | kubectl port-forward 207 | ``` 208 | 209 | ### Ingress 210 | 211 | It is use for an external trafic/request, which can be accessed by an URL instaed of `IP-PORT - 17.28.55.44.5:7800`. For that we need an ingress controller to make work of ingress. 212 | 213 | ![Ingress](https://user-images.githubusercontent.com/51878265/201585224-eca055af-eeb6-473c-bd96-33af9b5f6c55.png) 214 | 215 | ```yaml 216 | apiVersion: networking.k8s.io/v1 217 | kind: Ingress 218 | metadata: 219 | name: kubernetes-ingress 220 | namespace: kubernetes-dashboard 221 | spec: 222 | rules: 223 | - host: example.com 224 | http: 225 | paths: 226 | - pathType: Prefix 227 | path: "/" 228 | backend: 229 | service: 230 | name: kubernetes-dashboard 231 | port: 232 | number: 80 233 | 234 | ``` 235 | 236 | TLS 237 | 238 | Screenshot 2022-11-14 at 1 17 55 PM 239 | 240 | ### ConfigMap 241 | 242 | Use to store external configurations like database URLs. We put it in simple text format unlike [Secrets](#secrets) 243 | 244 | ```yaml 245 | apiVersion: v1 246 | kind: ConfigMap 247 | metadata: 248 | name: mongodb-configmap 249 | data: 250 | database_url: mongodb-service 251 | ``` 252 | 253 | ### Secrets 254 | 255 | We use secrets to pass environment variables inside the pods. 256 | 257 | ```yaml 258 | apiVersion: v1 259 | kind: Secret 260 | metadata: 261 | name: mongodb-secrets 262 | type: Opaque 263 | data: 264 | mongo-root-username: cHJhZHVtbmE= //pradumna 265 | mongo-root-password: c2FyYWYxMjM= //saraf123 266 | ``` 267 | 268 | > Note: the secret value should be `base64` encoded, like `cHJhZHVtbmE` 269 | 270 | ```bash 271 | echo -n "value" | base64 272 | ``` 273 | 274 | We can decode it by 275 | 276 | ```bash 277 | echo cHJhZHVtbmE | base64 --decode 278 | ``` 279 | 280 | ## StatefulSet 281 | 282 | - Any application that stores data to keep it state, like database. In this the name and endpoint stays same when the pods restarted. 283 | 284 | ## Secret and ConfigMap as volume 285 | 286 | We can mount Config and Secret as a volume 287 | 288 | **depployment.yaml** 289 | ```yaml 290 | apiVersion: apps/v1 291 | kind: Deployment 292 | metadata: 293 | name: mosquitto-deployment 294 | spec: 295 | replicas: 1 296 | selector: 297 | matchLabels: 298 | app: mosquitto 299 | template: 300 | metadata: 301 | labels: 302 | app: mosquitto 303 | spec: 304 | containers: 305 | - name: mosquitto 306 | image: eclipse-mosquitto:1.6.2 307 | ports: 308 | - containerPort: 1883 309 | volumeMounts: 310 | - name: mosquitto-config # Volume name which is defined below and need to mounted 311 | mountPath: /mosquitto/config 312 | 313 | volumes: # List of volumes to mount into the container's filesystem. 314 | - name: mosquitto-config # This is the name of the volume 315 | configMap: #This is type of volume 316 | name: mosquitto-config-file 317 | ``` 318 | 319 | **config.yaml** 320 | ```Yaml 321 | apiVersion: v1 322 | kind: ConfigMap 323 | metadata: 324 | name: mosquitto-config-file 325 | data: 326 | mosquitto.conf: | 327 | log_dest stdout 328 | log_type all 329 | log_timestamp_format %Y-%m-%dT%H:%M:%S 330 | listener 9001 331 | ``` 332 | 333 | ### Volume VS using it as a ENV. 334 | 335 | ![Env vs Volume mount](https://user-images.githubusercontent.com/51878265/202616618-c536bbd6-e221-4df9-b57d-8969dc1504a8.png) 336 | 337 | 338 | ## Persistent Volume 339 | 340 | First we create the Persistent Volume(PV) and then we claim it by creating Persistent Volume Claim (PVC). Then that claim is mounted to the pod. But when we use cloud provides we can claim the storage directly from the cloud provider. 341 | 342 | - Note: Persistent volume is indepent of the namespace, but Persistent Volume Claim is bound to a specfic. 343 | 344 | ## Cluster Config file 345 | 346 | All the Cluster info is stored in the file name `config` with the path: 347 | 348 | ```bash 349 | ~/.kube/config 350 | ``` 351 | 352 | ## Networking 353 | 354 | Container communication - The container inside a pod communicate via localhost shares the same networking namespace. To test it out, `Curl` the other conatiner by exec into the 1st container. 355 | 356 | Steps 357 | 358 | 1) Create a deploymeny with the config file below 359 | 360 | ```YAML 361 | apiVersion: apps/v1 362 | kind: Deployment 363 | metadata: 364 | name: myapp 365 | labels: 366 | app: myapp 367 | spec: 368 | selector: 369 | matchLabels: 370 | app: myapp 371 | template: 372 | metadata: 373 | labels: 374 | app: myapp 375 | spec: 376 | containers: 377 | - name: nginx 378 | image: nginx 379 | ports: 380 | - containerPort: 80 381 | - name: sidecar 382 | image: curlimages/curl 383 | command: ["bin/sh"] 384 | args: ["-c", "echo Hello from the sidecar container! && sleep 3600"] 385 | ``` 386 | 387 | 2) Get inside the `sidecar` conatiner in the pod myapp and access the terminal by: 388 | 389 | ```bash 390 | kubectl exec -it -c sidecar -- /bin/sh 391 | ``` 392 | 393 | 3) Curl the localhost with the respective port of other container. 394 | 395 | ```bash 396 | curl localhost:80 397 | ``` 398 | ## Updating Strategy 399 | 400 | Updating means chnaging the image of the pod. 401 | 402 | ### Rolling Update 403 | 404 | The pods are updated one by one, so the service is not down. But the new pods are created with the new image and then the old pods are deleted. 405 | 406 | ```yaml 407 | apiVersion: apps/v1 408 | kind: Deployment 409 | metadata: 410 | name: nginx-deployment 411 | spec: 412 | replicas: 5 413 | strategy: 414 | type: RollingUpdate 415 | rollingUpdate: 416 | maxSurge: 1 # 1 pod can be created above the desired number of pods. By default it is 25% 417 | maxUnavailable: 1 # 1 pod can be unavailable during the update. By default it is 25% 418 | selector: 419 | matchLabels: 420 | app: nginx-app 421 | template: 422 | metadata: 423 | labels: 424 | app: nginx-app 425 | spec: 426 | containers: 427 | - name: myapp 428 | image: nginx:1.23.2 429 | ports: 430 | - containerPort: 80 431 | ``` 432 | 433 | 434 | ### Recreate 435 | 436 | The pods are deleted and then new pods are created. So the service is down for a while. 437 | 438 | ```yaml 439 | apiVersion: apps/v1 440 | kind: Deployment 441 | metadata: 442 | name: nginx-deployment 443 | spec: 444 | replicas: 5 445 | strategy: 446 | type: Recreate # It will delete all the pods and then create new ones 447 | selector: 448 | matchLabels: 449 | app: nginx-app 450 | template: 451 | metadata: 452 | labels: 453 | app: nginx-app 454 | spec: 455 | containers: 456 | - name: myapp 457 | image: nginx:1.23.3 458 | ports: 459 | - containerPort: 80 460 | ``` 461 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/drupal-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: drupal-deployment 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: drupal-app 10 | template: 11 | metadata: 12 | labels: 13 | app: drupal-app 14 | spec: 15 | containers: 16 | - name: drupal 17 | image: drupal:9.4.5 18 | ports: 19 | - containerPort: 80 20 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/drupal-ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: drupal-ingress 5 | spec: 6 | rules: 7 | - host: test.com 8 | http: 9 | paths: 10 | - pathType: Prefix 11 | path: "/" 12 | backend: 13 | service: 14 | name: drupal-service 15 | port: 16 | number: 80 17 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/drupal-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: drupal-service 5 | spec: 6 | selector: 7 | app: drupal-app 8 | ports: 9 | - port: 80 10 | targetPort: 80 11 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/psql-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: postgres-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: postgres-app 9 | template: 10 | metadata: 11 | labels: 12 | app: postgres-app 13 | spec: 14 | containers: 15 | - name: postgres 16 | image: postgres:15.1 17 | ports: 18 | - containerPort: 5432 19 | env: 20 | - name: POSTGRES_USER 21 | valueFrom: 22 | secretKeyRef: 23 | name: postgres-secrets 24 | key: psql-username 25 | - name: POSTGRES_PASSWORD 26 | valueFrom: 27 | secretKeyRef: 28 | name: postgres-secrets 29 | key: psql-password 30 | volumeMounts: 31 | - name: postgres-persistent-storage 32 | mountPath: /var/lib/postgresql/data 33 | volumes: 34 | - name: postgres-persistent-storage 35 | persistentVolumeClaim: 36 | claimName: postgres-pvc 37 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/psql-secrets.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | metadata: 4 | name: postgres-secrets 5 | type: Opaque 6 | data: 7 | psql-username: dXNlcm5hbWU= 8 | psql-password: cGFzc3dvcmQ= 9 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/psql-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: postgres-service 5 | spec: 6 | selector: 7 | app: postgres-app 8 | ports: 9 | - port: 5432 10 | targetPort: 5432 11 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/psql-volume.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolume 3 | metadata: 4 | name: postgres-pv 5 | labels: 6 | type: local 7 | spec: 8 | capacity: 9 | storage: 1Gi 10 | storageClassName : manual 11 | volumeMode: Filesystem 12 | accessModes: 13 | - ReadWriteOnce 14 | hostPath: 15 | path: "/mnt/data/drupal-app/postgres-pv" 16 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Drupal-postgres/psql-volumeclaim.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolumeClaim 3 | metadata: 4 | name: postgres-pvc 5 | spec: 6 | resources: 7 | requests: 8 | storage: 1Gi 9 | storageClassName: manual 10 | volumeMode: Filesystem 11 | accessModes: 12 | - ReadWriteOnce 13 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Mongo/mongo-configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: mongodb-configmap 5 | data: 6 | database_url: mongodb-service 7 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Mongo/mongo-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: mongo-deployment 5 | labels: 6 | app: mongodb 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: mongodb 12 | template: 13 | metadata: 14 | labels: 15 | app: mongodb 16 | spec: 17 | containers: 18 | - name: mongodb 19 | image: mongo 20 | ports: 21 | - containerPort: 27017 22 | env: 23 | - name: MONGO_INITDB_ROOT_USERNAME 24 | valueFrom: 25 | secretKeyRef: 26 | name: mongodb-secrets 27 | key: mongo-root-username 28 | - name: MONGO_INITDB_ROOT_PASSWORD 29 | valueFrom: 30 | secretKeyRef: 31 | name: mongodb-secrets 32 | key: mongo-root-password 33 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Mongo/mongo-exp-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: mongo-express-deployment 5 | labels: 6 | app: mongo-express 7 | spec: 8 | selector: 9 | matchLabels: 10 | app: mongo-express 11 | template: 12 | metadata: 13 | labels: 14 | app: mongo-express 15 | spec: 16 | containers: 17 | - name: mongo-express 18 | image: mongo-express 19 | ports: 20 | - containerPort: 8001 21 | env: 22 | - name: ME_CONFIG_MONGODB_ADMINUSERNAME 23 | valueFrom: 24 | secretKeyRef: 25 | name: mongodb-secrets 26 | key: mongo-root-username 27 | - name: ME_CONFIG_MONGODB_ADMINPASSWORD 28 | valueFrom: 29 | secretKeyRef: 30 | name: mongodb-secrets 31 | key: mongo-root-password 32 | - name: ME_CONFIG_MONGODB_SERVER 33 | valueFrom: 34 | configMapKeyRef: 35 | name: mongodb-configmap 36 | key: database_url 37 | --- 38 | 39 | 40 | apiVersion: v1 41 | kind: Service 42 | metadata: 43 | name: mongo-express-service 44 | spec: 45 | selector: 46 | app: mongo-express 47 | type: LoadBalancer 48 | ports: 49 | - protocol: TCP 50 | port: 8081 51 | targetPort: 8081 52 | nodePort: 30000 53 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Mongo/mongo-secrets.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | metadata: 4 | name: mongodb-secrets 5 | type: Opaque 6 | data: 7 | mongo-root-username: cHJhZHVtbmE= 8 | mongo-root-password: c2FyYWYxMjM= 9 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Mongo/mongo-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: mongodb-service 5 | spec: 6 | selector: 7 | app: mongodb 8 | ports: 9 | - protocol: TCP 10 | port: 27017 11 | targetPort: 27017 12 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Nginx/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: nginx 9 | template: 10 | metadata: 11 | labels: 12 | app: nginx 13 | spec: 14 | containers: 15 | - name: nginx 16 | image: nginx:1.7.9 17 | ports: 18 | - containerPort: 80 19 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Nginx/ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: nginx-ingress 5 | spec: 6 | rules: 7 | - host: saraf.com 8 | http: 9 | paths: 10 | - pathType: Prefix 11 | path: "/" 12 | backend: 13 | service: 14 | name: nginx-service 15 | port: 16 | number: 80 17 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Complete-app-setup/Nginx/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | selector: 7 | app: nginx 8 | ports: 9 | - port: 80 10 | targetPort: 80 11 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Ingress/multiple-path.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: kubernetes-ingress 5 | namespace: kubernetes-dashboard 6 | spec: 7 | rules: 8 | - host: example.com # This is the domain name that you want to use for your website 9 | http: 10 | paths: 11 | - pathType: Prefix 12 | path: "/" 13 | backend: 14 | service: 15 | name: kubernetes-dashboard # This is the name of the service 16 | port: 17 | number: 80 # This is the port of the service 18 | # Have different paths for different services 19 | - pathType: Prefix 20 | path: "/app" 21 | backend: 22 | service: 23 | name: app-service 24 | port: 25 | number: 3000 26 | # Multiple most by creating subdomains 27 | - host: blog.example.com 28 | http: 29 | paths: 30 | - pathType: Prefix 31 | path: "/" 32 | backend: 33 | service: 34 | name: blog-service 35 | port: 36 | number: 8080 37 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Ingress/tls-ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: myingress 5 | labels: 6 | name: myingress 7 | spec: 8 | tls: 9 | - hosts: 10 | - example.com 11 | secretName: mysecret # This is the name of the secret that you created 12 | rules: 13 | - host: example.com 14 | http: 15 | paths: 16 | - pathType: Prefix 17 | path: "/" 18 | backend: 19 | service: 20 | name: 21 | port: 22 | number: 8080 23 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Multi-container-manifest/alpine.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: alpine-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: alpine 9 | template: 10 | metadata: 11 | labels: 12 | app: alpine 13 | spec: 14 | containers: 15 | - name: nginx 16 | image: nginx 17 | ports: 18 | - containerPort: 80 19 | - name: alpine 20 | image: alpine 21 | command: ["bin/sh"] 22 | args: ["-c", "echo Hello from the alpine container! && apk add curl && sleep 3600"] 23 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Multi-container-manifest/curlimage.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: myapp 9 | template: 10 | metadata: 11 | labels: 12 | app: myapp 13 | spec: 14 | containers: 15 | - name: nginx 16 | image: nginx 17 | ports: 18 | - containerPort: 80 19 | - name: sidecar 20 | image: curlimages/curl 21 | command: ["bin/sh"] 22 | args: ["-c", "echo Hello from the sidecar container! && sleep 3600"] 23 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Recreate-strategy/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | replicas: 5 7 | strategy: 8 | type: Recreate # It will delete all the pods and then create new ones 9 | selector: 10 | matchLabels: 11 | app: nginx-app 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx-app 16 | spec: 17 | containers: 18 | - name: myapp 19 | image: nginx:1.23.3 20 | ports: 21 | - containerPort: 80 22 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Rolling-update-strategy/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | replicas: 5 7 | strategy: 8 | type: RollingUpdate 9 | rollingUpdate: 10 | maxSurge: 1 # 1 pod can be created above the desired number of pods 11 | maxUnavailable: 1 # 1 pod can be unavailable during the update 12 | selector: 13 | matchLabels: 14 | app: nginx-app 15 | template: 16 | metadata: 17 | labels: 18 | app: nginx-app 19 | spec: 20 | containers: 21 | - name: myapp 22 | image: nginx:1.23.2 23 | ports: 24 | - containerPort: 80 25 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Secret + Config as volume/config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: mosquitto-config-file 5 | data: 6 | mosquitto.conf: | 7 | log_dest stdout 8 | log_type all 9 | log_timestamp_format %Y-%m-%dT%H:%M:%S 10 | listener 9001 11 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Secret + Config as volume/mosquitto.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: mosquitto-deployment 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: mosquitto 10 | template: 11 | metadata: 12 | labels: 13 | app: mosquitto 14 | spec: 15 | containers: 16 | - name: mosquitto 17 | image: eclipse-mosquitto:1.6.2 18 | ports: 19 | - containerPort: 1883 20 | volumeMounts: 21 | - name: mosquitto-config # Volume name which is defined below and need to mounted 22 | mountPath: /mosquitto/config 23 | # - name: mosquitto-secret 24 | # mountPath: /mosquitto/secret 25 | # readOnly: true 26 | volumes: # List of volumes to mount into the container's filesystem. 27 | - name: mosquitto-config # This is the name of the volume 28 | configMap: #This is type of volume 29 | name: mosquitto-config-file 30 | - name: mosquitto-secret 31 | secret: 32 | secretName: mosquitto-secret-file 33 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Secret + Config as volume/secret.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | metadata: 4 | name: mosquitto-secret-file 5 | type: Opaque 6 | data: 7 | secret.file: | 8 | aGV5IGFyZSB5b3UgY2FuIGRvIHRoaXM/ 9 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Volume/Nginx-app/nginx-volume.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolume 3 | metadata: 4 | name: nginx-pv 5 | labels: 6 | type: local 7 | spec: 8 | capacity: 9 | storage: 500Mi 10 | storageClassName: manual 11 | volumeMode: Filesystem 12 | accessModes: 13 | - ReadWriteOnce 14 | hostPath: 15 | path: "/mnt/data" 16 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Volume/Nginx-app/nginx-volumeclaim.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolumeClaim 3 | metadata: 4 | name: nginx-pvc 5 | spec: 6 | resources: 7 | requests: 8 | storage: 500Mi 9 | storageClassName: manual 10 | volumeMode: Filesystem 11 | accessModes: 12 | - ReadWriteOnce 13 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Volume/Nginx-app/nginx.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: nginx-app 10 | template: 11 | metadata: 12 | labels: 13 | app: nginx-app 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx:1.21.3 18 | ports: 19 | - containerPort: 80 20 | volumeMounts: 21 | - name: nginx-persistent-storage 22 | mountPath: /usr/share/nginx/html 23 | volumes: 24 | - name: nginx-persistent-storage 25 | persistentVolumeClaim: 26 | claimName: nginx-pvc 27 | -------------------------------------------------------------------------------- /Kubernetes/YAML/Volume/nginx-local.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: nginx-app 9 | template: 10 | metadata: 11 | labels: 12 | app: nginx-app 13 | spec: 14 | containers: 15 | - name: nginx 16 | image: nginx:1.21.3 17 | ports: 18 | - containerPort: 80 19 | volumeMounts: 20 | - name: local-storage 21 | mountPath: /usr/share/nginx/html 22 | volumes: 23 | - name: local-storage 24 | hostPath: 25 | path: /var/nginxserver 26 | 27 | -------------------------------------------------------------------------------- /Kubernetes/YAML/canray/deploy1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment-yellow 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | app: nginx-app 10 | template: 11 | metadata: 12 | labels: 13 | app: nginx-app 14 | spec: 15 | containers: 16 | - name: nginx-yellow 17 | image: pradumnasaraf/nginx:yellow 18 | ports: 19 | - containerPort: 80 20 | -------------------------------------------------------------------------------- /Kubernetes/YAML/canray/deploy2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment-red 5 | spec: 6 | replicas: 8 7 | selector: 8 | matchLabels: 9 | app: nginx-app 10 | template: 11 | metadata: 12 | labels: 13 | app: nginx-app 14 | spec: 15 | containers: 16 | - name: nginx-red 17 | image: pradumnasaraf/nginx:red 18 | ports: 19 | - containerPort: 80 20 | -------------------------------------------------------------------------------- /Kubernetes/YAML/canray/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | selector: 7 | app: nginx-app 8 | ports: 9 | - port: 80 10 | targetPort: 80 11 | -------------------------------------------------------------------------------- /Kubernetes/commands/README.md: -------------------------------------------------------------------------------- 1 | > KUBECTL COMMANDS 2 | 3 | - To check the version: 4 | 5 | ```bash 6 | kubectl version 7 | kubectl version --output=yaml 8 | ``` 9 | 10 | - To check info about the cluster 11 | 12 | ```bash 13 | kubectl config view 14 | ``` 15 | 16 | - To run a Pod 17 | 18 | ```bash 19 | kubectl run --image 20 | kubectl run myngix --image nginx 21 | ``` 22 | 23 | - To create a deployment 24 | 25 | ```bash 26 | kubectl create deployment --image 27 | kubectl create deployment mynginx --image nginx 28 | ``` 29 | 30 | - To sacle the deployment (increase replicas) 31 | 32 | ``` 33 | kubectl scale deployment --replicas 34 | kubectl scale deployment mynginx --replicas 2 35 | ``` 36 | 37 | - To check all running services, pods, etc. 38 | 39 | ```bash 40 | kubectl get all 41 | ``` 42 | 43 | - To get the get details from the a particular namespace 44 | 45 | ```bash 46 | kubectl get all -n 47 | ``` 48 | 49 | - To get the internal components running 50 | 51 | ```bash 52 | kubectl get pods -A 53 | kubectl get pods -A -owide 54 | ``` 55 | 56 | - To check all the running services 57 | 58 | ```bash 59 | kubectl get services 60 | ``` 61 | 62 | - To check all the running pods 63 | 64 | ```bash 65 | kubectl get pods 66 | ``` 67 | 68 | ```bash 69 | // with extra details 70 | kubectl get pods -o wide 71 | ``` 72 | 73 | - To check all the running node. 74 | 75 | ```bash 76 | kubectl get nodes 77 | ``` 78 | 79 | - To check all the replicaset 80 | 81 | ```bash 82 | kubectl get replicaset 83 | ``` 84 | 85 | - To check all the namespaces 86 | 87 | ```bash 88 | kubectl get namespaces 89 | ``` 90 | 91 | - To get all the API resources 92 | 93 | ``` 94 | kubectl api-resources 95 | ``` 96 | 97 | - To delete the deployment 98 | 99 | ```bash 100 | kubectl delete deployment 101 | ``` 102 | 103 | - To delete the pods 104 | 105 | ```bash 106 | kubectl delete pod 107 | ``` 108 | 109 | - To get logs of a pod 110 | 111 | ```bash 112 | kubectl logs 113 | ``` 114 | 115 | - To check logs or sh/bash of a container inside a pod. That if pods have multiple container an we have enter inside a container 116 | 117 | ```bash 118 | kube exec -it -c -- 119 | kube exec -it multi-container -c nginx-container -- curl localhost 120 | kube exec -it multi-container -c nginx-container -- sh 121 | kubectl logs multi-container -c nginx-container 122 | ``` 123 | 124 | - To get inside the pod 125 | 126 | ``` 127 | kubectl exec -it -- sh 128 | kubectl exec -it nginx -- sh 129 | ``` 130 | 131 | - Get a deep details/state chnages about a pod 132 | 133 | ```bash 134 | kube describe pod 135 | ``` 136 | 137 | - To watch the pods (watch refresh every few seconds) 138 | ```bash 139 | kubectl get pods -w 140 | ``` 141 | 142 | - To check the cluster are avilable 143 | 144 | ``` 145 | kube config get-contexts 146 | ``` 147 | 148 | - We can create namespace by 149 | 150 | ```bash 151 | kubectl create namespace 152 | kubectl create namespace dev 153 | ``` 154 | 155 | - To do a dry nun and get the output as Yaml 156 | 157 | ```bash 158 | kubectl create namespace test-name --dry-run=client -oyaml 159 | ``` 160 | 161 | - To edit the deployment (deployment file) 162 | 163 | ```bash 164 | kubectl edit deployment 165 | ``` 166 | 167 | - To delete all the pods 168 | ``` 169 | kubectl delete pods --all 170 | ``` 171 | 172 | - Apply to a particular namespace 173 | 174 | ```bash 175 | kubectl apply -f --namespace= 176 | ``` 177 | 178 | ## Persistent Volume 179 | 180 | - Get all the PersistentVolume 181 | 182 | ```bash 183 | kubectl get pv 184 | ``` 185 | 186 | - Get all the PersistentVolumeClaim (tied to a namespace) 187 | 188 | ```bash 189 | kubectl get pvc 190 | ``` 191 | 192 | - To chnage default/active namespace 193 | 194 | ```bash 195 | kubectl config set-context --current --namespace= 196 | ``` 197 | 198 | - To get the details of a particular namespace 199 | 200 | ```bash 201 | kubectl get all -n 202 | ``` -------------------------------------------------------------------------------- /Kubescape/README.md: -------------------------------------------------------------------------------- 1 | ## Kubescape 2 | 3 | Kubescape is a tool that helps you scan your Kubernetes clusters for security misconfigurations. We can scan local cluster and config files. 4 | 5 | - [Website](https://armosec.io/kubescape) 6 | - [Docs](https://hub.armosec.io/docs) 7 | - [GitHub](https://github.com/kubescape/kubescape) 8 | 9 | 10 | ### Usage 11 | 12 | For more usages head over to [GitHub](https://github.com/kubescape/kubescape) 13 | 14 | - Install Kubescape 15 | 16 | Installations instructions can be found [here](https://github.com/kubescape/kubescape#install-on-macos) 17 | 18 | - To scan local YAML/JSON files. 19 | 20 | ```bash 21 | kubescape scan *.yaml 22 | ``` 23 | 24 | - To Scan Kubernetes manifest files from a git repository 25 | 26 | ```bash 27 | kubescape scan https://github.com/kubescape/kubescape 28 | ``` 29 | 30 | - We can output the results in JSON, html, and markdown PDF. 31 | 32 | ```bash 33 | kubescape scan *.yaml --output results.json 34 | kubescape scan *.yaml --output results.pdf 35 | kubescape scan *.yaml --output results.html 36 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Lens/README.md: -------------------------------------------------------------------------------- 1 | ## Lens IDE 2 | 3 | It can be used to manage multiple Kubernetes cluster. 4 | 5 | ### Installation 6 | 7 | - Download the Lens from [here](https://k8slens.dev/). 8 | 9 | Screenshot 2022-12-17 at 7 20 59 PM 10 | -------------------------------------------------------------------------------- /Linux/README.md: -------------------------------------------------------------------------------- 1 | ## Concepts 2 | Linux is an operating system like windows and macOS. It is the most popular open source operating system and powers the vast majority of servers that compose the internet. 3 | 4 | Current linux systems contain graphical tools made specifically for an administrator. However, being able to use the interface in the command line mode is crucial for a number of reasons: 5 | 6 | * Administration is done by scripts. 7 | * Aduiting and Debugging is much easier as you can easily look through the logs to track every single action you performed. 8 | * Remote administration is done on the command line with an SSH terminal. 9 | * It providers more flexibility than GUIs (Graphical user interface). 10 | 11 | Thus, learning these commands allows you to connect to a linux terminal and manage resources and file. 12 | 13 | -------------------------------------------------------------------------------- /Linux/commands/README.md: -------------------------------------------------------------------------------- 1 | - `whereis` - Find the path of that executable file. 2 | 3 | ### List operation 4 | - `ls` - Shows list. 5 | - `-a` - Hidden file. 6 | - `-l` - Permission. 7 | - `-R` - Show sub dir. 8 | 9 | ### Changing dir operation 10 | - `cd ` - Change Dir. 11 | - `cd ..` - Go one Directory back. 12 | - `cd` - Go to home. 13 | - `cd ../` - Open a previous dir folder. 14 | - `cd ` - Open a dir with the path. 15 | 16 | ### File/Folder Ope. 17 | - `mkdir ` - Create a new folder. 18 | - `mkdir -p test/test1/test2` - Create a dir between two directories. 19 | - `touch ` - create a blank file. 20 | - `pwd` - Present working directory. 21 | - `cat ` - Display file content. 22 | - `cat > ` - Create a file. 23 | - `dd if=/dev/zero of=bos_dosya bs=4G count=1`- create empty file with zeros 24 | - `cat >> ` - Append the file 25 | - `cat >> ` - Append the content of the file filename1 at the end of the file . 26 | - `cat ` - Display 2 files at a time. 27 | - `cat > ` - Merge both of file content in a single one. 28 | - `cat | tr > ` - Translate the file. 29 | - `cut -c 1-2 ` - cut the file column wise 30 | - `echo "Hello" >> ` 31 | - `man ` - Know about the command usages and options. 32 | - `man ` - know about the command. 33 | 34 | ### File/Folder operation 35 | - `cp ` - Make a copy of a file in the current location. 36 | - `mv ` - Move a file from one dir to another. 37 | - `mv ` - Rename a file. 38 | - `mv -R ` - Move Dir 39 | - `rm ` - Remove a file permanently. 40 | - `rm -R ` - Delete a folder with dir included. 41 | - `head ` - Will display first 10 lines of a file. 42 | - `tail ` - Will display last 10 lines of a file. 43 | -`-n 2` - will display last 2 lines. 44 | - `diff ` - Show diff between the two files. 45 | - `locate ` - To find out the file. 46 | - `find ` - Find a file/folder. 47 | - `find ` - Find files inside the dir 48 | - `find .-type d` - Show only dir. 49 | - `.-type f` - show only files. 50 | - `.-type f -name "*.txt"` - Show only files with that specific name. 51 | - `.-type f -iname "*.txt"` - Show only files with that specific name - not case sensitive (i) 52 | - `.-type f -mmin -20` - Show files which modify less than 20 min ago. 53 | - `.-type f -mmin +20` - show files which modify more than 20 min ago. 54 | - `.-type f -maxdepth 2` - Will only show 1 folder deep. 55 | - `.-size +1k` - will only show file/folder with size of 1kb 56 | 57 | 58 | ### System commands 59 | - `ps aux` - processes which are running 60 | - `df` - Check the capacity and storage details. 61 | - `m` - In megabyte or 62 | - `hg` - In gigabyte. 63 | - `du` - Disk usages capcity 64 | - `-h` (human readable) 65 | - `echo` - Get a output of a string 66 | - `echo $PATH` - Check the path variable 67 | - `sudo` - Admin command 68 | - `sudo chown root text.txt` - change owner 69 | - `!` - Run the previous command 70 | - `git add .; git commit -m "message"` - Run multiple commands at a time 71 | - `sort "` - sort the file 72 | - `job` - show the jobs 73 | - `wget ` - download the file from the URL 74 | - `top` - what processes are running 75 | - `kill ` -stop that process 76 | - `Uname` - show the system info 77 | - `zip ` - Zip Two or more files 78 | - `Unzip ` - Unzip files 79 | - `useradd ` - add a user 80 | - `passwd ` - set a password for the user 81 | - `uname -` -o -m -r 82 | - `lscpu` - get cpu details 83 | - `free` - free memory 84 | - `vmstat` - virtual memory 85 | - `lsof` - list all the open file 86 | - `xdg-open ` - open the folder (graphical window) of a file/folder with path. 87 | - `xdg-open .` - open the folder of the current directory. 88 | - `vi ~/.bashrc` - set your Alias 89 | - `echo -n 'username' | base64` - encode the username to base64 90 | - `echo -n 'encoded' | base64 -d` - decode the username to base64 91 | 92 | ### Networking 93 | - `nslookup google.com` - To check the IP address of the domain. 94 | - `netstat` - To check the network status. 95 | - `hostname` - To check the hostname. 96 | - `whoami` - To check the current user. 97 | - `ping google.com` - To check the connectivity. 98 | 99 | 100 | ### Permissions 101 | - `chmod u=rwx,g=rxw,o=rwx ` READ, WRITE AND EXECUTE 102 | - `chmod 777 ` - 4- Read, 2- Write, 1 - Execute 103 | - `find . -perm 777 ` - shows files with all permissions(rwx) 104 | - `grep ` - To search if the keyword is presnt in the file or not 105 | - `grep -w ` - To search if the keyword is present in the file or not (complete word) 106 | - `grep -i ` - To search if the keyword is present in the file or not (not case sens) 107 | - `grep -n ` - To search if the keyword is present in the file or not (Line number) 108 | - `grep -B ` - Show Line before that keyword 109 | - `grep -win ./*.txt` - To search if the keyword is present in the file in current dir 110 | - `grep -win -r .*` 111 | - `history | grep "ls -l"` - Piping, we filter out the things 112 | 113 | ``` 114 | history 115 | ! 116 | ``` 117 | 118 | # Operators 119 | 120 | - `ping google.com & pingfacebook.com` - run both the commands at the same time 121 | - `echo "google.com" && echo "facebook.com"` - second will only run if first is successful 122 | - `echo "google.com" && {echo "facebook.com"; eco "pradumnasaraf.co"}` 123 | - `echo "google.com" || echo "pingfacebook.com"` - second will only run if first is not successful 124 | - `rm -r !(file.txt)` - delete all files except file.txt 125 | - `printevnv` - to print all th env. 126 | -------------------------------------------------------------------------------- /Networking/README.md: -------------------------------------------------------------------------------- 1 | ## OSI Layer 2 | 3 |

OSI

4 | 5 | ## TCP 6 | 7 | TCP is a connection-oriented protocol. This means that it first establishes a link between the source and destination before it sends data. CP is a preferred protocol when data integrity is critical, such as in any transactional system. Eg: email and file transfer 8 | 9 | ## UDP 10 | 11 | UDP in turn is not connection-oriented. UDP starts transmitting data immediately, without waiting for connection confirmation from the receiving side. Even though some data loss can happen, UDP is most often used in cases where speed is more important than perfect transmissions, such as in voice or video streaming. 12 | 13 | 14 | ## Ports 15 | 16 | A virtual point where network connections start and end. So that multiple applications can communicate easily. 17 | 18 |

Tcp port

19 | 20 | 21 | |Port Number| Process | Uses | 22 | |:--:|:--:|:--:| 23 | |80 | HTTP | | 24 | |443| HTTPs| | 25 | |3306| MySQl | | 26 | 27 | To check which ports the system are using 28 | 29 | ```bash 30 | netstat -a -b 31 | ``` 32 | 33 | ## URL (Uniform Resource Locator) 34 | 35 | A unique identifier is used to locate a resource on the Internet. Lilke HTML, JS files. 36 | 37 | ### URL Breakdown 38 | 39 |

40 | 41 | - Generally, the URL dosen't contains a port number in the string because it is by default. For eg, `google.com` or `google.com:443` 42 | 43 | 44 | ## IP Address 45 | 46 |

IP Address

47 | 48 | 49 | ### IP Address classes 50 | 51 | 52 |

IP Address classes

53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Networking/commands/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### Ping 3 | 4 | Ping is a command that is used to test the connectivity between two devices. It sends ICMP echo requests to the target device and waits for ICMP echo replies. If the target device replies, it means that the connection is working. 5 | 6 | ```bash 7 | ping google.com 8 | ``` 9 | 10 | ### Traceroute 11 | 12 | Traceroute is a command that is used to find the path taken by the packets to reach the target device. It sends ICMP echo requests to the target device and waits for ICMP time exceeded messages. If the target device replies, it means that the connection is working. 13 | 14 | ```bash 15 | traceroute google.com 16 | ``` 17 | 18 | ### Nslookup 19 | 20 | Nslookup is a command that is used to find the IP address of a domain name. It sends a DNS query to the DNS server and waits for a response. 21 | 22 | ```bash 23 | nslookup google.com 24 | ``` 25 | 26 | ### Netstat 27 | 28 | Netstat is a command that is used to display the network connections and routing tables. It can be used to find the open ports on a device. 29 | 30 | ```bash 31 | netstat -tulpn 32 | ``` 33 | 34 | ### Hostname 35 | 36 | Hostname is a command that is used to display the name of the current host. 37 | 38 | ```bash 39 | hostname 40 | ``` 41 | 42 | -------------------------------------------------------------------------------- /Portainer/README.md: -------------------------------------------------------------------------------- 1 | ### Resources 2 | 3 | - [Portainer](https://www.portainer.io/) 4 | - [Portainer Documentation](https://documentation.portainer.io/) 5 | - [Portainer GitHub](https://github.com/portainer/portainer) 6 | 7 | ### Installation 8 | 9 | Via Helm 10 | 11 | - Create a namespace for portainer 12 | 13 | ```bash 14 | kubectl create namespace portainer 15 | ``` 16 | 17 | - Add the portainer helm repository 18 | 19 | ```bash 20 | helm repo add portainer https://portainer.github.io/k8s 21 | ``` 22 | 23 | - Install the portainer helm chart 24 | 25 | ```bash 26 | helm update 27 | helm install -n portainer portainer portainer/portainer 28 | ``` 29 | 30 | > To install the business edition, use the following command 31 | 32 | ```bash 33 | helm install --create-namespace -n portainer portainer portainer/portainer \ 34 | --set enterpriseEdition.enabled=true \ 35 | --set tls.force=true 36 | ``` 37 | 38 | - To access the portainer dashboard, run the following command 39 | 40 | ```bash 41 | kubectl -n portainer port-forward svc/portainer 9000:9000 42 | ``` 43 | 44 | Dashboard will be available at http://localhost:9000. Preview 45 | 46 | - For business edition, follow this [guide](https://install.portainer.io/). -------------------------------------------------------------------------------- /Prometheus/README.md: -------------------------------------------------------------------------------- 1 | Monitoring tool for Kubernetes 2 | 3 | ## Installation using Helm 4 | 5 | It is collection of Promethus + Grafana + Alertmanager + Node Exporter + Kube State Metrics + Pushgateway + Blackbox Exporter 6 | 7 | 8 | Step 1: Create a Kubernetes Namespace 9 | 10 | ```bash 11 | kubectl create namespace monitoring 12 | ``` 13 | Step 2: Install Prometheus Operator 14 | 15 | ```bash 16 | helm repo add prometheus-community https://prometheus-community.github.io/helm-charts 17 | helm repo update 18 | helm install prometheus prometheus-community/kube-prometheus-stack -n monitoring 19 | ``` 20 | Step 3: Accessing though localhost by Port forwarding 21 | 22 | ```bash 23 | kubectl port-forward svc/prometheus-grafana 3000:80 -n monitoring 24 | ``` 25 | 26 | > The Grafana dashboard will be available at http://localhost:3000. The default username and password are `admin` $ `prom-operator`. 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

DevOps

2 | 3 |

Contains all my learning related to DevOps tools and tech.

4 | 5 | ## Kubernetes 6 | 7 | Kubernetes 8 | 9 | - [Notes](Kubernetes/README.md) 10 | - [Commands](Kubernetes/commands/README.md) 11 | - [Manifest Files](https://github.com/Pradumnasaraf/DevOps/tree/main/Kubernetes/YAML) 12 | 13 |
14 | 15 | ## Docker 16 | 17 | docker 18 | 19 | - [Notes](Docker/README.md) 20 | - [Commands](Docker/commands/README.md) 21 | - [Compose/Stack Files](https://github.com/Pradumnasaraf/DevOps/tree/main/Docker/YAML) 22 | - [Dockerfile](https://github.com/Pradumnasaraf/DevOps/tree/main/Docker/Dockerfile) 23 | 24 |
25 | 26 | ## GitHub Actions 27 | 28 | GitHub Action 29 | 30 | - [Notes](GitHub-Actions/README.md) 31 | - [Workflows](https://github.com/Pradumnasaraf/DevOps/tree/main/GitHub-Actions/Workflows) 32 | 33 |
34 | 35 | ## Networking 36 | 37 | network 38 | 39 | - [Notes](Networking/README.md) 40 | - [Commands](Networking/commands/README.md) 41 | 42 |
43 | 44 | ## Linux 45 | 46 | linux 47 | 48 | - [Notes](Linux/README.md) 49 | - [Commands](Linux/commands/README.md) 50 | 51 |
52 | 53 | ## Git 54 | 55 | git 56 | 57 | - [Notes](Git/README.md) 58 | - [Commands](Git/commands/README.md) 59 | 60 |
61 | 62 | ## YAML 63 | 64 | YAML 65 | 66 | - [Notes](YAML/README.md) 67 | - [Syntax](YAML/syntax/README.md) 68 | 69 |
70 | 71 | ## Helm 72 | 73 | Helm 74 | 75 | - [Notes](Helm/README.md) 76 | 77 |
78 | 79 | ## Prometheus 80 | 81 | Prometheus 82 | 83 | - [Notes](Prometheus/README.md) 84 | 85 |
86 | 87 | ## GitOps 88 | 89 | Gitops 90 | 91 | - [Notes](GitOps/README.md) 92 | 93 |
94 | 95 | ## ArgoCD 96 | 97 | Argo 98 | 99 | - [Notes](ArgoCD/README.md) 100 | - [Manifest Files](https://github.com/Pradumnasaraf/DevOps/tree/main/ArgoCD/YAML) 101 | 102 |
103 | 104 | ## Portainer 105 | 106 | portainer 107 | 108 | - [Notes](Portainer/README.md) 109 | 110 |
111 | 112 | ## Jenkins 113 | 114 | Jenkins 115 | 116 | - [Notes](Jenkins/README.md) 117 | - [Jenkinsfile](https://github.com/Pradumnasaraf/DevOps/tree/main/Jenkins/Jenkinsfile) 118 | 119 |
120 | 121 | ## Bash Scripting 122 | 123 | Bash 124 | 125 | - [Notes](Bash-Scripting/README.md) 126 | - [Script](https://github.com/Pradumnasaraf/DevOps/tree/main/Bash-Scripting/Scripts) 127 | 128 |
129 | 130 | ## Lens IDE 131 | 132 | Lens 133 | 134 | - [Notes](Lens/README.md) 135 | 136 |
137 | 138 | ## Kubescape 139 | 140 | Kubescape 141 | 142 | - [Notes](Kubescape/README.md) 143 | 144 |
145 | 146 | ## ValidKube 147 | 148 | ValidKube 149 | 150 | - [Notes](Validkube/README.md) 151 | 152 |
153 | 154 | 160 | -------------------------------------------------------------------------------- /Validkube/README.md: -------------------------------------------------------------------------------- 1 | ## ValidKube 2 | 3 | - Website - [validkube.com](https://validkube.com/) 4 | 5 | - It is a tool to validate the Kubernetes YAML files to find vulnerabilities, security issues, and best practices. 6 | 7 | Screenshot 2022-12-17 at 7 18 25 PM 8 | 9 | -------------------------------------------------------------------------------- /YAML/README.md: -------------------------------------------------------------------------------- 1 | ## YAML - YAML Ain't Markup Langugae 2 | 3 | - Data format used to exchnage data. 4 | - Similar to XML & JSON. 5 | - We can't add commands. 6 | - Simple and easy to read. 7 | - Strict syntax - (Indentation) 8 | - More powerful to represent complex data. 9 | - Parsing is easy 10 | 11 | 12 | ## Usage 13 | 14 | - Use in config files (Docker/Kubernetes) 15 | - used Logs, cache, etc 16 | 17 | #### YAML tools 18 | [yamllint](http://www.yamllint.com/) - Check the the format of the file -------------------------------------------------------------------------------- /YAML/syntax/README.md: -------------------------------------------------------------------------------- 1 | ### Key Value pair 2 | 3 | ```yaml 4 | Name: "Pradumna Saraf" 5 | 1: "This a list" 6 | ``` 7 | 8 | ### List 9 | 10 | ```yaml 11 | - apple 12 | - mango 13 | - Banana 14 | - banana 15 | ``` 16 | or 17 | 18 | ```yaml 19 | cities: [new delhi, patna,gujrat] 20 | ``` 21 | 22 | ### String and Variables 23 | 24 | ```yaml 25 | name: Pradumna Saraf 26 | fruit: "Mango" 27 | job: 'Advocate' 28 | age: 65 29 | marks: 10.33 30 | booleanValue: No, N, fasle, Fasle, FALSE 31 | ``` 32 | 33 | ### Multiline String 34 | 35 | ```yaml 36 | Address: | 37 | 01 38 | Delhi 39 | India 40 | ``` 41 | Single line in multiple line. 42 | 43 | ```yaml 44 | message: > 45 | This all 46 | will be in a single 47 | line 48 | 49 | ``` 50 | 51 | ### Nested Mapping 52 | 53 | ```yaml 54 | names: Pradumna 55 | role: 56 | age: 22 57 | job: student 58 | ``` 59 | 60 | ### Nested Sequence 61 | 62 | ```yaml 63 | - 64 | - mango 65 | - apple 66 | - banana 67 | - 68 | - marks 69 | - roll 70 | ``` 71 | 72 | ##### Specify the data type 73 | 74 | ```yaml 75 | 76 | # Integer 77 | Zero: !!int 0 78 | postiveNumber: !!int 45 79 | negativeNumber: !!int -45 80 | hexa: !!int 0x45 81 | 82 | # Float 83 | mark: !!float 56.55 84 | infinity: !!float .inf 85 | not a num: .nan 86 | itNot: !!bool false 87 | 88 | # String 89 | string: !!str "hello" 90 | 91 | # Null 92 | surnmae: !!null #null or NULL ~ 93 | ~: this a null key 94 | 95 | # Exponential Numbers 96 | myNum: 6.22ES56 97 | 98 | # Dates and time 99 | date: !!timestamp 2002-01-02 100 | no Time zone: 2012-12-15T02:59:43 101 | India Time: 2012-12-15T02:59:43 +5:30 102 | ``` 103 | -------------------------------------------------------------------------------- /docker-compose.dev.yaml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | devops-website: 5 | volumes: 6 | - ./:/usr/share/nginx/html:ro 7 | 8 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | devops-website: 5 | container_name: website 6 | build: 7 | context: . 8 | dockerfile: Dockerfile 9 | ports: 10 | - 8000:80 11 | -------------------------------------------------------------------------------- /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ayush7614/DevOps/34db69d7f13e2302d6b16f348232630219504a4c/favicon.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DevOps 6 | 7 | 8 | 9 | 13 | 19 | 20 | 21 |
22 | 49 | 50 | 51 | 52 | 53 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /releases.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.3.2" 3 | } --------------------------------------------------------------------------------