├── terraform ├── 09-appgateway │ ├── aws.tf │ ├── azure.tf │ └── gcp.tf ├── 12-staticIpAddress │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 02-storageaccount │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 10-queues │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 01-virtualmachine │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 07-nosqldb │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 05-functionapp │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 13-nsg │ ├── gcp.tf │ ├── aws.tf │ └── azure.tf ├── 08-mysql │ ├── gcp.tf │ ├── aws.tf │ └── azure.tf ├── 16-KubernetesCluster │ ├── azure-aks.tf │ ├── gcp.tf │ ├── aws-eks.tf │ ├── aws.tf │ └── azure.tf ├── 04-virtualnetwork │ ├── azure.tf │ ├── aws.tf │ └── gcp.tf ├── 03-postgress │ ├── aws.tf │ ├── azure.tf │ └── gcp.tf ├── 14-RouteTraffic │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 15-CDN │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── 06-Webapp │ ├── gcp.tf │ ├── aws.tf │ └── azure.tf └── 11-loadbalancer │ ├── aws.tf │ ├── gcp.tf │ └── azure.tf ├── docker ├── 10-Kotlin and Redis │ └── compose.yml ├── 01-NodeJsMongoDB │ └── compose.yml ├── 15-Ruby and Redis │ └── compose.yml ├── 02-PythonFlaskandRedis │ └── compose.yml ├── 11-Swift and MongoDB │ └── compose.yml ├── 09-Scala and Cassandra │ └── compose.yml ├── 21-Python Flask and MongoDB │ └── compose.yml ├── 18-Go and RabbitMQ │ └── compose.yml ├── 06-Django and SQLite │ └── compose.yml ├── 07-Rust and MySQL │ └── compose.yml ├── 16-PHP Symfony and MySQL │ └── compose.yml ├── 13-Java and Elasticsearch │ └── compose.yml ├── 19-Kotlin and MariaDB │ └── compose.yml ├── 12-C# and SQL Server │ └── compose.yml ├── 22-Java Spring Boot and MySQL │ └── compose.yml ├── 17-Node.js and PostgreSQL │ └── compose.yml ├── 20-Rust and PostgreSQL │ └── compose.yml ├── 05-Golang and PostgreSQL │ └── compose.yml ├── 04-JavaSpringBootandMySQL │ └── compose.yml ├── 09-PHP Laravel and MySQL │ └── compose.yml ├── 14-Python Django and PostgreSQL │ └── compose.yml ├── 23-PHP Laravel and PostgreSQL │ └── compose.yml ├── 03-RubyonRailsandPostgres │ └── compose.yml ├── 33-Node.js, MongoDB, and RabbitMQ │ └── compose.yml ├── 25-Java Spring Boot, React, and MongoDB with nginx reverse proxy │ └── compose.yml ├── 26-Java Spring Boot, MySQL, and Nginx reverse proxy │ └── compose.yml ├── 32-Django, PostgreSQL, and Redis │ └── compose.yml ├── Node.js, MongoDB, and Redis with socket.io │ └── compose.yml ├── 30-Go, PostgreSQL, and RabbitMQ with microservices architecture │ └── compose.yml ├── 29-Ruby on Rails, PostgreSQL, Redis, and Sidekiq worker │ └── compose.yml ├── 31-PHP Laravel, MySQL, Redis, and Elasticsearch with multiple containers │ └── compose.yml ├── 34-Java Spring Boot, MySQL, and Prometheus │ └── compose.yml ├── 24-Node.js, React, and PostgreSQL with nginx load balancer │ └── compose.yml ├── 27-PHP Laravel, MySQL, and Redis with Horizon job dashboard │ └── compose.yml ├── 28-Python Django, PostgreSQL, Redis, and Celery │ └── compose.yml ├── Readme.md └── 35-Docker-50-commands │ └── commands.sh ├── starterprojects ├── GolangURLShortner │ ├── go.mod │ ├── deployment.yml │ ├── DockerFile │ └── main.go ├── NodeJsURLShortner │ ├── package-lock.json │ ├── Dockerfile.js │ ├── package.json │ ├── deployment.yml │ └── index.js ├── PythonURLShorner │ ├── Dockerfile │ ├── main.py │ └── deployment.yml └── CSharpURLShortner │ ├── Dockerfile │ ├── deployment.yml │ └── controller.cs ├── Contribution.md ├── kubernetes ├── 23-Helm chart for deploying a WordPress application with a MySQL database │ └── deployment.yml ├── 24-Helm chart for deploying a Node.js application with a PostgreSQL database │ └── deployment.yml ├── 01-Simple Deployment with a single container │ └── deployment.yml ├── 04-Deployment with multiple containers │ └── deployment.yml ├── 03-Deployment with liveness probe │ └── deployment.yml ├── 21-Helm chart for deploying Kafka with Zookeeper │ └── deployment.yml ├── 16-Load balancer and API server │ └── deployment.yml ├── 05-Deployment with multiple replicas and service │ └── deployment.yml ├── 15-Database server and worker │ └── deployment.yml ├── 08-Deployment with pod anti-affinity │ └── deployment.yml ├── 07-Deployment with init containers │ └── deployment.yml ├── 11-StatefulSet with a Persistent Volume Claim │ └── deployment.yml ├── 02-Deployment with resource limits and readiness probe │ └── deployment.yml ├── 29-CronJob with Job and ConfigMap │ └── deployment.yml ├── 14-NGINX and PHP-FPM │ └── deployment.yml ├── 20-Python and Redis Application with ConfigMap │ └── deployment.yml ├── 25-Kubernetes deployment with multiple containers using a Helm chart │ └── deployment.yml ├── 09-Deployment with custom health check │ └── deployment.yml ├── 26-Kubernetes deployment with an init container using a Helm chart │ └── deployment.yml ├── 10-Deployment with a Service and Ingress │ └── deployment.yml ├── 18-StatefulSet with persistent volume claims │ └── deployment.yml ├── 27-Kubernetes statefulset with a persistent volume using a Helm chart │ └── deployment.yml ├── 06-Deployment with environment variables and configMap │ └── deployment.yml ├── 12-CronJob │ └── deployment.yml ├── 28-Multiple Containers with ConfigMap and Secrets │ └── deployment.yml ├── 19-Node.js and MongoDB Application with Horizontal Scaling │ └── deployment.yml ├── 17-Microservices with internal load balancing │ └── deployment.yml ├── 22-Simple Helm Chart for a Web Application │ └── deployment.yml ├── 13-WordPress and MySQL │ └── deployment.yml ├── 31-All-K8-Resource │ └── resources.yml └── 30-KubeCtl-50-commandexample │ └── readme.sh ├── LICENCE └── Readme.md /terraform/09-appgateway/aws.tf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /terraform/09-appgateway/azure.tf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /terraform/09-appgateway/gcp.tf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docker/10-Kotlin and Redis/compose.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /starterprojects/GolangURLShortner/go.mod: -------------------------------------------------------------------------------- 1 | module urlshortner 2 | 3 | go 1.20 4 | -------------------------------------------------------------------------------- /terraform/12-staticIpAddress/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_eip" "example" { 6 | vpc = true 7 | } 8 | -------------------------------------------------------------------------------- /starterprojects/NodeJsURLShortner/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NodeJsURLShortner", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": {} 6 | } 7 | -------------------------------------------------------------------------------- /terraform/12-staticIpAddress/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | region = "us-west1" 3 | } 4 | 5 | resource "google_compute_address" "ip" { 6 | name = "example-ip" 7 | } 8 | -------------------------------------------------------------------------------- /starterprojects/NodeJsURLShortner/Dockerfile.js: -------------------------------------------------------------------------------- 1 | FROM node:14-alpine 2 | WORKDIR /app 3 | COPY package*.json ./ 4 | RUN npm install 5 | COPY . . 6 | EXPOSE 3000 7 | CMD ["npm", "start"] 8 | -------------------------------------------------------------------------------- /terraform/02-storageaccount/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_s3_bucket" "example" { 6 | bucket = "example-bucket" 7 | acl = "private" 8 | } 9 | -------------------------------------------------------------------------------- /starterprojects/GolangURLShortner/deployment.yml: -------------------------------------------------------------------------------- 1 | FROM golang:1.16 2 | 3 | WORKDIR /app 4 | 5 | COPY . /app 6 | 7 | RUN go build -o url-shortener 8 | 9 | EXPOSE 8080 10 | 11 | CMD ["./url-shortener"] 12 | -------------------------------------------------------------------------------- /terraform/02-storageaccount/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "my-project-id" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_storage_bucket" "example" { 7 | name = "example-bucket" 8 | } 9 | -------------------------------------------------------------------------------- /terraform/10-queues/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_sqs_queue" "queue" { 6 | name = "my-queue" 7 | 8 | tags = { 9 | Environment = "Production" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docker/01-NodeJsMongoDB/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "3000:3000" 7 | environment: 8 | MONGO_URI: mongodb://mongo/db 9 | mongo: 10 | image: mongo:latest 11 | -------------------------------------------------------------------------------- /docker/15-Ruby and Redis/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "3000:3000" 7 | environment: 8 | REDIS_URL: redis://redis:6379 9 | redis: 10 | image: redis:latest 11 | -------------------------------------------------------------------------------- /starterprojects/PythonURLShorner/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9 2 | 3 | WORKDIR /app 4 | 5 | COPY requirements.txt . 6 | 7 | RUN pip install --no-cache-dir -r requirements.txt 8 | 9 | COPY app.py . 10 | 11 | CMD ["python", "app.py"] 12 | -------------------------------------------------------------------------------- /docker/02-PythonFlaskandRedis/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | web: 4 | build: . 5 | ports: 6 | - "5000:5000" 7 | environment: 8 | REDIS_URL: redis://redis:6379/0 9 | redis: 10 | image: redis:latest 11 | -------------------------------------------------------------------------------- /docker/11-Swift and MongoDB/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | MONGODB_URI: mongodb://mongo:27017/myapp 9 | mongo: 10 | image: mongo:latest 11 | -------------------------------------------------------------------------------- /docker/09-Scala and Cassandra/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | CASSANDRA_CONTACT_POINTS: cassandra 9 | cassandra: 10 | image: cassandra:latest 11 | -------------------------------------------------------------------------------- /docker/21-Python Flask and MongoDB/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "5000:5000" 7 | environment: 8 | MONGO_URI: mongodb://mongo:27017/myapp 9 | mongo: 10 | image: mongo:latest 11 | -------------------------------------------------------------------------------- /docker/18-Go and RabbitMQ/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ 9 | rabbitmq: 10 | image: rabbitmq:latest 11 | -------------------------------------------------------------------------------- /docker/06-Django and SQLite/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8000:8000" 7 | environment: 8 | DB_ENGINE: django.db.backends.sqlite3 9 | DB_NAME: /code/db.sqlite3 10 | db: 11 | image: postgres:latest 12 | -------------------------------------------------------------------------------- /starterprojects/NodeJsURLShortner/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejsurlshortner", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /terraform/01-virtualmachine/aws.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS provider 2 | provider "aws" { 3 | region = "us-east-1" 4 | } 5 | 6 | # Create an EC2 instance 7 | resource "aws_instance" "example" { 8 | ami = "ami-0c55b159cbfafe1f0" 9 | instance_type = "t2.micro" 10 | 11 | tags = { 12 | Name = "Example Instance" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /terraform/10-queues/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "my-project" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_pubsub_topic" "topic" { 7 | name = "my-topic" 8 | } 9 | 10 | resource "google_pubsub_subscription" "subscription" { 11 | name = "my-subscription" 12 | topic = google_pubsub_topic.topic.name 13 | } 14 | -------------------------------------------------------------------------------- /terraform/12-staticIpAddress/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_public_ip" "example" { 6 | name = "example-public-ip" 7 | location = "West US" 8 | resource_group_name = "example-rg" 9 | 10 | allocation_method = "Dynamic" 11 | sku = "Standard" 12 | } 13 | -------------------------------------------------------------------------------- /Contribution.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions should be made via pull requests. Pull requests will be reviewed 4 | by one or more maintainers and merged when acceptable. 5 | 6 | The goal of the Awesome Compose is to provide a curated list of application 7 | samples that can be easily deployed with [Docker Compose](https://github.com/docker/compose). 8 | -------------------------------------------------------------------------------- /docker/07-Rust and MySQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | DATABASE_URL: mysql://root:example@mysql:3306/myapp 9 | mysql: 10 | image: mysql:latest 11 | environment: 12 | MYSQL_DATABASE: myapp 13 | MYSQL_ROOT_PASSWORD: example 14 | -------------------------------------------------------------------------------- /docker/16-PHP Symfony and MySQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8000:8000" 7 | environment: 8 | DATABASE_URL: mysql://root:example@mysql:3306/myapp 9 | mysql: 10 | image: mysql:latest 11 | environment: 12 | MYSQL_DATABASE: myapp 13 | MYSQL_ROOT_PASSWORD: example 14 | -------------------------------------------------------------------------------- /docker/13-Java and Elasticsearch/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | ELASTICSEARCH_URL: http://elasticsearch:9200 9 | elasticsearch: 10 | image: docker.elastic.co/elasticsearch/elasticsearch:7.16.2 11 | environment: 12 | discovery.type: single-node 13 | -------------------------------------------------------------------------------- /docker/19-Kotlin and MariaDB/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | DATABASE_URL: jdbc:mariadb://mariadb:3306/myapp?user=root&password=example 9 | mariadb: 10 | image: mariadb:latest 11 | environment: 12 | MYSQL_DATABASE: myapp 13 | MYSQL_ROOT_PASSWORD: example 14 | -------------------------------------------------------------------------------- /docker/12-C# and SQL Server/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "5000:5000" 7 | environment: 8 | MSSQL_CONNECTION_STRING: Server=db;Database=myapp;User Id=sa;Password=example; 9 | db: 10 | image: mcr.microsoft.com/mssql/server:latest 11 | environment: 12 | SA_PASSWORD: example 13 | ACCEPT_EULA: Y 14 | -------------------------------------------------------------------------------- /docker/22-Java Spring Boot and MySQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | DATABASE_URL: jdbc:mysql://mysql:3306/myapp?user=root&password=example&useSSL=false 9 | mysql: 10 | image: mysql:latest 11 | environment: 12 | MYSQL_DATABASE: myapp 13 | MYSQL_ROOT_PASSWORD: example 14 | -------------------------------------------------------------------------------- /docker/17-Node.js and PostgreSQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "3000:3000" 7 | environment: 8 | DATABASE_URL: postgres://postgres:example@postgres:5432/myapp 9 | postgres: 10 | image: postgres:latest 11 | environment: 12 | POSTGRES_USER: postgres 13 | POSTGRES_PASSWORD: example 14 | POSTGRES_DB: myapp 15 | -------------------------------------------------------------------------------- /docker/20-Rust and PostgreSQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | DATABASE_URL: postgres://postgres:example@postgres:5432/myapp 9 | postgres: 10 | image: postgres:latest 11 | environment: 12 | POSTGRES_USER: postgres 13 | POSTGRES_PASSWORD: example 14 | POSTGRES_DB: myapp 15 | -------------------------------------------------------------------------------- /terraform/07-nosqldb/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_dynamodb_table" "example" { 6 | name = "example_table" 7 | billing_mode = "PAY_PER_REQUEST" 8 | hash_key = "hash_key" 9 | range_key = "range_key" 10 | point_in_time_recovery { 11 | enabled = true 12 | } 13 | tags = { 14 | Environment = "prod" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docker/05-Golang and PostgreSQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | DATABASE_URL: postgres://postgres:example@postgres:5432/myapp?sslmode=disable 9 | postgres: 10 | image: postgres:latest 11 | environment: 12 | POSTGRES_USER: postgres 13 | POSTGRES_PASSWORD: example 14 | POSTGRES_DB: myapp 15 | -------------------------------------------------------------------------------- /kubernetes/23-Helm chart for deploying a WordPress application with a MySQL database/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: wordpress 3 | description: A Helm chart for deploying WordPress and MySQL 4 | version: 0.1.0 5 | dependencies: 6 | - name: mysql 7 | version: 8.0.0 8 | repository: https://charts.bitnami.com/bitnami 9 | - name: wordpress 10 | version: 8.0.0 11 | repository: https://charts.bitnami.com/bitnami 12 | -------------------------------------------------------------------------------- /terraform/07-nosqldb/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "my-project" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_firestore_database" "example" { 7 | name = "example_db" 8 | location = "us-central1" 9 | } 10 | 11 | resource "google_firestore_index" "example_index" { 12 | collection_group = "example_collection" 13 | fields { 14 | field_path = "field1" 15 | order = "ASCENDING" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /kubernetes/24-Helm chart for deploying a Node.js application with a PostgreSQL database/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: node-postgres 3 | description: A Helm chart for deploying Node.js and PostgreSQL 4 | version: 0.1.0 5 | dependencies: 6 | - name: postgresql 7 | version: 10.3.0 8 | repository: https://charts.bitnami.com/bitnami 9 | - name: node 10 | version: 10.3.0 11 | repository: https://charts.bitnami.com/bitnami 12 | -------------------------------------------------------------------------------- /terraform/05-functionapp/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_lambda_function" "function_app" { 6 | filename = "function_app.zip" 7 | function_name = "function_app" 8 | role = "arn:aws:iam::ACCOUNT_ID:role/lambda-role" 9 | handler = "index.handler" 10 | runtime = "nodejs12.x" 11 | source_code_hash = "${base64sha256(file("function_app.zip"))}" 12 | } 13 | -------------------------------------------------------------------------------- /terraform/13-nsg/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "my-project" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_compute_firewall" "nsg" { 7 | name = "nsg" 8 | network = "default" 9 | description = "NSG for allowing all traffic" 10 | 11 | allow { 12 | protocol = "tcp" 13 | ports = ["0-65535"] 14 | } 15 | 16 | source_ranges = ["0.0.0.0/0"] 17 | target_tags = ["my-server-tag"] 18 | } 19 | -------------------------------------------------------------------------------- /docker/04-JavaSpringBootandMySQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8080:8080" 7 | environment: 8 | SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/myapp?useSSL=false 9 | SPRING_DATASOURCE_USERNAME: root 10 | SPRING_DATASOURCE_PASSWORD: example 11 | mysql: 12 | image: mysql:latest 13 | environment: 14 | MYSQL_DATABASE: myapp 15 | MYSQL_ROOT_PASSWORD: example -------------------------------------------------------------------------------- /terraform/13-nsg/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_security_group" "nsg" { 6 | name_prefix = "nsg-" 7 | 8 | ingress { 9 | from_port = 0 10 | to_port = 65535 11 | protocol = "tcp" 12 | cidr_blocks = ["0.0.0.0/0"] 13 | } 14 | 15 | egress { 16 | from_port = 0 17 | to_port = 65535 18 | protocol = "tcp" 19 | cidr_blocks = ["0.0.0.0/0"] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /docker/09-PHP Laravel and MySQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8000:8000" 7 | environment: 8 | DB_CONNECTION: mysql 9 | DB_HOST: mysql 10 | DB_PORT: 3306 11 | DB_DATABASE: myapp 12 | DB_USERNAME: root 13 | DB_PASSWORD: example 14 | mysql: 15 | image: mysql:latest 16 | environment: 17 | MYSQL_DATABASE: myapp 18 | MYSQL_ROOT_PASSWORD: example 19 | -------------------------------------------------------------------------------- /docker/14-Python Django and PostgreSQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | web: 4 | build: . 5 | ports: 6 | - "8000:8000" 7 | environment: 8 | DB_HOST: db 9 | DB_PORT: 5432 10 | DB_NAME: myapp 11 | DB_USER: postgres 12 | DB_PASSWORD: example 13 | db: 14 | image: postgres:latest 15 | environment: 16 | POSTGRES_USER: postgres 17 | POSTGRES_PASSWORD: example 18 | POSTGRES_DB: myapp 19 | -------------------------------------------------------------------------------- /kubernetes/01-Simple Deployment with a single container/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | replicas: 3 7 | selector: 8 | matchLabels: 9 | app: nginx 10 | template: 11 | metadata: 12 | labels: 13 | app: nginx 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx:latest 18 | ports: 19 | - containerPort: 80 20 | -------------------------------------------------------------------------------- /starterprojects/CSharpURLShortner/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . ./ 10 | RUN dotnet publish -c Release -o out 11 | 12 | FROM mcr.microsoft.com/dotnet/aspnet:5.0 13 | WORKDIR /app 14 | COPY --from=build /app/out . 15 | 16 | EXPOSE 80 17 | ENTRYPOINT ["dotnet", "URLShortener.dll"] 18 | -------------------------------------------------------------------------------- /terraform/05-functionapp/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "PROJECT_ID" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_cloudfunctions_function" "function_app" { 7 | name = "function_app" 8 | runtime = "nodejs12" 9 | source_archive_bucket = "function-app-bucket" 10 | source_archive_object = "function_app.zip" 11 | entry_point = "function_handler" 12 | environment_variables = { 13 | "VAR_NAME" = "VAR_VALUE" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docker/23-PHP Laravel and PostgreSQL/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | ports: 6 | - "8000:8000" 7 | environment: 8 | DB_CONNECTION: pgsql 9 | DB_HOST: db 10 | DB_PORT: 5432 11 | DB_DATABASE: myapp 12 | DB_USERNAME: postgres 13 | DB_PASSWORD: example 14 | db: 15 | image: postgres:latest 16 | environment: 17 | POSTGRES_USER: postgres 18 | POSTGRES_PASSWORD: example 19 | POSTGRES_DB: myapp 20 | -------------------------------------------------------------------------------- /starterprojects/GolangURLShortner/DockerFile: -------------------------------------------------------------------------------- 1 | # Use an official Golang runtime as a parent image 2 | FROM golang:1.16 3 | 4 | # Set the working directory to /app 5 | WORKDIR /app 6 | 7 | # Copy the current directory contents into the container at /app 8 | COPY . /app 9 | 10 | # Build the Go application 11 | RUN go build -o url-shortener 12 | 13 | # Expose port 8080 to the outside world 14 | EXPOSE 8080 15 | 16 | # Define the command to run the application when the container starts 17 | CMD ["./url-shortener"] 18 | -------------------------------------------------------------------------------- /kubernetes/04-Deployment with multiple containers/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: myapp 10 | template: 11 | metadata: 12 | labels: 13 | app: myapp 14 | spec: 15 | containers: 16 | - name: web 17 | image: myapp-web:latest 18 | ports: 19 | - containerPort: 8000 20 | - name: worker 21 | image: myapp-worker:latest 22 | -------------------------------------------------------------------------------- /docker/03-RubyonRailsandPostgres/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | web: 4 | build: . 5 | ports: 6 | - "3000:3000" 7 | environment: 8 | POSTGRES_USER: postgres 9 | POSTGRES_PASSWORD: example 10 | POSTGRES_DB: myapp_development 11 | DATABASE_URL: postgres://postgres:example@postgres/myapp_development 12 | db: 13 | image: postgres:latest 14 | environment: 15 | POSTGRES_USER: postgres 16 | POSTGRES_PASSWORD: example 17 | POSTGRES_DB: myapp_development -------------------------------------------------------------------------------- /terraform/01-virtualmachine/gcp.tf: -------------------------------------------------------------------------------- 1 | # Configure the GCP provider 2 | provider "google" { 3 | project = "my-project" 4 | region = "us-central1" 5 | } 6 | 7 | # Create a GCE instance 8 | resource "google_compute_instance" "example" { 9 | name = "example-instance" 10 | machine_type = "n1-standard-1" 11 | zone = "us-central1-a" 12 | 13 | boot_disk { 14 | initialize_params { 15 | image = "debian-cloud/debian-10" 16 | } 17 | } 18 | 19 | network_interface { 20 | network = "default" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /terraform/02-storageaccount/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "example" { 6 | name = "example-group" 7 | location = "eastus" 8 | } 9 | 10 | resource "azurerm_storage_account" "example" { 11 | name = "examplestorageaccount" 12 | resource_group_name = azurerm_resource_group.example.name 13 | location = azurerm_resource_group.example.location 14 | account_tier = "Standard" 15 | account_replication_type = "GRS" 16 | } 17 | -------------------------------------------------------------------------------- /docker/33-Node.js, MongoDB, and RabbitMQ/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | image: node:latest 5 | environment: 6 | - MONGO_URL=mongodb://mongo:27017/myapp 7 | - RABBITMQ_URL=amqp://guest:guest@rabbitmq:5672/ 8 | working_dir: /usr/src/app 9 | volumes: 10 | - .:/usr/src/app 11 | command: npm start 12 | depends_on: 13 | - mongo 14 | - rabbitmq 15 | mongo: 16 | image: mongo:latest 17 | volumes: 18 | - db-data:/data/db 19 | rabbitmq: 20 | image: rabbitmq:latest 21 | -------------------------------------------------------------------------------- /docker/25-Java Spring Boot, React, and MongoDB with nginx reverse proxy/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | SPRING_DATA_MONGODB_HOST: db 7 | depends_on: 8 | - db 9 | db: 10 | image: mongo:latest 11 | frontend: 12 | build: 13 | context: frontend 14 | dockerfile: Dockerfile 15 | depends_on: 16 | - app 17 | nginx: 18 | image: nginx:latest 19 | ports: 20 | - "80:80" 21 | volumes: 22 | - ./nginx.conf:/etc/nginx/nginx.conf 23 | depends_on: 24 | - frontend 25 | -------------------------------------------------------------------------------- /terraform/10-queues/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_storage_account" "account" { 6 | name = "myaccount" 7 | resource_group_name = "myresourcegroup" 8 | location = "westus2" 9 | account_tier = "Standard" 10 | account_replication_type = "LRS" 11 | } 12 | 13 | resource "azurerm_storage_queue" "queue" { 14 | name = "myqueue" 15 | storage_account_name = azurerm_storage_account.account.name 16 | storage_queue_metadata { 17 | some_metadata = "metadata-value" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /kubernetes/03-Deployment with liveness probe/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | replicas: 3 7 | selector: 8 | matchLabels: 9 | app: nginx 10 | template: 11 | metadata: 12 | labels: 13 | app: nginx 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx:latest 18 | ports: 19 | - containerPort: 80 20 | livenessProbe: 21 | httpGet: 22 | path: / 23 | port: 80 24 | initialDelaySeconds: 30 25 | periodSeconds: 10 26 | -------------------------------------------------------------------------------- /starterprojects/PythonURLShorner/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, request 2 | import random 3 | import string 4 | 5 | app = Flask(__name__) 6 | 7 | urls = {} 8 | 9 | @app.route('/shorten', methods=['POST']) 10 | def shorten_url(): 11 | data = request.get_json() 12 | url = data['url'] 13 | key = ''.join(random.choices(string.ascii_letters + string.digits, k=6)) 14 | urls[key] = url 15 | return jsonify({'key': key}) 16 | 17 | @app.route('/') 18 | def redirect_url(key): 19 | return jsonify({'url': urls[key]}), 302 20 | 21 | if __name__ == '__main__': 22 | app.run(debug=True, host='0.0.0.0') 23 | -------------------------------------------------------------------------------- /docker/26-Java Spring Boot, MySQL, and Nginx reverse proxy/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | SPRING_PROFILES_ACTIVE: production 7 | SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/myapp 8 | SPRING_DATASOURCE_USERNAME: root 9 | SPRING_DATASOURCE_PASSWORD: example 10 | depends_on: 11 | - db 12 | restart: always 13 | db: 14 | image: mysql:latest 15 | environment: 16 | MYSQL_ROOT_PASSWORD: example 17 | MYSQL_DATABASE: myapp 18 | proxy: 19 | build: . 20 | ports: 21 | - "80:80" 22 | depends_on: 23 | - app 24 | restart: always 25 | -------------------------------------------------------------------------------- /kubernetes/21-Helm chart for deploying Kafka with Zookeeper/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: kafka-zookeeper 3 | description: A Helm chart for deploying Kafka with Zookeeper. 4 | version: 0.1.0 5 | appVersion: 1.0 6 | 7 | dependencies: 8 | - name: zookeeper 9 | version: 0.3.0 10 | repository: https://charts.helm.sh/stable 11 | 12 | - name: kafka 13 | version: 12.2.3 14 | repository: https://charts.helm.sh/incubator 15 | 16 | values: 17 | kafka: 18 | enabled: true 19 | replicaCount: 3 20 | persistence: 21 | enabled: true 22 | size: 100Gi 23 | zookeeper: 24 | enabled: true 25 | url: zookeeper:2181 26 | -------------------------------------------------------------------------------- /docker/32-Django, PostgreSQL, and Redis/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | web: 4 | image: python:3.9-slim 5 | command: python manage.py runserver 0.0.0.0:8000 6 | working_dir: /code 7 | volumes: 8 | - .:/code 9 | ports: 10 | - "8000:8000" 11 | environment: 12 | - DATABASE_URL=postgres://postgres:postgres@db:5432/mydb 13 | - REDIS_URL=redis://redis:6379/0 14 | depends_on: 15 | - db 16 | - redis 17 | db: 18 | image: postgres:latest 19 | environment: 20 | POSTGRES_DB: mydb 21 | POSTGRES_USER: postgres 22 | POSTGRES_PASSWORD: postgres 23 | redis: 24 | image: redis:latest 25 | -------------------------------------------------------------------------------- /kubernetes/16-Load balancer and API server/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: lb-api 5 | spec: 6 | replicas: 3 7 | selector: 8 | matchLabels: 9 | app: lb-api 10 | template: 11 | metadata: 12 | labels: 13 | app: lb-api 14 | spec: 15 | containers: 16 | - name: lb 17 | image: haproxy:latest 18 | ports: 19 | - containerPort: 80 20 | - name: api 21 | image: node:latest 22 | command: ["npm", "start"] 23 | volumeMounts: 24 | - name: appdir 25 | mountPath: /app 26 | volumes: 27 | - name: appdir 28 | emptyDir: {} 29 | -------------------------------------------------------------------------------- /terraform/07-nosqldb/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_cosmosdb_account" "example" { 6 | name = "example-account" 7 | location = "East US" 8 | resource_group_name = azurerm_resource_group.example.name 9 | offer_type = "Standard" 10 | kind = "GlobalDocumentDB" 11 | consistency_policy { 12 | consistency_level = "Session" 13 | } 14 | } 15 | 16 | resource "azurerm_cosmosdb_sql_database" "example_database" { 17 | name = "example-db" 18 | resource_group_name = azurerm_resource_group.example.name 19 | account_name = azurerm_cosmosdb_account.example.name 20 | } 21 | -------------------------------------------------------------------------------- /docker/Node.js, MongoDB, and Redis with socket.io/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | NODE_ENV: production 7 | MONGO_URI: mongodb://db:27017/myapp 8 | REDIS_URI: redis://redis:6379/0 9 | depends_on: 10 | - db 11 | - redis 12 | ports: 13 | - "3000:3000" 14 | restart: always 15 | db: 16 | image: mongo:latest 17 | volumes: 18 | - db-data:/data/db 19 | redis: 20 | image: redis:latest 21 | worker: 22 | build: . 23 | environment: 24 | NODE_ENV: production 25 | REDIS_URI: redis://redis:6379/0 26 | depends_on: 27 | - app 28 | - redis 29 | restart: always 30 | -------------------------------------------------------------------------------- /starterprojects/PythonURLShorner/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: url-shortener 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: url-shortener 10 | template: 11 | metadata: 12 | labels: 13 | app: url-shortener 14 | spec: 15 | containers: 16 | - name: url-shortener 17 | image: /: 18 | ports: 19 | - containerPort: 5000 20 | env: 21 | - name: FLASK_APP 22 | value: app.py 23 | readinessProbe: 24 | httpGet: 25 | path: /shorten 26 | port: 5000 27 | -------------------------------------------------------------------------------- /docker/30-Go, PostgreSQL, and RabbitMQ with microservices architecture/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | DATABASE_URL: postgresql://postgres:example@db:5432/myapp 7 | RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ 8 | ports: 9 | - "8080:8080" 10 | depends_on: 11 | - db 12 | - rabbitmq 13 | restart: always 14 | db: 15 | image: postgres:latest 16 | environment: 17 | POSTGRES_USER: postgres 18 | POSTGRES_PASSWORD: example 19 | POSTGRES_DB: myapp 20 | rabbitmq: 21 | image: rabbitmq:latest 22 | environment: 23 | RABBITMQ_DEFAULT_USER: guest 24 | RABBITMQ_DEFAULT_PASS: guest 25 | -------------------------------------------------------------------------------- /starterprojects/CSharpURLShortner/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: shortener 5 | spec: 6 | selector: 7 | app: shortener 8 | ports: 9 | - name: http 10 | port: 80 11 | targetPort: 80 12 | --- 13 | apiVersion: apps/v1 14 | kind: Deployment 15 | metadata: 16 | name: shortener 17 | spec: 18 | replicas: 1 19 | selector: 20 | matchLabels: 21 | app: shortener 22 | template: 23 | metadata: 24 | labels: 25 | app: shortener 26 | spec: 27 | containers: 28 | - name: shortener 29 | image: my-registry.com/shortener:latest 30 | ports: 31 | - name: http 32 | containerPort: 80 33 | -------------------------------------------------------------------------------- /terraform/08-mysql/gcp.tf: -------------------------------------------------------------------------------- 1 | # Provider configuration 2 | provider "google" { 3 | project = "my-project" 4 | region = "us-central1" 5 | } 6 | 7 | # Resource configuration 8 | resource "google_compute_instance" "mysql_server" { 9 | name = "mysql-server" 10 | machine_type = "f1-micro" 11 | boot_disk { 12 | initialize_params { 13 | image = "ubuntu-1804-bionic-v20220510" 14 | } 15 | } 16 | metadata_startup_script = "sudo apt-get update && sudo apt-get install -y mysql-server" 17 | 18 | network_interface { 19 | network = "default" 20 | access_config { 21 | # Include this section to give the instance a public IP address 22 | } 23 | } 24 | 25 | tags = ["mysql"] 26 | } 27 | -------------------------------------------------------------------------------- /kubernetes/05-Deployment with multiple replicas and service/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | replicas: 3 7 | selector: 8 | matchLabels: 9 | app: myapp 10 | template: 11 | metadata: 12 | labels: 13 | app: myapp 14 | spec: 15 | containers: 16 | - name: web 17 | image: myapp-web:latest 18 | ports: 19 | - containerPort: 8000 20 | - name: worker 21 | image: myapp-worker:latest 22 | --- 23 | apiVersion: v1 24 | kind: Service 25 | metadata: 26 | name: myapp-service 27 | spec: 28 | selector: 29 | app: myapp 30 | ports: 31 | - protocol: TCP 32 | port: 80 33 | targetPort: 8000 34 | -------------------------------------------------------------------------------- /starterprojects/NodeJsURLShortner/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: url-shortener 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: url-shortener 10 | template: 11 | metadata: 12 | labels: 13 | app: url-shortener 14 | spec: 15 | containers: 16 | - name: url-shortener 17 | image: 18 | ports: 19 | - containerPort: 3000 20 | --- 21 | apiVersion: v1 22 | kind: Service 23 | metadata: 24 | name: url-shortener 25 | spec: 26 | selector: 27 | app: url-shortener 28 | ports: 29 | - name: http 30 | protocol: TCP 31 | port: 80 32 | targetPort: 3000 33 | type: LoadBalancer 34 | -------------------------------------------------------------------------------- /docker/29-Ruby on Rails, PostgreSQL, Redis, and Sidekiq worker/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | RAILS_ENV: production 7 | DATABASE_URL: postgresql://postgres:example@db:5432/myapp 8 | REDIS_URL: redis://redis:6379/0 9 | depends_on: 10 | - db 11 | - redis 12 | restart: always 13 | db: 14 | image: postgres:latest 15 | environment: 16 | POSTGRES_USER: postgres 17 | POSTGRES_PASSWORD: example 18 | POSTGRES_DB: myapp 19 | redis: 20 | image: redis:latest 21 | sidekiq: 22 | build: . 23 | environment: 24 | REDIS_URL: redis://redis:6379/0 25 | depends_on: 26 | - app 27 | - redis 28 | - db 29 | restart: always 30 | -------------------------------------------------------------------------------- /kubernetes/15-Database server and worker/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: db-worker 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: db-worker 10 | template: 11 | metadata: 12 | labels: 13 | app: db-worker 14 | spec: 15 | containers: 16 | - name: db 17 | image: mysql:latest 18 | env: 19 | - name: MYSQL_ROOT_PASSWORD 20 | value: example_password 21 | - name: worker 22 | image: python:latest 23 | command: ["python", "worker.py"] 24 | volumeMounts: 25 | - name: workdir 26 | mountPath: /app 27 | volumes: 28 | - name: workdir 29 | configMap: 30 | name: worker-config 31 | -------------------------------------------------------------------------------- /kubernetes/08-Deployment with pod anti-affinity/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | replicas: 3 7 | selector: 8 | matchLabels: 9 | app: myapp 10 | template: 11 | metadata: 12 | labels: 13 | app: myapp 14 | spec: 15 | affinity: 16 | podAntiAffinity: 17 | requiredDuringSchedulingIgnoredDuringExecution: 18 | - labelSelector: 19 | matchExpressions: 20 | - key: app 21 | operator: In 22 | values: 23 | - myapp 24 | topologyKey: "kubernetes.io/hostname" 25 | containers: 26 | - name: web 27 | image: myapp-web:latest 28 | ports: 29 | - containerPort: 8000 30 | -------------------------------------------------------------------------------- /kubernetes/07-Deployment with init containers/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: myapp 10 | template: 11 | metadata: 12 | labels: 13 | app: myapp 14 | spec: 15 | initContainers: 16 | - name: init-db 17 | image: myapp-db-init:latest 18 | command: ["./init-db.sh"] 19 | volumeMounts: 20 | - name: data 21 | mountPath: /data 22 | containers: 23 | - name: web 24 | image: myapp-web:latest 25 | ports: 26 | - containerPort: 8000 27 | volumeMounts: 28 | - name: data 29 | mountPath: /data 30 | volumes: 31 | - name: data 32 | emptyDir: {} 33 | -------------------------------------------------------------------------------- /terraform/16-KubernetesCluster/azure-aks.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "k8s_rg" { 6 | name = "k8s-rg" 7 | location = "eastus" 8 | } 9 | 10 | module "aks" { 11 | source = "Azure/aks/azurerm" 12 | resource_group_name = azurerm_resource_group.k8s_rg.name 13 | cluster_name = "k8s-cluster" 14 | dns_prefix = "k8s-cluster" 15 | 16 | agent_pool_profiles = [ 17 | { 18 | name = "default" 19 | count = 3 20 | vm_size = "Standard_DS2_v2" 21 | os_disk_size_gb = 30 22 | } 23 | ] 24 | 25 | service_principal { 26 | client_id = "" 27 | client_secret = "" 28 | } 29 | 30 | tags = { 31 | environment = "test" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /terraform/04-virtualnetwork/azure.tf: -------------------------------------------------------------------------------- 1 | # Define provider configuration 2 | provider "azurerm" { 3 | features {} 4 | } 5 | 6 | # Create resource group 7 | resource "azurerm_resource_group" "example" { 8 | name = "example-rg" 9 | location = "East US" 10 | } 11 | 12 | # Create virtual network 13 | resource "azurerm_virtual_network" "example" { 14 | name = "example-vnet" 15 | address_space = ["10.0.0.0/16"] 16 | location = azurerm_resource_group.example.location 17 | resource_group_name = azurerm_resource_group.example.name 18 | 19 | # Create subnet 20 | subnet { 21 | name = "example-subnet" 22 | address_prefix = "10.0.1.0/24" 23 | } 24 | } 25 | 26 | # Output virtual network details 27 | output "virtual_network_id" { 28 | value = azurerm_virtual_network.example.id 29 | } 30 | -------------------------------------------------------------------------------- /terraform/13-nsg/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "rg" { 6 | name = "my-resource-group" 7 | location = "westus2" 8 | } 9 | 10 | resource "azurerm_network_security_group" "nsg" { 11 | name = "nsg" 12 | location = azurerm_resource_group.rg.location 13 | resource_group_name = azurerm_resource_group.rg.name 14 | 15 | security_rule { 16 | name = "allow-all-traffic" 17 | priority = 100 18 | direction = "Inbound" 19 | access = "Allow" 20 | protocol = "Tcp" 21 | source_port_range = "*" 22 | destination_port_range = "*" 23 | source_address_prefix = "*" 24 | destination_address_prefix = "*" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /kubernetes/11-StatefulSet with a Persistent Volume Claim/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: StatefulSet 3 | metadata: 4 | name: myapp 5 | spec: 6 | serviceName: myapp 7 | replicas: 3 8 | selector: 9 | matchLabels: 10 | app: myapp 11 | template: 12 | metadata: 13 | labels: 14 | app: myapp 15 | spec: 16 | containers: 17 | - name: db 18 | image: myapp-db:latest 19 | volumeMounts: 20 | - name: data 21 | mountPath: /var/lib/postgresql/data 22 | volumes: 23 | - name: data 24 | persistentVolumeClaim: 25 | claimName: myapp-pvc 26 | --- 27 | apiVersion: v1 28 | kind: PersistentVolumeClaim 29 | metadata: 30 | name: myapp-pvc 31 | spec: 32 | accessModes: 33 | - ReadWriteOnce 34 | resources: 35 | requests: 36 | storage: 1Gi 37 | -------------------------------------------------------------------------------- /terraform/03-postgress/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_instance" "postgres" { 6 | ami = "ami-0c55b159cbfafe1f0" 7 | instance_type = "t2.micro" 8 | tags = { 9 | Name = "postgres" 10 | } 11 | 12 | user_data = <<-EOF 13 | #!/bin/bash 14 | sudo apt-get update 15 | sudo apt-get -y install postgresql postgresql-contrib 16 | sudo systemctl start postgresql 17 | sudo systemctl enable postgresql 18 | EOF 19 | 20 | vpc_security_group_ids = [aws_security_group.postgres.id] 21 | } 22 | 23 | resource "aws_security_group" "postgres" { 24 | name_prefix = "postgres" 25 | ingress { 26 | from_port = 5432 27 | to_port = 5432 28 | protocol = "tcp" 29 | cidr_blocks = ["0.0.0.0/0"] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /kubernetes/02-Deployment with resource limits and readiness probe/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | replicas: 3 7 | selector: 8 | matchLabels: 9 | app: nginx 10 | template: 11 | metadata: 12 | labels: 13 | app: nginx 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx:latest 18 | ports: 19 | - containerPort: 80 20 | resources: 21 | limits: 22 | cpu: "0.5" 23 | memory: "512Mi" 24 | requests: 25 | cpu: "0.2" 26 | memory: "256Mi" 27 | readinessProbe: 28 | httpGet: 29 | path: / 30 | port: 80 31 | initialDelaySeconds: 10 32 | periodSeconds: 5 33 | timeoutSeconds: 3 34 | -------------------------------------------------------------------------------- /docker/31-PHP Laravel, MySQL, Redis, and Elasticsearch with multiple containers/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | APP_ENV: production 7 | DB_CONNECTION: mysql 8 | DB_HOST: db 9 | DB_PORT: 3306 10 | DB_DATABASE: myapp 11 | DB_USERNAME: root 12 | DB_PASSWORD: example 13 | REDIS_HOST: redis 14 | REDIS_PORT: 6379 15 | ELASTICSEARCH_HOST: elasticsearch 16 | ELASTICSEARCH_PORT: 9200 17 | depends_on: 18 | - db 19 | - redis 20 | - elasticsearch 21 | ports: 22 | - "80:80" 23 | restart: always 24 | db: 25 | image: mysql:latest 26 | environment: 27 | MYSQL_ROOT_PASSWORD: example 28 | MYSQL_DATABASE: myapp 29 | redis: 30 | image: redis:latest 31 | elasticsearch: 32 | image: elasticsearch:latest 33 | -------------------------------------------------------------------------------- /terraform/08-mysql/aws.tf: -------------------------------------------------------------------------------- 1 | # Provider configuration 2 | provider "aws" { 3 | region = "us-west-2" 4 | } 5 | 6 | # Resource configuration 7 | resource "aws_instance" "mysql_server" { 8 | ami = "ami-0c94855ba95c71c99" 9 | instance_type = "t2.micro" 10 | key_name = "my_key" 11 | vpc_security_group_ids = [aws_security_group.mysql_sg.id] 12 | 13 | tags = { 14 | Name = "mysql-server" 15 | } 16 | 17 | # User data for installing MySQL 18 | user_data = <<-EOF 19 | #!/bin/bash 20 | sudo apt-get update 21 | sudo apt-get install mysql-server -y 22 | EOF 23 | } 24 | 25 | resource "aws_security_group" "mysql_sg" { 26 | name_prefix = "mysql-sg" 27 | 28 | ingress { 29 | from_port = 3306 30 | to_port = 3306 31 | protocol = "tcp" 32 | cidr_blocks = ["0.0.0.0/0"] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /kubernetes/29-CronJob with Job and ConfigMap/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: my-configmap 5 | data: 6 | app.properties: | 7 | server.port=8080 8 | --- 9 | apiVersion: batch/v1beta1 10 | kind: CronJob 11 | metadata: 12 | name: my-cronjob 13 | spec: 14 | schedule: "*/5 * * * *" 15 | jobTemplate: 16 | spec: 17 | template: 18 | spec: 19 | containers: 20 | - name: my-app 21 | image: my-image 22 | command: ["/bin/sh"] 23 | args: ["-c", "echo Starting job... && sleep 60 && echo Finishing job..."] 24 | env: 25 | - name: APP_PROPERTIES 26 | valueFrom: 27 | configMapKeyRef: 28 | name: my-configmap 29 | key: app.properties 30 | restartPolicy: OnFailure 31 | -------------------------------------------------------------------------------- /docker/34-Java Spring Boot, MySQL, and Prometheus/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | web: 4 | image: openjdk:16-jdk-alpine 5 | command: java -jar app.jar 6 | environment: 7 | - DATABASE_URL=jdbc:mysql://db:3306/mydb 8 | - SPRING_DATASOURCE_USERNAME=root 9 | - SPRING_DATASOURCE_PASSWORD=example 10 | - SPRING_PROFILES_ACTIVE=prod 11 | volumes: 12 | - .:/app 13 | depends_on: 14 | - db 15 | - prometheus 16 | ports: 17 | - "8080:8080" 18 | restart: always 19 | db: 20 | image: mysql:latest 21 | environment: 22 | - MYSQL_DATABASE=mydb 23 | - MYSQL_ROOT_PASSWORD=example 24 | volumes: 25 | - db-data:/var/lib/mysql 26 | prometheus: 27 | image: prom/prometheus:latest 28 | ports: 29 | - "9090:9090" 30 | volumes: 31 | - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro 32 | volumes: 33 | db-data: 34 | -------------------------------------------------------------------------------- /terraform/03-postgress/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "postgres" { 6 | name = "my-postgres-group" 7 | location = "westus2" 8 | } 9 | 10 | resource "azurerm_postgresql_server" "postgres" { 11 | name = "my-postgres-server" 12 | resource_group_name = azurerm_resource_group.postgres.name 13 | location = azurerm_resource_group.postgres.location 14 | version = "9.6" 15 | 16 | administrator_login = "myadminuser" 17 | administrator_login_password = "H@Sh1CoR3!" 18 | } 19 | 20 | resource "azurerm_postgresql_database" "postgres" { 21 | name = "my-postgres-db" 22 | resource_group_name = azurerm_resource_group.postgres.name 23 | server_name = azurerm_postgresql_server.postgres.name 24 | charset = "UTF8" 25 | collation = "English_United States.1252" 26 | } 27 | -------------------------------------------------------------------------------- /kubernetes/14-NGINX and PHP-FPM/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx 5 | labels: 6 | app: nginx 7 | spec: 8 | type: NodePort 9 | ports: 10 | - port: 80 11 | targetPort: 80 12 | nodePort: 31001 13 | selector: 14 | app: nginx 15 | --- 16 | apiVersion: v1 17 | kind: Service 18 | metadata: 19 | name: php-fpm 20 | labels: 21 | app: php-fpm 22 | spec: 23 | ports: 24 | - port: 9000 25 | targetPort: 9000 26 | selector: 27 | app: php-fpm 28 | --- 29 | apiVersion: apps/v1 30 | kind: Deployment 31 | metadata: 32 | name: nginx 33 | labels: 34 | app: nginx 35 | spec: 36 | replicas: 1 37 | selector: 38 | matchLabels: 39 | app: nginx 40 | template: 41 | metadata: 42 | labels: 43 | app: nginx 44 | spec: 45 | containers: 46 | - name: nginx 47 | image: nginx:latest 48 | ports: 49 | - containerPort: 80 50 | -------------------------------------------------------------------------------- /kubernetes/20-Python and Redis Application with ConfigMap/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | labels: 6 | app: myapp 7 | spec: 8 | replicas: 3 9 | selector: 10 | matchLabels: 11 | app: myapp 12 | template: 13 | metadata: 14 | labels: 15 | app: myapp 16 | spec: 17 | containers: 18 | - name: web 19 | image: myapp:latest 20 | ports: 21 | - containerPort: 8080 22 | - name: worker 23 | image: myapp-worker:latest 24 | env: 25 | - name: QUEUE_NAME 26 | value: myqueue 27 | - name: MAX_JOBS 28 | value: "10" 29 | command: [ "sh", "-c", "python worker.py" ] 30 | --- 31 | apiVersion: v1 32 | kind: Service 33 | metadata: 34 | name: myapp 35 | spec: 36 | selector: 37 | app: myapp 38 | ports: 39 | - protocol: TCP 40 | port: 80 41 | targetPort: 8080 42 | type: LoadBalancer 43 | -------------------------------------------------------------------------------- /terraform/14-RouteTraffic/aws.tf: -------------------------------------------------------------------------------- 1 | # Configure provider 2 | provider "aws" { 3 | region = "us-east-1" 4 | } 5 | 6 | # Create target group 7 | resource "aws_lb_target_group" "example" { 8 | name_prefix = "example-tg-" 9 | port = 80 10 | protocol = "HTTP" 11 | vpc_id = aws_vpc.example.id 12 | target_type = "ip" 13 | } 14 | 15 | # Create listener 16 | resource "aws_lb_listener" "example" { 17 | load_balancer_arn = aws_lb.example.arn 18 | port = 80 19 | protocol = "HTTP" 20 | 21 | default_action { 22 | type = "forward" 23 | target_group_arn = aws_lb_target_group.example.arn 24 | } 25 | } 26 | 27 | # Create load balancer 28 | resource "aws_lb" "example" { 29 | name = "example-lb" 30 | internal = false 31 | load_balancer_type = "application" 32 | security_groups = [aws_security_group.example.id] 33 | subnets = aws_subnet.example.*.id 34 | } 35 | -------------------------------------------------------------------------------- /terraform/15-CDN/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | resource "aws_cloudfront_distribution" "cdn" { 6 | origin { 7 | domain_name = "example.com.s3.amazonaws.com" 8 | origin_id = "S3-example.com" 9 | } 10 | 11 | enabled = true 12 | is_ipv6_enabled = true 13 | default_root_object = "index.html" 14 | 15 | default_cache_behavior { 16 | allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"] 17 | cached_methods = ["GET", "HEAD"] 18 | target_origin_id = "S3-example.com" 19 | 20 | forwarded_values { 21 | query_string = false 22 | 23 | cookies { 24 | forward = "none" 25 | } 26 | } 27 | 28 | viewer_protocol_policy = "redirect-to-https" 29 | min_ttl = 0 30 | default_ttl = 3600 31 | max_ttl = 86400 32 | } 33 | 34 | viewer_certificate { 35 | cloudfront_default_certificate = true 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /terraform/16-KubernetesCluster/gcp.tf: -------------------------------------------------------------------------------- 1 | # Configure the Google Cloud provider 2 | provider "google" { 3 | project = "" 4 | region = "us-central1" 5 | } 6 | 7 | # Set the default machine type for the worker nodes 8 | variable "machine_type" { 9 | default = "n1-standard-2" 10 | } 11 | 12 | # Create a Google Kubernetes Engine cluster 13 | resource "google_container_cluster" "primary" { 14 | name = "example-cluster" 15 | location = "us-central1" 16 | initial_node_count = 1 17 | 18 | node_config { 19 | machine_type = var.machine_type 20 | } 21 | } 22 | 23 | # Connect to the cluster 24 | data "google_client_config" "current" {} 25 | 26 | provider "kubernetes" { 27 | host = google_container_cluster.primary.endpoint 28 | cluster_ca_certificate = base64decode(google_container_cluster.primary.master_auth[0].cluster_ca_certificate) 29 | token = data.google_client_config.current.access_token 30 | } 31 | -------------------------------------------------------------------------------- /terraform/04-virtualnetwork/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_vpc" "example" { 6 | cidr_block = "10.0.0.0/16" 7 | 8 | tags = { 9 | Name = "example-vpc" 10 | } 11 | } 12 | 13 | resource "aws_subnet" "example" { 14 | vpc_id = aws_vpc.example.id 15 | cidr_block = "10.0.1.0/24" 16 | 17 | tags = { 18 | Name = "example-subnet" 19 | } 20 | } 21 | 22 | resource "aws_internet_gateway" "example" { 23 | vpc_id = aws_vpc.example.id 24 | 25 | tags = { 26 | Name = "example-igw" 27 | } 28 | } 29 | 30 | resource "aws_route_table" "example" { 31 | vpc_id = aws_vpc.example.id 32 | 33 | route { 34 | cidr_block = "0.0.0.0/0" 35 | gateway_id = aws_internet_gateway.example.id 36 | } 37 | 38 | tags = { 39 | Name = "example-rt" 40 | } 41 | } 42 | 43 | resource "aws_route_table_association" "example" { 44 | subnet_id = aws_subnet.example.id 45 | route_table_id = aws_route_table.example.id 46 | } 47 | -------------------------------------------------------------------------------- /kubernetes/25-Kubernetes deployment with multiple containers using a Helm chart/deployment.yml: -------------------------------------------------------------------------------- 1 | # Chart.yaml 2 | name: app 3 | version: 1.0.0 4 | description: A Helm chart for deploying the app 5 | 6 | # values.yaml 7 | image: 8 | repository: myapp 9 | tag: latest 10 | 11 | # deployment.yaml 12 | apiVersion: apps/v1 13 | kind: Deployment 14 | metadata: 15 | name: {{ include "app.fullname" . }} 16 | labels: 17 | app: {{ include "app.name" . }} 18 | spec: 19 | replicas: {{ .Values.replicaCount }} 20 | selector: 21 | matchLabels: 22 | app: {{ include "app.name" . }} 23 | template: 24 | metadata: 25 | labels: 26 | 27 | app: {{ include "app.name" . }} 28 | spec: 29 | containers: 30 | - name: {{ .Chart.Name }} 31 | image: {{ .Values.image.repository }}:{{ .Values.image.tag }} 32 | ports: 33 | - name: http 34 | containerPort: 80 35 | - name: sidecar 36 | image: mysidecar:latest 37 | -------------------------------------------------------------------------------- /kubernetes/09-Deployment with custom health check/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: myapp 10 | template: 11 | metadata: 12 | labels: 13 | app: myapp 14 | spec: 15 | containers: 16 | - name: web 17 | image: myapp-web:latest 18 | ports: 19 | - containerPort: 8000 20 | readinessProbe: 21 | tcpSocket: 22 | port: 8000 23 | initialDelaySeconds: 10 24 | periodSeconds: 5 25 | livenessProbe: 26 | exec: 27 | command: 28 | - /bin/bash 29 | - -c 30 | - | 31 | response=$(curl -s -w "%{http_code}" http://localhost:8000 -o /dev/null) 32 | if [ "$response" -ne "200" ]; then 33 | exit 1 34 | fi 35 | initialDelaySeconds: 15 36 | periodSeconds: 10 37 | -------------------------------------------------------------------------------- /starterprojects/NodeJsURLShortner/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | const bodyParser = require('body-parser'); 4 | const shortid = require('shortid'); 5 | const port = 3000; 6 | 7 | const urlDatabase = {}; 8 | 9 | app.set('view engine', 'ejs'); 10 | app.use(bodyParser.urlencoded({ extended: true })); 11 | 12 | app.get('/', (req, res) => { 13 | res.render('index'); 14 | }); 15 | 16 | app.post('/urls', (req, res) => { 17 | const shortURL = shortid.generate(); 18 | urlDatabase[shortURL] = req.body.longURL; 19 | const data = { shortURL, longURL: req.body.longURL }; 20 | res.render('urls_show', { data }); 21 | }); 22 | 23 | app.get('/u/:shortURL', (req, res) => { 24 | const longURL = urlDatabase[req.params.shortURL]; 25 | if (longURL) { 26 | res.redirect(longURL); 27 | } else { 28 | res.status(404).send('URL not found'); 29 | } 30 | }); 31 | 32 | app.listen(port, () => { 33 | console.log(`URL shortener app listening on port ${port}!`); 34 | }); 35 | -------------------------------------------------------------------------------- /kubernetes/26-Kubernetes deployment with an init container using a Helm chart/deployment.yml: -------------------------------------------------------------------------------- 1 | # Chart.yaml 2 | name: app 3 | version: 1.0.0 4 | description: A Helm chart for deploying the app 5 | 6 | # values.yaml 7 | image: 8 | repository: myapp 9 | tag: latest 10 | 11 | # deployment.yaml 12 | apiVersion: apps/v1 13 | kind: Deployment 14 | metadata: 15 | name: {{ include "app.fullname" . }} 16 | labels: 17 | app: {{ include "app.name" . }} 18 | spec: 19 | replicas: {{ .Values.replicaCount }} 20 | selector: 21 | matchLabels: 22 | app: {{ include "app.name" . }} 23 | template: 24 | metadata: 25 | labels: 26 | app: {{ include "app.name" . }} 27 | spec: 28 | initContainers: 29 | - name: init 30 | image: myinitcontainer:latest 31 | containers: 32 | - name: {{ .Chart.Name }} 33 | image: {{ .Values.image.repository }}:{{ .Values.image.tag }} 34 | ports: 35 | - name: http 36 | containerPort: 80 37 | -------------------------------------------------------------------------------- /terraform/03-postgress/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "my-project" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_compute_instance" "postgres" { 7 | name = "postgres" 8 | machine_type = "f1-micro" 9 | 10 | boot_disk { 11 | initialize_params { 12 | image = "debian-cloud/debian-10" 13 | } 14 | } 15 | 16 | metadata_startup_script = <<-EOF 17 | #!/bin/bash 18 | apt-get update 19 | apt-get -y install postgresql 20 | systemctl start postgresql 21 | systemctl enable postgresql 22 | EOF 23 | 24 | network_interface { 25 | network = "default" 26 | } 27 | } 28 | 29 | resource "google_compute_firewall" "postgres" { 30 | name = "postgres" 31 | network = "default" 32 | 33 | allow { 34 | protocol = "tcp" 35 | ports = ["5432"] 36 | } 37 | 38 | source_ranges = ["0.0.0.0/0"] 39 | } 40 | -------------------------------------------------------------------------------- /terraform/06-Webapp/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "example-project" 3 | region = "us-central1" 4 | zone = "us-central1-a" 5 | } 6 | 7 | resource "google_compute_instance" "example" { 8 | name = "example-instance" 9 | machine_type = "f1-micro" 10 | tags = ["http-server"] 11 | boot_disk { 12 | initialize_params { 13 | image = "debian-cloud/debian-9" 14 | } 15 | } 16 | 17 | metadata_startup_script = <<-SCRIPT 18 | #!/bin/bash 19 | apt-get update 20 | apt-get install -y apache2 21 | service apache2 start 22 | echo "

Welcome to the Example Web App!

" > /var/www/html/index.html 23 | SCRIPT 24 | 25 | network_interface { 26 | network = "default" 27 | access_config {} 28 | } 29 | } 30 | 31 | resource "google_compute_firewall" "http" { 32 | name = "http" 33 | network = "default" 34 | 35 | allow { 36 | protocol = "tcp" 37 | ports = ["80"] 38 | } 39 | 40 | source_ranges = ["0.0.0.0/0"] 41 | target_tags = ["http-server"] 42 | } 43 | -------------------------------------------------------------------------------- /docker/24-Node.js, React, and PostgreSQL with nginx load balancer/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | environment: 8 | NODE_ENV: production 9 | DB_HOST: db 10 | DB_PORT: 5432 11 | DB_DATABASE: myapp 12 | DB_USERNAME: postgres 13 | DB_PASSWORD: example 14 | depends_on: 15 | - db 16 | restart: always 17 | db: 18 | image: postgres:latest 19 | environment: 20 | POSTGRES_USER: postgres 21 | POSTGRES_PASSWORD: example 22 | POSTGRES_DB: myapp 23 | volumes: 24 | - db-data:/var/lib/postgresql/data 25 | frontend: 26 | build: 27 | context: frontend 28 | dockerfile: Dockerfile 29 | environment: 30 | NODE_ENV: production 31 | restart: always 32 | nginx: 33 | image: nginx:latest 34 | ports: 35 | - "80:80" 36 | volumes: 37 | - ./nginx.conf:/etc/nginx/conf.d/default.conf 38 | depends_on: 39 | - app 40 | volumes: 41 | db-data: 42 | -------------------------------------------------------------------------------- /kubernetes/10-Deployment with a Service and Ingress/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | app: myapp 10 | template: 11 | metadata: 12 | labels: 13 | app: myapp 14 | spec: 15 | containers: 16 | - name: web 17 | image: myapp-web:latest 18 | ports: 19 | - containerPort: 8000 20 | --- 21 | apiVersion: v1 22 | kind: Service 23 | metadata: 24 | name: myapp-service 25 | spec: 26 | selector: 27 | app: myapp 28 | ports: 29 | - name: http 30 | port: 80 31 | targetPort: 8000 32 | --- 33 | apiVersion: networking.k8s.io/v1beta1 34 | kind: Ingress 35 | metadata: 36 | name: myapp-ingress 37 | annotations: 38 | nginx.ingress.kubernetes.io/rewrite-target: / 39 | spec: 40 | rules: 41 | - host: myapp.example.com 42 | http: 43 | paths: 44 | - path: / 45 | backend: 46 | serviceName: myapp-service 47 | servicePort: http 48 | -------------------------------------------------------------------------------- /terraform/16-KubernetesCluster/aws-eks.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS provider 2 | provider "aws" { 3 | region = "us-west-2" 4 | } 5 | 6 | # Set the default machine type for the worker nodes 7 | variable "instance_type" { 8 | default = "t2.micro" 9 | } 10 | 11 | # Create an Amazon EKS cluster 12 | module "eks" { 13 | source = "terraform-aws-modules/eks/aws" 14 | 15 | cluster_name = "example-cluster" 16 | subnets = ["subnet-12345678", "subnet-87654321"] 17 | vpc_id = "vpc-12345678" 18 | 19 | tags = { 20 | Terraform = "true" 21 | Environment = "dev" 22 | } 23 | 24 | node_groups_launch_template = [ 25 | { 26 | name = "workers" 27 | instance_type = var.instance_type 28 | asg_desired_capacity = 2 29 | }, 30 | ] 31 | } 32 | 33 | # Connect to the cluster 34 | provider "kubernetes" { 35 | host = module.eks.cluster_endpoint 36 | cluster_ca_certificate = base64decode(module.eks.cluster_ca_certificate) 37 | token = module.eks.cluster_token 38 | } 39 | -------------------------------------------------------------------------------- /docker/27-PHP Laravel, MySQL, and Redis with Horizon job dashboard/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | APP_ENV: production 7 | DB_CONNECTION: mysql 8 | DB_HOST: db 9 | DB_PORT: 3306 10 | DB_DATABASE: myapp 11 | DB_USERNAME: root 12 | DB_PASSWORD: example 13 | CACHE_DRIVER: redis 14 | SESSION_DRIVER: redis 15 | QUEUE_CONNECTION: redis 16 | HORIZON_BASE_URI: /horizon 17 | HORIZON_TERMINATE_WORKERS: true 18 | depends_on: 19 | - db 20 | - redis 21 | restart: always 22 | db: 23 | image: mysql:latest 24 | environment: 25 | MYSQL_ROOT_PASSWORD: example 26 | MYSQL_DATABASE: myapp 27 | redis: 28 | image: redis:latest 29 | horizon: 30 | build: . 31 | environment: 32 | APP_ENV: production 33 | CACHE_DRIVER: redis 34 | QUEUE_CONNECTION: redis 35 | HORIZON_BASE_URI: /horizon 36 | depends_on: 37 | - app 38 | - redis 39 | ports: 40 | - "8080:80" 41 | restart: always 42 | -------------------------------------------------------------------------------- /kubernetes/18-StatefulSet with persistent volume claims/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: StatefulSet 3 | metadata: 4 | name: database 5 | spec: 6 | replicas: 3 7 | selector: 8 | matchLabels: 9 | app: database 10 | serviceName: "database" 11 | template: 12 | metadata: 13 | labels: 14 | app: database 15 | spec: 16 | containers: 17 | - name: mysql 18 | image: mysql:5.7 19 | env: 20 | - name: MYSQL_ROOT_PASSWORD 21 | value: mysecretpassword 22 | ports: 23 | - containerPort: 3306 24 | volumeMounts: 25 | - name: data 26 | mountPath: /var/lib/mysql 27 | volumeClaimTemplates: 28 | - metadata: 29 | name: data 30 | spec: 31 | accessModes: [ "ReadWriteOnce" ] 32 | storageClassName: "standard" 33 | resources: 34 | requests: 35 | storage: 1Gi 36 | --- 37 | apiVersion: v1 38 | kind: Service 39 | metadata: 40 | name: database 41 | spec: 42 | selector: 43 | app: database 44 | ports: 45 | - name: mysql 46 | port: 3306 47 | -------------------------------------------------------------------------------- /kubernetes/27-Kubernetes statefulset with a persistent volume using a Helm chart/deployment.yml: -------------------------------------------------------------------------------- 1 | # Chart.yaml 2 | name: app 3 | version: 1.0.0 4 | description: A Helm chart for deploying the app 5 | 6 | # values.yaml 7 | image: 8 | repository: myapp 9 | tag: latest 10 | persistence: 11 | enabled: true 12 | size: 10Gi 13 | 14 | # statefulset.yaml 15 | apiVersion: apps/v1 16 | kind: StatefulSet 17 | metadata: 18 | name: {{ include "app.fullname" . }} 19 | labels: 20 | app: {{ include "app.name" . }} 21 | spec: 22 | replicas: {{ .Values.replicaCount }} 23 | selector: 24 | matchLabels: 25 | app: {{ include "app.name" . }} 26 | serviceName: {{ include "app.fullname" . }} 27 | template: 28 | metadata: 29 | labels: 30 | app: {{ include "app.name" . }} 31 | spec: 32 | containers: 33 | - name: {{ .Chart.Name }} 34 | image: {{ .Values.image.repository }}:{{ .Values.image.tag }} 35 | ports: 36 | - name: http 37 | containerPort: 80 38 | volumeMounts: 39 | - name: data 40 | mountPath: /data 41 | 42 | -------------------------------------------------------------------------------- /docker/28-Python Django, PostgreSQL, Redis, and Celery/compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: . 5 | environment: 6 | DJANGO_SETTINGS_MODULE: myapp.settings.production 7 | DATABASE_URL: postgresql://postgres:example@db:5432/myapp 8 | REDIS_URL: redis://redis:6379/0 9 | depends_on: 10 | - db 11 | - redis 12 | - worker 13 | ports: 14 | - "8000:8000" 15 | restart: always 16 | db: 17 | image: postgres:latest 18 | environment: 19 | POSTGRES_USER: postgres 20 | POSTGRES_PASSWORD: example 21 | POSTGRES_DB: myapp 22 | redis: 23 | image: redis:latest 24 | worker: 25 | build: . 26 | environment: 27 | DJANGO_SETTINGS_MODULE: myapp.settings.production 28 | REDIS_URL: redis://redis:6379/0 29 | depends_on: 30 | - app 31 | - redis 32 | - db 33 | restart: always 34 | flower: 35 | build: . 36 | environment: 37 | CELERY_BROKER_URL: redis://redis:6379/0 38 | FLOWER_PORT: 5555 39 | depends_on: 40 | - worker 41 | ports: 42 | - "5555:5555" 43 | restart: always 44 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Acaleph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /kubernetes/06-Deployment with environment variables and configMap/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: myapp 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: myapp 10 | template: 11 | metadata: 12 | labels: 13 | app: myapp 14 | spec: 15 | containers: 16 | - name: web 17 | image: myapp-web:latest 18 | ports: 19 | - containerPort: 8000 20 | env: 21 | - name: DB_HOST 22 | valueFrom: 23 | configMapKeyRef: 24 | name: db-config 25 | key: db_host 26 | - name: DB_USER 27 | valueFrom: 28 | configMapKeyRef: 29 | name: db-config 30 | key: db_user 31 | - name: DB_PASSWORD 32 | valueFrom: 33 | secretKeyRef: 34 | name: db-secret 35 | key: db_password 36 | volumes: 37 | - name: config-volume 38 | configMap: 39 | name: db-config 40 | - name: secret-volume 41 | secret: 42 | secretName: db-secret 43 | -------------------------------------------------------------------------------- /starterprojects/CSharpURLShortner/controller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace URLShortener.Controllers 9 | { 10 | [ApiController] 11 | [Route("[controller]")] 12 | public class ShortenerController : ControllerBase 13 | { 14 | private readonly ILogger _logger; 15 | 16 | public ShortenerController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet] 22 | public string Get() 23 | { 24 | // Generate a random short code 25 | var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 26 | var random = new Random(); 27 | var shortCode = new string(Enumerable.Repeat(chars, 6) 28 | .Select(s => s[random.Next(s.Length)]).ToArray()); 29 | 30 | // Return the short URL 31 | return "https://example.com/" + shortCode; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /kubernetes/12-CronJob/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: batch/v1beta1 2 | kind: CronJob 3 | metadata: 4 | name: myapp-backup 5 | spec: 6 | schedule: "0 1 * * *" 7 | jobTemplate: 8 | spec: 9 | template: 10 | spec: 11 | containers: 12 | - name: backup 13 | image: myapp-backup:latest 14 | env: 15 | - name: AWS_ACCESS_KEY_ID 16 | valueFrom: 17 | secretKeyRef: 18 | name: aws-creds 19 | key: access-key-id 20 | - name: AWS_SECRET_ACCESS_KEY 21 | valueFrom: 22 | secretKeyRef: 23 | name: aws-creds 24 | key: secret-access-key 25 | restartPolicy: OnFailure 26 | imagePullSecrets: 27 | - name: my-registry-key 28 | restartPolicy: OnFailure 29 | successfulJobsHistoryLimit: 3 30 | failedJobsHistoryLimit: 1 31 | --- 32 | apiVersion: v1 33 | kind: Secret 34 | metadata: 35 | name: aws-creds 36 | type: Opaque 37 | data: 38 | access-key-id: 39 | secret-access-key: 40 | -------------------------------------------------------------------------------- /terraform/06-Webapp/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_instance" "example" { 6 | ami = "ami-0c55b159cbfafe1f0" 7 | instance_type = "t2.micro" 8 | tags = { 9 | Name = "example-instance" 10 | } 11 | 12 | provisioner "remote-exec" { 13 | inline = [ 14 | "sudo yum install httpd -y", 15 | "sudo systemctl start httpd", 16 | "sudo systemctl enable httpd", 17 | "echo '

Welcome to the Example Web App!

' | sudo tee /var/www/html/index.html" 18 | ] 19 | } 20 | 21 | connection { 22 | type = "ssh" 23 | user = "ec2-user" 24 | private_key = file("~/.ssh/id_rsa") 25 | host = self.public_ip 26 | } 27 | 28 | tags = { 29 | Name = "example-instance" 30 | } 31 | 32 | provisioner "local-exec" { 33 | command = "echo ${self.public_ip} > ip_address.txt" 34 | } 35 | 36 | depends_on = [ 37 | aws_security_group.allow_http, 38 | ] 39 | } 40 | 41 | resource "aws_security_group" "allow_http" { 42 | name_prefix = "allow-http" 43 | ingress { 44 | from_port = 80 45 | to_port = 80 46 | protocol = "tcp" 47 | cidr_blocks = ["0.0.0.0/0"] 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /terraform/15-CDN/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "my-project" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_compute_backend_bucket" "backend_bucket" { 7 | name = "backend-bucket" 8 | bucket_name = "backend-bucket" 9 | enable_cdn = true 10 | signed_url_cache_max_age_sec = 3600 11 | description = "Backend bucket for my web app" 12 | } 13 | 14 | resource "google_compute_url_map" "url_map" { 15 | name = "url-map" 16 | default_service = "https://www.googleapis.com/compute/v1/projects/my-project/global/backendBuckets/backend-bucket" 17 | 18 | host_rule { 19 | hosts = ["mydomain.com"] 20 | } 21 | 22 | path_matcher { 23 | name = "path-matcher" 24 | default_service = "https://www.googleapis.com/compute/v1/projects/my-project/global/backendBuckets/backend-bucket" 25 | 26 | path_rule { 27 | paths = ["/"] 28 | service = "https://www.googleapis.com/compute/v1/projects/my-project/global/backendBuckets/backend-bucket" 29 | } 30 | } 31 | } 32 | 33 | resource "google_compute_global_forwarding_rule" "forwarding_rule" { 34 | name = "forwarding-rule" 35 | target = google_compute_url_map.url_map.self_link 36 | ip_address = "0.0.0.0" 37 | port_range = "80" 38 | } 39 | -------------------------------------------------------------------------------- /terraform/08-mysql/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "myresourcegroup" { 6 | name = "myresourcegroup" 7 | location = "East US" 8 | } 9 | 10 | resource "azurerm_mysql_server" "mysqldatabase" { 11 | name = "my-mysql-server" 12 | resource_group_name = azurerm_resource_group.myresourcegroup.name 13 | location = azurerm_resource_group.myresourcegroup.location 14 | version = "5.7" 15 | 16 | administrator_login = "myadmin" 17 | administrator_login_password = "Password1234!" 18 | 19 | sku { 20 | name = "B_Gen5_1" 21 | capacity = 1 22 | } 23 | 24 | storage_profile { 25 | storage_mb = 5120 26 | backup_retention_days = 7 27 | geo_redundant_backup = "Disabled" 28 | } 29 | } 30 | 31 | resource "azurerm_mysql_database" "mysqldatabase" { 32 | name = "mydatabase" 33 | resource_group_name = azurerm_resource_group.myresourcegroup.name 34 | server_name = azurerm_mysql_server.mysqldatabase.name 35 | charset = "utf8" 36 | collation = "utf8_general_ci" 37 | } 38 | 39 | variable "mysql_admin_username" { 40 | type = string 41 | } 42 | 43 | variable "mysql_admin_password" { 44 | type = string 45 | } 46 | 47 | variable "mysql_database_name" { 48 | type = string 49 | } 50 | -------------------------------------------------------------------------------- /kubernetes/28-Multiple Containers with ConfigMap and Secrets/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: my-configmap 5 | data: 6 | app.properties: | 7 | server.port=8080 8 | --- 9 | apiVersion: v1 10 | kind: Secret 11 | metadata: 12 | name: my-secret 13 | type: Opaque 14 | data: 15 | password: c2VjcmV0MTIzNDU2 16 | --- 17 | apiVersion: apps/v1 18 | kind: Deployment 19 | metadata: 20 | name: my-app 21 | spec: 22 | replicas: 1 23 | selector: 24 | matchLabels: 25 | app: my-app 26 | template: 27 | metadata: 28 | labels: 29 | app: my-app 30 | spec: 31 | containers: 32 | - name: my-app 33 | image: my-image 34 | ports: 35 | - containerPort: 8080 36 | env: 37 | - name: PASSWORD 38 | valueFrom: 39 | secretKeyRef: 40 | name: my-secret 41 | key: password 42 | volumeMounts: 43 | - name: app-config 44 | mountPath: /app/config 45 | volumes: 46 | - name: app-config 47 | configMap: 48 | name: my-configmap 49 | --- 50 | apiVersion: v1 51 | kind: Service 52 | metadata: 53 | name: my-service 54 | spec: 55 | selector: 56 | app: my-app 57 | ports: 58 | - name: http 59 | protocol: TCP 60 | port: 80 61 | targetPort: 8080 62 | -------------------------------------------------------------------------------- /terraform/11-loadbalancer/aws.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | resource "aws_security_group" "load_balancer" { 6 | name_prefix = "load-balancer" 7 | 8 | ingress { 9 | from_port = 80 10 | to_port = 80 11 | protocol = "tcp" 12 | cidr_blocks = ["0.0.0.0/0"] 13 | } 14 | 15 | ingress { 16 | from_port = 443 17 | to_port = 443 18 | protocol = "tcp" 19 | cidr_blocks = ["0.0.0.0/0"] 20 | } 21 | } 22 | 23 | resource "aws_lb" "load_balancer" { 24 | name = "load-balancer" 25 | internal = false 26 | load_balancer_type = "application" 27 | 28 | subnets = [ 29 | "subnet-0f9e4b48ef0cbea6d", 30 | "subnet-0e74eef6de76b6b93", 31 | "subnet-0c5d5f82c5d2568ec" 32 | ] 33 | 34 | security_groups = [ 35 | aws_security_group.load_balancer.id 36 | ] 37 | 38 | tags = { 39 | Name = "load-balancer" 40 | } 41 | } 42 | 43 | resource "aws_lb_target_group" "target_group" { 44 | name_prefix = "target-group" 45 | port = 80 46 | protocol = "HTTP" 47 | vpc_id = "vpc-0de3839a20fbb0cb5" 48 | } 49 | 50 | resource "aws_lb_listener" "listener" { 51 | load_balancer_arn = aws_lb.load_balancer.arn 52 | port = "80" 53 | protocol = "HTTP" 54 | 55 | default_action { 56 | target_group_arn = aws_lb_target_group.target_group.arn 57 | type = "forward" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /terraform/06-Webapp/azure.tf: -------------------------------------------------------------------------------- 1 | # Configure the Azure provider 2 | provider "azurerm" { 3 | features {} 4 | } 5 | 6 | # Create a resource group 7 | resource "azurerm_resource_group" "example" { 8 | name = "example-resource-group" 9 | location = "East US" 10 | } 11 | 12 | # Create an App Service plan 13 | resource "azurerm_app_service_plan" "example" { 14 | name = "example-app-service-plan" 15 | location = azurerm_resource_group.example.location 16 | resource_group_name = azurerm_resource_group.example.name 17 | 18 | sku { 19 | tier = "Free" 20 | size = "F1" 21 | } 22 | } 23 | 24 | # Create an App Service web app 25 | resource "azurerm_app_service" "example" { 26 | name = "example-web-app" 27 | location = azurerm_resource_group.example.location 28 | resource_group_name = azurerm_resource_group.example.name 29 | app_service_plan_id = azurerm_app_service_plan.example.id 30 | 31 | site_config { 32 | dotnet_framework_version = "v4.0" 33 | scm_type = "LocalGit" 34 | } 35 | 36 | app_settings = { 37 | "WEBSITE_TIME_ZONE" = "UTC" 38 | } 39 | 40 | connection_string { 41 | name = "MyDatabase" 42 | type = "SQLServer" 43 | value = "Server=tcp:my-server.database.windows.net,1433;Initial Catalog=my-db;Persist Security Info=False;User ID=my-user;Password=my-password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /terraform/15-CDN/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "rg" { 6 | name = "my-resource-group" 7 | location = "East US" 8 | } 9 | 10 | resource "azurerm_cdn_profile" "cdn_profile" { 11 | name = "my-cdn-profile" 12 | resource_group_name = azurerm_resource_group.rg.name 13 | location = azurerm_resource_group.rg.location 14 | sku = "Standard_Verizon" 15 | } 16 | 17 | resource "azurerm_cdn_endpoint" "cdn_endpoint" { 18 | name = "my-cdn-endpoint" 19 | location = azurerm_resource_group.rg.location 20 | profile_name = azurerm_cdn_profile.cdn_profile.name 21 | resource_group_name = azurerm_resource_group.rg.name 22 | origin { 23 | name = "my-origin" 24 | host_name = "my-vm.azurewebsites.net" 25 | http_port = 80 26 | https_port = 443 27 | content_path = "/" 28 | origin_host_header = "my-vm.azurewebsites.net" 29 | } 30 | delivery_rule { 31 | order = 1 32 | request_scheme_condition { 33 | operator = "Equal" 34 | match_values = [ 35 | "HTTP", 36 | ] 37 | } 38 | cache_behavior { 39 | cache_duration_seconds = 86400 40 | dynamic_compression = "Enabled" 41 | query_string_caching_behavior = "IgnoreQueryString" 42 | header_action = "Append" 43 | headers = { 44 | "X-Custom-Header" = "Custom-Value" 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /kubernetes/19-Node.js and MongoDB Application with Horizontal Scaling/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: node-mongo-deployment 5 | labels: 6 | app: node-mongo 7 | spec: 8 | replicas: 3 9 | selector: 10 | matchLabels: 11 | app: node-mongo 12 | template: 13 | metadata: 14 | labels: 15 | app: node-mongo 16 | spec: 17 | containers: 18 | - name: node 19 | image: node:12-alpine 20 | command: ["npm", "start"] 21 | env: 22 | - name: MONGODB_URI 23 | valueFrom: 24 | secretKeyRef: 25 | name: mongo-secret 26 | key: uri 27 | ports: 28 | - containerPort: 3000 29 | - name: mongo 30 | image: mongo:4.2 31 | env: 32 | - name: MONGO_INITDB_ROOT_USERNAME 33 | valueFrom: 34 | secretKeyRef: 35 | name: mongo-secret 36 | key: username 37 | - name: MONGO_INITDB_ROOT_PASSWORD 38 | valueFrom: 39 | secretKeyRef: 40 | name: mongo-secret 41 | key: password 42 | ports: 43 | - containerPort: 27017 44 | --- 45 | apiVersion: v1 46 | kind: Service 47 | metadata: 48 | name: node-mongo-service 49 | spec: 50 | selector: 51 | app: node-mongo 52 | ports: 53 | - name: http 54 | port: 80 55 | targetPort: 3000 56 | type: LoadBalancer 57 | -------------------------------------------------------------------------------- /kubernetes/17-Microservices with internal load balancing/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: backend 5 | spec: 6 | selector: 7 | app: backend 8 | ports: 9 | - name: http 10 | port: 80 11 | targetPort: 8080 12 | clusterIP: None 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: backend 18 | spec: 19 | replicas: 3 20 | selector: 21 | matchLabels: 22 | app: backend 23 | template: 24 | metadata: 25 | labels: 26 | app: backend 27 | spec: 28 | containers: 29 | - name: app 30 | image: mycompany/backend:latest 31 | ports: 32 | - name: http 33 | containerPort: 8080 34 | - name: db 35 | image: mysql:latest 36 | env: 37 | - name: MYSQL_ROOT_PASSWORD 38 | value: mysecretpassword 39 | --- 40 | apiVersion: v1 41 | kind: Service 42 | metadata: 43 | name: frontend 44 | spec: 45 | selector: 46 | app: frontend 47 | ports: 48 | - name: http 49 | port: 80 50 | targetPort: 8080 51 | --- 52 | apiVersion: apps/v1 53 | kind: Deployment 54 | metadata: 55 | name: frontend 56 | spec: 57 | replicas: 2 58 | selector: 59 | matchLabels: 60 | app: frontend 61 | template: 62 | metadata: 63 | labels: 64 | app: frontend 65 | spec: 66 | containers: 67 | - name: app 68 | image: mycompany/frontend:latest 69 | ports: 70 | - name: http 71 | containerPort: 8080 72 | env: 73 | - name: BACKEND_URL 74 | value: http://backend.default.svc.cluster.local 75 | -------------------------------------------------------------------------------- /terraform/01-virtualmachine/azure.tf: -------------------------------------------------------------------------------- 1 | # Configure the Azure provider 2 | provider "azurerm" { 3 | features {} 4 | } 5 | 6 | # Create an Azure VM 7 | resource "azurerm_virtual_machine" "example" { 8 | name = "example-vm" 9 | location = "eastus" 10 | resource_group_name = "example-group" 11 | network_interface_ids = [azurerm_network_interface.example.id] 12 | 13 | vm_size = "Standard_DS1_v2" 14 | 15 | storage_image_reference { 16 | publisher = "Canonical" 17 | offer = "UbuntuServer" 18 | sku = "18.04-LTS" 19 | version = "latest" 20 | } 21 | 22 | os_disk { 23 | name = "example-osdisk" 24 | caching = "ReadWrite" 25 | storage_account_type = "Standard_LRS" 26 | } 27 | 28 | source_image_reference { 29 | publisher = "Canonical" 30 | offer = "UbuntuServer" 31 | sku = "18.04-LTS" 32 | version = "latest" 33 | } 34 | 35 | admin_username = "exampleuser" 36 | admin_password = "password1234!" 37 | } 38 | 39 | # Create a network interface for the VM 40 | resource "azurerm_network_interface" "example" { 41 | name = "example-nic" 42 | location = "eastus" 43 | resource_group_name = "example-group" 44 | 45 | ip_configuration { 46 | name = "example-ipconfig" 47 | subnet_id = azurerm_subnet.example.id 48 | private_ip_address_allocation = "Dynamic" 49 | } 50 | } 51 | 52 | # Create a subnet for the VM 53 | resource "azurerm_subnet" "example" { 54 | name = "example-subnet" 55 | resource_group_name = "example-group" 56 | virtual_network_name = "example-vnet" 57 | address_prefixes = ["10.0.1.0/24"] 58 | } 59 | -------------------------------------------------------------------------------- /terraform/11-loadbalancer/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "my-project-id" 3 | region = "us-central1" 4 | } 5 | 6 | resource "google_compute_backend_service" "backend-service" { 7 | name = "my-backend-service" 8 | 9 | backend { 10 | group = "my-instance-group" 11 | } 12 | } 13 | 14 | resource "google_compute_health_check" "health-check" { 15 | name = "my-health-check" 16 | check_interval_sec = 10 17 | timeout_sec = 5 18 | tcp_health_check { 19 | port = 80 20 | } 21 | } 22 | 23 | resource "google_compute_url_map" "url-map" { 24 | name = "my-url-map" 25 | default_service = "${google_compute_backend_service.backend-service.self_link}" 26 | 27 | host_rule { 28 | hosts = ["mydomain.com"] 29 | path_matcher = "my-path-matcher" 30 | } 31 | 32 | path_matcher { 33 | name = "my-path-matcher" 34 | default_service = "${google_compute_backend_service.backend-service.self_link}" 35 | 36 | path_rule { 37 | paths = ["/path1/*"] 38 | service = "${google_compute_backend_service.backend-service.self_link}" 39 | route_action { 40 | url_rewrite { 41 | path_prefix_rewrite = "/app1/" 42 | } 43 | } 44 | } 45 | 46 | path_rule { 47 | paths = ["/path2/*"] 48 | service = "${google_compute_backend_service.backend-service.self_link}" 49 | route_action { 50 | url_rewrite { 51 | path_prefix_rewrite = "/app2/" 52 | } 53 | } 54 | } 55 | } 56 | } 57 | 58 | resource "google_compute_global_forwarding_rule" "forwarding-rule" { 59 | name = "my-forwarding-rule" 60 | ip_address = "0.0.0.0" 61 | port_range = "80-80" 62 | 63 | target = "${google_compute_url_map.url-map.self_link}" 64 | } 65 | 66 | -------------------------------------------------------------------------------- /terraform/11-loadbalancer/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "example" { 6 | name = "example-resource-group" 7 | location = "West US" 8 | } 9 | 10 | resource "azurerm_public_ip" "example" { 11 | name = "example-public-ip" 12 | location = azurerm_resource_group.example.location 13 | resource_group_name = azurerm_resource_group.example.name 14 | allocation_method = "Static" 15 | 16 | tags = { 17 | environment = "example" 18 | } 19 | } 20 | 21 | resource "azurerm_lb" "example" { 22 | name = "example-lb" 23 | location = azurerm_resource_group.example.location 24 | resource_group_name = azurerm_resource_group.example.name 25 | 26 | frontend_ip_configuration { 27 | name = "PublicIPAddress" 28 | public_ip_address_id = azurerm_public_ip.example.id 29 | } 30 | 31 | tags = { 32 | environment = "example" 33 | } 34 | } 35 | 36 | resource "azurerm_lb_backend_address_pool" "example" { 37 | name = "example-backend-pool" 38 | loadbalancer_id = azurerm_lb.example.id 39 | resource_group_name = azurerm_resource_group.example.name 40 | 41 | tags = { 42 | environment = "example" 43 | } 44 | } 45 | 46 | resource "azurerm_network_interface_backend_address_pool_association" "example" { 47 | count = var.vm_count 48 | 49 | network_interface_id = element(azurerm_network_interface.example.*.id, count.index) 50 | ip_configuration_name = "ipconfig" 51 | backend_address_pool_id = azurerm_lb_backend_address_pool.example.id 52 | 53 | depends_on = [ 54 | azurerm_lb_backend_address_pool.example, 55 | azurerm_network_interface.example, 56 | ] 57 | 58 | tags = { 59 | environment = "example" 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /terraform/16-KubernetesCluster/aws.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS provider 2 | provider "aws" { 3 | region = var.region 4 | } 5 | 6 | # Create a new VPC 7 | resource "aws_vpc" "kubernetes_vpc" { 8 | cidr_block = "10.0.0.0/16" 9 | } 10 | 11 | # Create a new public subnet 12 | resource "aws_subnet" "public_subnet" { 13 | vpc_id = aws_vpc.kubernetes_vpc.id 14 | cidr_block = "10.0.1.0/24" 15 | availability_zone = var.availability_zone 16 | tags = { 17 | Name = "kubernetes_public_subnet" 18 | } 19 | } 20 | 21 | # Create a new security group for the Kubernetes control plane 22 | resource "aws_security_group" "kubernetes_control_plane_sg" { 23 | name_prefix = "kubernetes_control_plane_" 24 | vpc_id = aws_vpc.kubernetes_vpc.id 25 | 26 | ingress { 27 | from_port = 22 28 | to_port = 22 29 | protocol = "tcp" 30 | cidr_blocks = [var.allowed_cidr_blocks] 31 | } 32 | 33 | ingress { 34 | from_port = 6443 35 | to_port = 6443 36 | protocol = "tcp" 37 | cidr_blocks = [var.allowed_cidr_blocks] 38 | } 39 | 40 | egress { 41 | from_port = 0 42 | to_port = 0 43 | protocol = "-1" 44 | cidr_blocks = ["0.0.0.0/0"] 45 | } 46 | } 47 | 48 | # Provision a Kubernetes control plane 49 | module "kubernetes" { 50 | source = "terraform-aws-modules/kubernetes/aws" 51 | 52 | cluster_name = var.cluster_name 53 | subnets = [aws_subnet.public_subnet.id] 54 | vpc_id = aws_vpc.kubernetes_vpc.id 55 | 56 | tags = { 57 | Terraform = "true" 58 | Environment = var.environment 59 | } 60 | 61 | # Use the security group created above 62 | control_plane_security_group_id = aws_security_group.kubernetes_control_plane_sg.id 63 | } 64 | 65 | # Output the Kubernetes control plane endpoint 66 | output "kubernetes_control_plane_endpoint" { 67 | value = module.kubernetes.control_plane_endpoint 68 | } 69 | 70 | -------------------------------------------------------------------------------- /docker/Readme.md: -------------------------------------------------------------------------------- 1 | # This repository contains a pre-built docker operations tasks. 2 | 3 | These samples provide a starting point for how to integrate different services using a Compose file and to manage their deployment with Docker Compose. 4 | 5 | 6 | ## Getting started 7 | 8 | These instructions will get you through the bootstrap phase of creating and 9 | deploying samples of containerized applications with Docker Compose. 10 | 11 | ### Prerequisites 12 | 13 | - Make sure that you have Docker and Docker Compose installed 14 | - Windows or macOS: 15 | [Install Docker Desktop](https://www.docker.com/get-started) 16 | - Linux: [Install Docker](https://www.docker.com/get-started) and then 17 | [Docker Compose](https://github.com/docker/compose) 18 | - Download some or all of the samples from this repository. 19 | 20 | ### Running a sample 21 | 22 | The root directory of each sample contains the `compose.yaml` which 23 | describes the configuration of service components. All samples can be run in 24 | a local environment by going into the root directory of each one and executing: 25 | 26 | ```console 27 | docker compose up -d 28 | ``` 29 | 30 | Check the `README.md` of each sample to get more details on the structure and 31 | what is the expected output. 32 | To stop and remove all containers of the sample application run: 33 | 34 | ```console 35 | docker compose down 36 | ``` 37 | 38 | ### Quickstart guides 39 | 40 | In addition to all the ready to run Compose samples listed above the folder [official-documentation-samples](official-documentation-samples/README.md) contains quickstart guides. Each of these step by step guides explain which files need to be created to build and run a Docker Compose application. 41 | 42 | 43 | ## Contribute 44 | 45 | We welcome examples that help people understand how to use Docker Compose for 46 | common applications. Check the [Contribution Guide](../CONTRIBUTING.md) for more details. 47 | -------------------------------------------------------------------------------- /terraform/04-virtualnetwork/gcp.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | region = "us-central1" 3 | } 4 | 5 | resource "google_compute_network" "example" { 6 | name = "example-vpc" 7 | auto_create_subnetworks = false 8 | } 9 | 10 | resource "google_compute_subnetwork" "example" { 11 | name = "example-subnet" 12 | ip_cidr_range = "10.0.1.0/24" 13 | network = google_compute_network.example.self_link 14 | } 15 | 16 | resource "google_compute_global_address" "example" { 17 | name = "example-address" 18 | } 19 | 20 | resource "google_compute_address" "example" { 21 | name = "example-address" 22 | address_type = "INTERNAL" 23 | subnetwork = google_compute_subnetwork.example.self_link 24 | address = google_compute_global_address.example.address 25 | } 26 | 27 | resource "google_compute_router" "example" { 28 | name = "example-router" 29 | } 30 | 31 | resource "google_compute_router_interface" "example" { 32 | router = google_compute_router.example.name 33 | region = google_compute_network.example.region 34 | ip_range = "10.0.1.0/24" 35 | linked_vpn_tunnel = null 36 | linked_interconnect = null 37 | subnetwork = google_compute_subnetwork.example.self_link 38 | } 39 | 40 | resource "google_compute_route" "example" { 41 | name = "example-route" 42 | network = google_compute_network.example.self_link 43 | priority = 1000 44 | destination_range = "0.0.0.0/0" 45 | next_hop_network = null 46 | next_hop_gateway = google_compute_router_interface.example.ip_address 47 | next_hop_instance = null 48 | next_hop_vpn_tunnel = null 49 | next_hop_gateway_vpc = null 50 | next_hop_ilb = null 51 | } 52 | 53 | resource "google_compute_firewall" "example" { 54 | name = "example-firewall" 55 | network = google_compute_network.example.self_link 56 | 57 | allow { 58 | protocol = "icmp" 59 | } 60 | 61 | allow { 62 | protocol = "tcp" 63 | ports = ["22"] 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /kubernetes/22-Simple Helm Chart for a Web Application/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: myapp 3 | description: A simple web application 4 | version: 1.0.0 5 | appVersion: "1.0" 6 | dependencies: 7 | - name: nginx 8 | version: "1.0.0" 9 | repository: https://charts.bitnami.com/bitnami 10 | - name: mysql 11 | version: "8.0.27" 12 | repository: https://charts.bitnami.com/bitnami 13 | - name: redis 14 | version: "15.8.0" 15 | repository: https://charts.bitnami.com/bitnami 16 | - name: memcached 17 | version: "3.14.2" 18 | repository: https://charts.bitnami.com/bitnami 19 | - name: mongodb 20 | version: "10.3.3" 21 | repository: https://charts.bitnami.com/bitnami 22 | 23 | --- 24 | # Deployment manifest 25 | apiVersion: apps/v1 26 | kind: Deployment 27 | metadata: 28 | name: {{ .Release.Name }}-deployment 29 | labels: 30 | app: {{ .Release.Name }} 31 | spec: 32 | replicas: 3 33 | selector: 34 | matchLabels: 35 | app: {{ .Release.Name }} 36 | template: 37 | metadata: 38 | labels: 39 | app: {{ .Release.Name }} 40 | spec: 41 | containers: 42 | - name: {{ .Release.Name }}-container 43 | image: nginx:1.16 44 | ports: 45 | - containerPort: 80 46 | env: 47 | - name: MYSQL_ROOT_PASSWORD 48 | value: mypassword 49 | - name: REDIS_PASSWORD 50 | value: mypassword 51 | - name: MEMCACHED_PASSWORD 52 | value: mypassword 53 | - name: MONGODB_ROOT_PASSWORD 54 | value: mypassword 55 | volumeMounts: 56 | - name: nginx-config 57 | mountPath: /etc/nginx/nginx.conf 58 | subPath: nginx.conf 59 | volumes: 60 | - name: nginx-config 61 | configMap: 62 | name: {{ .Release.Name }}-nginx-configmap 63 | 64 | --- 65 | # Service manifest 66 | apiVersion: v1 67 | kind: Service 68 | metadata: 69 | name: {{ .Release.Name }}-service 70 | spec: 71 | type: NodePort 72 | selector: 73 | app: {{ .Release.Name }} 74 | ports: 75 | - protocol: TCP 76 | port: 80 77 | targetPort: 80 78 | -------------------------------------------------------------------------------- /kubernetes/13-WordPress and MySQL/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: wordpress 5 | labels: 6 | app: wordpress 7 | spec: 8 | type: NodePort 9 | ports: 10 | - port: 80 11 | targetPort: 80 12 | nodePort: 31000 13 | selector: 14 | app: wordpress 15 | --- 16 | apiVersion: v1 17 | kind: Service 18 | metadata: 19 | name: mysql 20 | labels: 21 | app: mysql 22 | spec: 23 | ports: 24 | - port: 3306 25 | targetPort: 3306 26 | selector: 27 | app: mysql 28 | --- 29 | apiVersion: apps/v1 30 | kind: Deployment 31 | metadata: 32 | name: wordpress 33 | labels: 34 | app: wordpress 35 | spec: 36 | replicas: 1 37 | selector: 38 | matchLabels: 39 | app: wordpress 40 | template: 41 | metadata: 42 | labels: 43 | app: wordpress 44 | spec: 45 | containers: 46 | - name: wordpress 47 | image: wordpress:latest 48 | ports: 49 | - containerPort: 80 50 | env: 51 | - name: WORDPRESS_DB_HOST 52 | value: mysql 53 | - name: WORDPRESS_DB_USER 54 | value: root 55 | - name: WORDPRESS_DB_PASSWORD 56 | value: example 57 | volumeMounts: 58 | - name: wordpress-persistent-storage 59 | mountPath: /var/www/html 60 | volumes: 61 | - name: wordpress-persistent-storage 62 | emptyDir: {} 63 | --- 64 | apiVersion: apps/v1 65 | kind: Deployment 66 | metadata: 67 | name: mysql 68 | labels: 69 | app: mysql 70 | spec: 71 | replicas: 1 72 | selector: 73 | matchLabels: 74 | app: mysql 75 | template: 76 | metadata: 77 | labels: 78 | app: mysql 79 | spec: 80 | containers: 81 | - name: mysql 82 | image: mysql:latest 83 | env: 84 | - name: MYSQL_ROOT_PASSWORD 85 | value: example 86 | - name: MYSQL_DATABASE 87 | value: wordpress 88 | ports: 89 | - containerPort: 3306 90 | volumeMounts: 91 | - name: mysql-persistent-storage 92 | mountPath: /var/lib/mysql 93 | volumes: 94 | - name: mysql-persistent-storage 95 | emptyDir: {} 96 | -------------------------------------------------------------------------------- /starterprojects/GolangURLShortner/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "log" 7 | "net/http" 8 | "strconv" 9 | "sync" 10 | ) 11 | 12 | var ( 13 | port int 14 | baseURL string 15 | shortened = make(map[string]string) 16 | mu sync.Mutex 17 | ) 18 | 19 | func main() { 20 | flag.IntVar(&port, "port", 8080, "Port to listen on") 21 | flag.StringVar(&baseURL, "base-url", "http://localhost:8080", "Base URL for shortened URLs") 22 | flag.Parse() 23 | 24 | http.HandleFunc("/", handleIndex) 25 | http.HandleFunc("/shorten", handleShorten) 26 | http.HandleFunc("/s/", handleShortened) 27 | 28 | log.Printf("Listening on port %d...\n", port) 29 | if err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil); err != nil { 30 | log.Fatal(err) 31 | } 32 | } 33 | 34 | func handleIndex(w http.ResponseWriter, r *http.Request) { 35 | w.Header().Set("Content-Type", "text/html") 36 | fmt.Fprintf(w, ` 37 | 38 | 39 |

URL Shortener

40 |
41 | 42 | 43 | 44 |
45 | 46 | 47 | `) 48 | } 49 | 50 | func handleShorten(w http.ResponseWriter, r *http.Request) { 51 | if r.Method != http.MethodPost { 52 | http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) 53 | return 54 | } 55 | 56 | r.ParseForm() 57 | url := r.Form.Get("url") 58 | 59 | mu.Lock() 60 | defer mu.Unlock() 61 | 62 | shortURL := fmt.Sprintf("%s/s/%d", baseURL, len(shortened)) 63 | shortened[shortURL] = url 64 | 65 | w.Header().Set("Content-Type", "text/html") 66 | fmt.Fprintf(w, ` 67 | 68 | 69 |

Shortened URL

70 |

Original URL: %s

71 |

Short URL: %s

72 | 73 | 74 | `, url, shortURL, shortURL) 75 | } 76 | 77 | func handleShortened(w http.ResponseWriter, r *http.Request) { 78 | mu.Lock() 79 | defer mu.Unlock() 80 | 81 | url, ok := shortened[r.URL.String()] 82 | if !ok { 83 | http.Error(w, "URL not found", http.StatusNotFound) 84 | return 85 | } 86 | 87 | http.Redirect(w, r, url, http.StatusFound) 88 | } 89 | -------------------------------------------------------------------------------- /terraform/16-KubernetesCluster/azure.tf: -------------------------------------------------------------------------------- 1 | # Provider block for Azure 2 | provider "azurerm" { 3 | features {} 4 | } 5 | 6 | # Resource group 7 | resource "azurerm_resource_group" "example" { 8 | name = "k8s-cluster-rg" 9 | location = "eastus" 10 | } 11 | 12 | # Virtual network 13 | resource "azurerm_virtual_network" "example" { 14 | name = "k8s-cluster-vnet" 15 | address_space = ["10.0.0.0/16"] 16 | location = azurerm_resource_group.example.location 17 | resource_group_name = azurerm_resource_group.example.name 18 | 19 | subnet { 20 | name = "k8s-subnet" 21 | address_prefix = "10.0.1.0/24" 22 | } 23 | } 24 | 25 | # Public IP address 26 | resource "azurerm_public_ip" "example" { 27 | name = "k8s-cluster-ip" 28 | location = azurerm_resource_group.example.location 29 | resource_group_name = azurerm_resource_group.example.name 30 | allocation_method = "Static" 31 | } 32 | 33 | # Network interface 34 | resource "azurerm_network_interface" "example" { 35 | name = "k8s-cluster-nic" 36 | location = azurerm_resource_group.example.location 37 | resource_group_name = azurerm_resource_group.example.name 38 | 39 | ip_configuration { 40 | name = "k8s-nic-ip" 41 | subnet_id = azurerm_virtual_network.example.subnet.id 42 | private_ip_address_allocation = "Dynamic" 43 | public_ip_address_id = azurerm_public_ip.example.id 44 | } 45 | } 46 | 47 | # Kubernetes cluster 48 | resource "azurerm_kubernetes_cluster" "example" { 49 | name = "example-aks-cluster" 50 | location = azurerm_resource_group.example.location 51 | resource_group_name = azurerm_resource_group.example.name 52 | dns_prefix = "example-k8s" 53 | kubernetes_version = "1.21.2" 54 | node_resource_group = "k8s-node-rg" 55 | 56 | default_node_pool { 57 | name = "default" 58 | node_count = 1 59 | vm_size = "Standard_DS2_v2" 60 | vnet_subnet_id = azurerm_virtual_network.example.subnet.id 61 | os_disk_size_gb = 30 62 | } 63 | 64 | service_principal { 65 | client_id = var.client_id 66 | client_secret = var.client_secret 67 | } 68 | 69 | tags = { 70 | Environment = "dev" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /terraform/14-RouteTraffic/gcp.tf: -------------------------------------------------------------------------------- 1 | # Define provider 2 | provider "google" { 3 | project = var.project_id 4 | region = var.region 5 | } 6 | 7 | # Create instance template 8 | resource "google_compute_instance_template" "web_template" { 9 | name_prefix = "web-template-" 10 | machine_type = "n1-standard-1" 11 | 12 | disk { 13 | source_image = "debian-cloud/debian-10" 14 | } 15 | 16 | network_interface { 17 | network = "default" 18 | access_config { 19 | // Create a new ephemeral IP for each instance 20 | } 21 | } 22 | 23 | metadata = { 24 | // Install Apache web server 25 | "startup-script" = <<-EOF 26 | #!/bin/bash 27 | apt-get update 28 | apt-get install -y apache2 29 | systemctl enable apache2 30 | systemctl start apache2 31 | EOF 32 | } 33 | 34 | tags = ["web"] 35 | } 36 | 37 | # Create managed instance group 38 | resource "google_compute_instance_group_manager" "web_group" { 39 | name = "web-group" 40 | base_instance_name = "web-instance" 41 | instance_template = google_compute_instance_template.web_template.self_link 42 | target_size = 3 43 | 44 | # Autoscaling policy 45 | auto_scaling_policy { 46 | max_replicas = 5 47 | min_replicas = 2 48 | cool_down_period_sec = 90 49 | cpu_utilization { 50 | target_utilization = 0.6 51 | } 52 | } 53 | 54 | # Health check for load balancer 55 | named_port { 56 | name = "http" 57 | port = 80 58 | } 59 | 60 | target_pools = [google_compute_target_pool.web_pool.self_link] 61 | } 62 | 63 | # Create target pool 64 | resource "google_compute_target_pool" "web_pool" { 65 | name = "web-pool" 66 | region = var.region 67 | 68 | health_checks = [google_compute_http_health_check.web_health_check.self_link] 69 | } 70 | 71 | # Create health check 72 | resource "google_compute_http_health_check" "web_health_check" { 73 | name = "web-health-check" 74 | check_interval_sec = 10 75 | timeout_sec = 5 76 | healthy_threshold = 2 77 | unhealthy_threshold = 3 78 | port = 80 79 | request_path = "/" 80 | } 81 | 82 | # Create forwarding rule for load balancer 83 | resource "google_compute_forwarding_rule" "web_forwarding_rule" { 84 | name = "web-forwarding-rule" 85 | region = var.region 86 | 87 | port_range = "80" 88 | target = google_compute_target_pool.web_pool.self_link 89 | } 90 | -------------------------------------------------------------------------------- /terraform/05-functionapp/azure.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | features {} 3 | } 4 | 5 | resource "azurerm_resource_group" "resource_group" { 6 | name = "function-app-group" 7 | location = "eastus" 8 | } 9 | 10 | resource "azurerm_storage_account" "storage_account" { 11 | name = "functionappstorage" 12 | resource_group_name = azurerm_resource_group.resource_group.name 13 | location = azurerm_resource_group.resource_group.location 14 | account_tier = "Standard" 15 | account_replication_type = "LRS" 16 | } 17 | 18 | resource "azurerm_storage_container" "storage_container" { 19 | name = "functionapp" 20 | resource_group_name = azurerm_resource_group.resource_group.name 21 | storage_account_name = azurerm_storage_account.storage_account.name 22 | container_access_type = "private" 23 | } 24 | 25 | resource "azurerm_function_app" "function_app" { 26 | name = "function-app" 27 | location = azurerm_resource_group.resource_group.location 28 | resource_group_name = azurerm_resource_group.resource_group.name 29 | app_service_plan_id = "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Web/serverfarms/APP_SERVICE_PLAN_NAME" 30 | storage_account_name = azurerm_storage_account.storage_account.name 31 | storage_account_access_key = azurerm_storage_account.storage_account.primary_access_key 32 | https_only = true 33 | version = "~3" 34 | site_config { 35 | always_on = true 36 | } 37 | } 38 | 39 | resource "azurerm_function_app_file_blob" "function_app_blob" { 40 | name = "functionapp.zip" 41 | function_name = azurerm_function_app.function_app.name 42 | storage_account_name = azurerm_storage_account.storage_account.name 43 | storage_account_access_key = azurerm_storage_account.storage_account.primary_access_key 44 | storage_container_name = azurerm_storage_container.storage_container.name 45 | type = "zip" 46 | } 47 | 48 | resource "azurerm_function_app_slot" "function_app_slot" { 49 | name = "function-app-slot" 50 | resource_group_name = azurerm_resource_group.resource_group.name 51 | location = azurerm_resource_group.resource_group.location 52 | function_app_name = azurerm_function_app.function_app.name 53 | } 54 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Azure Devops A to Z 2 | 3 | This repository contains a pre-built devops task aimed at helping beginners start 4 | 5 | DevOps is a software development methodology that emphasizes collaboration and communication between developers and operations teams to facilitate continuous integration, delivery, and deployment of software. The following are some of the key components of DevOps: 6 | 7 | - Collaboration and communication tools: DevOps relies heavily on collaboration and communication between developers, operations teams, and other stakeholders. To facilitate this, DevOps teams use a variety of tools such as chat systems, collaboration platforms, and project management software. 8 | 9 | - Continuous integration (CI) tools: CI tools enable developers to continuously integrate code changes into a central repository, where they are automatically tested and built. Popular CI tools include Jenkins, CircleCI, and Travis CI. 10 | 11 | - Continuous delivery/deployment (CD) tools: CD tools automate the process of deploying code changes to production environments. Popular CD tools include Ansible, Chef, Puppet, and Kubernetes. 12 | 13 | - Infrastructure automation tools: Infrastructure automation tools automate the process of provisioning and configuring infrastructure resources such as servers, networks, and storage. Popular infrastructure automation tools include Terraform, CloudFormation, and Ansible. 14 | 15 | - Monitoring and logging tools: Monitoring and logging tools are used to monitor the performance of applications and infrastructure resources, and to collect and analyze logs and metrics. Popular monitoring and logging tools include Prometheus, Grafana, and ELK Stack. 16 | 17 | - Security tools: DevOps teams use a variety of security tools to ensure that applications and infrastructure resources are secure. These include vulnerability scanners, intrusion detection systems, and penetration testing tools. 18 | 19 | - Agile methodologies: Agile methodologies such as Scrum and Kanban are often used in DevOps to facilitate iterative development and continuous improvement. 20 | 21 | - Culture and organizational practices: Finally, DevOps is as much about culture and organizational practices as it is about tools and methodologies. DevOps teams need to foster a culture of collaboration, communication, and continuous learning, and implement practices such as blameless postmortems and continuous improvement to ensure that they are continuously delivering value to their customers. -------------------------------------------------------------------------------- /terraform/14-RouteTraffic/azure.tf: -------------------------------------------------------------------------------- 1 | # Configure the Azure provider 2 | provider "azurerm" { 3 | features {} 4 | } 5 | 6 | # Create a resource group 7 | resource "azurerm_resource_group" "lb_rg" { 8 | name = "my-lb-resource-group" 9 | location = "West US" 10 | } 11 | 12 | # Create a virtual network 13 | resource "azurerm_virtual_network" "lb_vnet" { 14 | name = "my-lb-vnet" 15 | address_space = ["10.0.0.0/16"] 16 | location = azurerm_resource_group.lb_rg.location 17 | resource_group_name = azurerm_resource_group.lb_rg.name 18 | } 19 | 20 | # Create a subnet 21 | resource "azurerm_subnet" "lb_subnet" { 22 | name = "my-lb-subnet" 23 | resource_group_name = azurerm_resource_group.lb_rg.name 24 | virtual_network_name = azurerm_virtual_network.lb_vnet.name 25 | address_prefixes = ["10.0.1.0/24"] 26 | } 27 | 28 | # Create a public IP address 29 | resource "azurerm_public_ip" "lb_public_ip" { 30 | name = "my-lb-public-ip" 31 | location = azurerm_resource_group.lb_rg.location 32 | resource_group_name = azurerm_resource_group.lb_rg.name 33 | allocation_method = "Dynamic" 34 | } 35 | 36 | # Create a load balancer 37 | resource "azurerm_lb" "lb" { 38 | name = "my-lb" 39 | location = azurerm_resource_group.lb_rg.location 40 | resource_group_name = azurerm_resource_group.lb_rg.name 41 | 42 | frontend_ip_configuration { 43 | name = "PublicIPAddress" 44 | public_ip_address_id = azurerm_public_ip.lb_public_ip.id 45 | } 46 | 47 | backend_address_pool { 48 | name = "my-lb-backend-pool" 49 | } 50 | 51 | probe { 52 | name = "my-lb-probe" 53 | protocol = "Tcp" 54 | port = 80 55 | interval_in_seconds = 5 56 | number_of_probes = 2 57 | } 58 | 59 | load_balancing_rule { 60 | name = "my-lb-rule" 61 | frontend_ip_configuration_name = "PublicIPAddress" 62 | backend_address_pool_name = "my-lb-backend-pool" 63 | probe_name = "my-lb-probe" 64 | protocol = "Tcp" 65 | frontend_port = 80 66 | backend_port = 80 67 | } 68 | } 69 | 70 | # Create a virtual machine scale set 71 | resource "azurerm_linux_virtual_machine_scale_set" "vmss" { 72 | name = "my-vmss" 73 | location = azurerm_resource_group.lb_rg.location 74 | resource_group_name = azurerm_resource_group.lb_rg.name 75 | sku = "Standard_DS1_v2" 76 | 77 | instance_count = 2 78 | 79 | upgrade_policy_mode = "Automatic" 80 | 81 | storage_profile_image_reference { 82 | publisher = "Canonical" 83 | offer = "UbuntuServer" 84 | sku = "18.04-LTS" 85 | version = "latest" 86 | } 87 | 88 | os_disk { 89 | caching = "ReadWrite" 90 | storage_account_type = "Standard_LRS" 91 | } 92 | 93 | network_interface { 94 | name = "vmss-nic" 95 | 96 | ip_configuration { 97 | name = "ipconfig1" 98 | load_balancer_backend_address_pool_ids = [azurerm_lb.lb.backend_address_pool_ids[0]] 99 | load_balancer_inbound_nat_rules_ids = [azurerm_lb.lb.inbound_nat_rules_ids[0]] 100 | subnet_id = azurerm_subnet.lb_subnet.id 101 | } 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /kubernetes/31-All-K8-Resource/resources.yml: -------------------------------------------------------------------------------- 1 | # Pod 2 | apiVersion: v1 3 | kind: Pod 4 | metadata: 5 | name: my-pod 6 | spec: 7 | containers: 8 | - name: my-container 9 | image: nginx 10 | --- 11 | # Deployment 12 | apiVersion: apps/v1 13 | kind: Deployment 14 | metadata: 15 | name: my-deployment 16 | spec: 17 | replicas: 3 18 | selector: 19 | matchLabels: 20 | app: my-app 21 | template: 22 | metadata: 23 | labels: 24 | app: my-app 25 | spec: 26 | containers: 27 | - name: my-container 28 | image: nginx 29 | --- 30 | # Service 31 | apiVersion: v1 32 | kind: Service 33 | metadata: 34 | name: my-service 35 | spec: 36 | selector: 37 | app: my-app 38 | ports: 39 | - name: http 40 | port: 80 41 | targetPort: 80 42 | --- 43 | # ConfigMap 44 | apiVersion: v1 45 | kind: ConfigMap 46 | metadata: 47 | name: my-configmap 48 | data: 49 | key1: value1 50 | key2: value2 51 | --- 52 | # Secret 53 | apiVersion: v1 54 | kind: Secret 55 | metadata: 56 | name: my-secret 57 | type: Opaque 58 | data: 59 | username: YWRtaW4= 60 | password: MWYyZDFlMmU2N2Rm 61 | --- 62 | # PersistentVolume 63 | apiVersion: v1 64 | kind: PersistentVolume 65 | metadata: 66 | name: my-pv 67 | spec: 68 | storageClassName: my-storage-class 69 | capacity: 70 | storage: 1Gi 71 | accessModes: 72 | - ReadWriteOnce 73 | hostPath: 74 | path: /data 75 | --- 76 | # PersistentVolumeClaim 77 | apiVersion: v1 78 | kind: PersistentVolumeClaim 79 | metadata: 80 | name: my-pvc 81 | spec: 82 | storageClassName: my-storage-class 83 | accessModes: 84 | - ReadWriteOnce 85 | resources: 86 | requests: 87 | storage: 1Gi 88 | --- 89 | # StatefulSet 90 | apiVersion: apps/v1 91 | kind: StatefulSet 92 | metadata: 93 | name: my-statefulset 94 | spec: 95 | serviceName: my-service 96 | replicas: 3 97 | selector: 98 | matchLabels: 99 | app: my-app 100 | template: 101 | metadata: 102 | labels: 103 | app: my-app 104 | spec: 105 | containers: 106 | - name: my-container 107 | image: nginx 108 | volumeClaimTemplates: 109 | - metadata: 110 | name: my-pvc 111 | spec: 112 | storageClassName: my-storage-class 113 | accessModes: 114 | - ReadWriteOnce 115 | resources: 116 | requests: 117 | storage: 1Gi 118 | --- 119 | # DaemonSet 120 | apiVersion: apps/v1 121 | kind: DaemonSet 122 | metadata: 123 | name: my-daemonset 124 | spec: 125 | selector: 126 | matchLabels: 127 | app: my-app 128 | template: 129 | metadata: 130 | labels: 131 | app: my-app 132 | spec: 133 | containers: 134 | - name: my-container 135 | image: nginx 136 | --- 137 | # Job 138 | apiVersion: batch/v1 139 | kind: Job 140 | metadata: 141 | name: my-job 142 | spec: 143 | completions: 1 144 | template: 145 | metadata: 146 | name: my-pod 147 | spec: 148 | containers: 149 | - name: my-container 150 | image: nginx 151 | restartPolicy: OnFailure 152 | --- 153 | # CronJob 154 | apiVersion: batch/v1 155 | kind: CronJob 156 | metadata: 157 | name: my-cronjob 158 | spec: 159 | schedule: "*/1 * * * *" 160 | jobTemplate: 161 | spec: 162 | completions: 1 163 | template: 164 | metadata: 165 | name: my-pod 166 | spec: 167 | containers: 168 | - name: my-container 169 | image: nginx 170 | 171 | -------------------------------------------------------------------------------- /kubernetes/30-KubeCtl-50-commandexample/readme.sh: -------------------------------------------------------------------------------- 1 | # Display the version of kubectl. 2 | `kubectl version` 3 | 4 | # Show all pods in the default namespace. 5 | kubectl get pods 6 | 7 | # Show all pods in a specific namespace. 8 | kubectl get pods -n 9 | 10 | # Show detailed information about a specific pod. 11 | kubectl describe pod 12 | 13 | # Create a deployment from a YAML file. 14 | kubectl create -f 15 | 16 | # Update a deployment with a new YAML file. 17 | kubectl apply -f 18 | 19 | # Delete a deployment by name. 20 | kubectl delete deployment 21 | 22 | # Scale a deployment to a specific number of replicas. 23 | kubectl scale deployment --replicas= 24 | 25 | # Create a service from a YAML file. 26 | kubectl create -f 27 | 28 | # Delete a service by name. 29 | kubectl delete service 30 | 31 | # Show all services in the default namespace. 32 | kubectl get services 33 | 34 | # Show all services in a specific namespace. 35 | kubectl get services -n 36 | 37 | # Expose a deployment as a service. 38 | kubectl expose deployment --type= --port= 39 | 40 | # Show all pods with their associated node. 41 | kubectl get pods -o wide 42 | 43 | # Show logs for a specific pod. 44 | kubectl logs 45 | 46 | # Show logs for a specific container within a pod. 47 | kubectl logs -c 48 | 49 | # Show the CPU and memory usage for all pods in the default namespace. 50 | kubectl top pods 51 | 52 | # Show the CPU and memory usage for all pods in a specific namespace. 53 | kubectl top pods -n 54 | 55 | # Copy files to/from a pod. 56 | kubectl cp : 57 | 58 | # Create a secret from a YAML file. 59 | kubectl create -f 60 | 61 | # Delete a secret by name. 62 | kubectl delete secret 63 | 64 | # Show all secrets in the default namespace. 65 | kubectl get secrets 66 | 67 | # Show all secrets in a specific namespace. 68 | kubectl get secrets -n 69 | 70 | # Create a config map from a YAML file. 71 | kubectl create -f 72 | 73 | # Delete a config map by name. 74 | kubectl delete configmap 75 | 76 | # Show all config maps in the default namespace. 77 | kubectl get configmaps 78 | 79 | # Show all config maps in a specific namespace. 80 | kubectl get configmaps -n 81 | 82 | # Open a shell inside a specific pod. 83 | kubectl exec -it -- /bin/bash 84 | 85 | # List all available API resources. 86 | kubectl api-resources 87 | 88 | # Describe a specific API resource. 89 | kubectl api-resources 90 | 91 | # Show all nodes in the cluster. 92 | kubectl get nodes 93 | 94 | # Drain a node to gracefully remove it from the cluster. 95 | kubectl drain 96 | 97 | # Uncordon a previously drained node. 98 | kubectl uncordon 99 | 100 | # Label a node with a specific key and value. 101 | kubectl label nodes = 102 | 103 | # Show all namespaces in the cluster. 104 | kubectl get namespaces 105 | 106 | # Create a new namespace. 107 | kubectl create namespace 108 | 109 | # Delete a namespace by name. 110 | kubectl delete namespace 111 | 112 | # Set the default namespace for future kubectl commands. 113 | kubectl config set-context --current --namespace= 114 | 115 | # Rollout a new version of a deployment. 116 | kubectl rollout restart deployment 117 | 118 | # Rollout a previous version of a deployment. 119 | kubectl rollout undo deployment 120 | 121 | # Show the status of a deployment rollout. 122 | kubectl rollout status deployment 123 | 124 | # Show the history of a deployment rollout. 125 | kubectl rollout history deployment 126 | 127 | # Pause a deployment rollout. 128 | kubectl rollout pause deployment 129 | 130 | # Resume a paused deployment rollout. 131 | kubectl rollout resume deployment 132 | -------------------------------------------------------------------------------- /docker/35-Docker-50-commands/commands.sh: -------------------------------------------------------------------------------- 1 | # 1. Build an image from a Dockerfile 2 | docker build -t myimage:latest . 3 | 4 | # 2. Run a container in interactive mode with a shell 5 | docker run -it --rm myimage:latest sh 6 | 7 | # 3. List all running containers 8 | docker ps 9 | 10 | # 4. List all containers, including stopped ones 11 | docker ps -a 12 | 13 | # 5. Stop a running container 14 | docker stop 15 | 16 | # 6. Start a stopped container 17 | docker start 18 | 19 | # 7. Remove a stopped container 20 | docker rm 21 | 22 | # 8. Remove a running container (forceful) 23 | docker rm -f 24 | 25 | # 9. List all images on the local machine 26 | docker images 27 | 28 | # 10. Remove an image 29 | docker rmi 30 | 31 | # 11. Pull an image from a registry 32 | docker pull 33 | 34 | # 12. Push an image to a registry 35 | docker push 36 | 37 | # 13. Tag an image with a new name 38 | docker tag 39 | 40 | # 14. Create a network 41 | docker network create 42 | 43 | # 15. List all networks 44 | docker network ls 45 | 46 | # 16. Remove a network 47 | docker network rm 48 | 49 | # 17. Attach a container to a network 50 | docker network connect 51 | 52 | # 18. Detach a container from a network 53 | docker network disconnect 54 | 55 | # 19. Run a container with port mapping 56 | docker run -p : 57 | 58 | # 20. Run a container with a specific name 59 | docker run --name 60 | 61 | # 21. Run a container in the background 62 | docker run -d 63 | 64 | # 22. Inspect a container 65 | docker inspect 66 | 67 | # 23. Inspect an image 68 | docker inspect 69 | 70 | # 24. Get logs from a container 71 | docker logs 72 | 73 | # 25. Get container resource usage statistics 74 | docker stats 75 | 76 | # 26. Execute a command in a running container 77 | docker exec 78 | 79 | # 27. Copy files between a container and the local filesystem 80 | docker cp : 81 | 82 | # 28. Set environment variables when running a container 83 | docker run -e = 84 | 85 | # 29. Mount a host directory as a volume in a container 86 | docker run -v : 87 | 88 | # 30. Create a named volume 89 | docker volume create 90 | 91 | # 31. List all volumes 92 | docker volume ls 93 | 94 | # 32. Remove a volume 95 | docker volume rm 96 | 97 | # 33. Run a container with a named volume 98 | docker run -v : 99 | 100 | # 34. Run a container with a temporary writable container layer 101 | docker run --rm -it --name sh 102 | 103 | # 35. Build an image from a Dockerfile in a specific directory 104 | docker build -t 105 | 106 | # 36. Save an image to a tar archive 107 | docker save -o 108 | 109 | # 37. Remove all stopped containers: 110 | docker container prune 111 | 112 | # 38. Remove all dangling images: 113 | docker image prune 114 | 115 | # 39. Remove all unused networks: 116 | docker network prune 117 | 118 | # 40. Remove all unused volumes: 119 | docker volume prune 120 | 121 | # 41. Tag an image with a new name and tag: 122 | docker tag old-image-name:old-image-tag new-image-name:new-image-tag 123 | 124 | # 42. Push an image to a registry: 125 | docker push registry-url/image-name:tag 126 | 127 | # 43. Pull an image from a registry: 128 | docker pull registry-url/image-name:tag 129 | 130 | # 44. Build a Docker image using a Dockerfile: 131 | docker build -t image-name . 132 | 133 | # Show the logs of a running container: 134 | docker logs container-name 135 | 136 | # Stop a running container: 137 | docker stop container-name 138 | 139 | # Pause a running container: 140 | docker pause container-name 141 | 142 | # Unpause a paused container: 143 | docker unpause container-name 144 | 145 | # Restart a stopped container: 146 | docker restart container-name 147 | 148 | # Monitor resource usage of containers: 149 | docker stats container-name --------------------------------------------------------------------------------