Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaganti committed May 5, 2023
0 parents commit 4f5f127
Show file tree
Hide file tree
Showing 23 changed files with 478 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
35 changes: 35 additions & 0 deletions 01-containers/01-manual.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# pull an image from Docker Hub
docker image pull ubuntu:latest

# List all images
docker images

# Run a container interactively
docker run -it ubuntu /bin/bash

# Run a container in the background
docker run -d ubuntu sleep 100

# List running containers
docker container ls

# List all containers on the systems
docker container ls -a

# list all networks
docker network ls

# create a network
docker network create frontend
docker network create backend

# provision voting app
docker run -d -p 6379:6379 --name redis --network backend redis
docker run -d -p 5000:80 --name vote --network frontend docker/example-voting-app-vote
docker network connect backend vote
docker run -d --name db --network=backend -e POSTGRES_HOST_AUTH_METHOD=trust postgres:9.4
docker run -d --name worker --network=backend docker/example-voting-app-worker
docker run -d --name result --network=frontend -p 5001:80 docker/example-voting-app-result
docker network connect backend result
13 changes: 13 additions & 0 deletions 01-containers/02-compose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# install compose plugin
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

# Check compose version
docker compose version

# Run a compose service
docker compose up
35 changes: 35 additions & 0 deletions 01-containers/03-swarm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Firewall rules
ufw allow 22/tcp
ufw allow 2376/tcp
ufw allow 2377/tcp
ufw allow 7946/tcp
ufw allow 7946/udp
ufw allow 4789/udp

# Initialize swarm
docker swarm init

# Join swarm
docker swarm join --token <Token> <Leader-IP>:2377

# Checlk swarm nodes
docker node ls

# Enabling swarm creates an overlay network
docker network ls

# Create a service
docker service create --replicas 2 --name nginx --publish 8080:80 nginx:latest

# Create declaratively
docker stack deploy -c docker-stack.yaml voting-app

# Inspect services
docker stack services voting-app
docker service ps voting-app_vote

# Working with stack
docker stack ps voting-app
docker stack rm voting-app
44 changes: 44 additions & 0 deletions 01-containers/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
services:
redis:
image: redis:latest
networks:
- backend

vote:
image: docker/example-voting-app-vote:latest
ports:
- 5000:80
networks:
- frontend
- backend
depends_on:
- redis

db:
image: postgres:9.4
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
networks:
- backend

worker:
image: docker/example-voting-app-worker
networks:
- backend
depends_on:
- db

result:
image: docker/example-voting-app-result
networks:
- frontend
- backend
ports:
- 5001:80
depends_on:
- db
- worker

networks:
frontend:
backend:
49 changes: 49 additions & 0 deletions 01-containers/docker-stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3.9"
services:
redis:
image: redis:latest
networks:
- backend

vote:
image: docker/example-voting-app-vote:latest
ports:
- 5000:80
networks:
- frontend
- backend
depends_on:
- redis
deploy:
replicas: 2

db:
image: postgres:9.4
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
networks:
- backend

worker:
image: docker/example-voting-app-worker
networks:
- backend
depends_on:
- db

result:
image: docker/example-voting-app-result
networks:
- frontend
- backend
ports:
- 5001:80
depends_on:
- db
- worker
deploy:
replicas: 2

networks:
frontend:
backend:
7 changes: 7 additions & 0 deletions 02-get-started/kubectl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Check if kubectl is working
kubectl version --output=json

# Get help
kubectl explain pods
9 changes: 9 additions & 0 deletions 02-get-started/minikube.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
New-Item -Path 'c:\' -Name 'minikube' -ItemType Directory -Force
Invoke-WebRequest -OutFile 'c:\minikube\minikube.exe' -Uri 'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe' -UseBasicParsing

$oldPath = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)
if ($oldPath.Split(';') -inotcontains 'C:\minikube'){
[Environment]::SetEnvironmentVariable('Path', $('{0};C:\minikube' -f $oldPath), [EnvironmentVariableTarget]::Machine)
}

minikube start
11 changes: 11 additions & 0 deletions 03-pods/pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
tier: frontend
spec:
containers:
- name: nginx
image: nginx
8 changes: 8 additions & 0 deletions 03-pods/pods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kubectl apply -f .\vote.yml
kubectl apply -f .\result.yml

kubectl get pods

kubectl describe pods vote

kubectl exec -it vote -- sh
20 changes: 20 additions & 0 deletions 04-replicasets/rs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
spec:
selector:
matchLabels:
tier: frontend
replicas: 4
template:
metadata:
name: nginx-2
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx
22 changes: 22 additions & 0 deletions 05-deployments/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deploment
labels:
tier: frontend
app: nginx
spec:
selector:
matchLabels:
tier: frontend
replicas: 3
template:
metadata:
name: nginx-2
labels:
app: nginx
tier: frontend
spec:
containers:
- name: nginx
image: nginx
15 changes: 15 additions & 0 deletions 06-services/clusterip/db-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: db
name: db
spec:
type: ClusterIP
ports:
- name: "db-service"
port: 5432
targetPort: 5432
selector:
app: db

33 changes: 33 additions & 0 deletions 06-services/clusterip/db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: db
name: db
spec:
replicas: 1
selector:
matchLabels:
app: db
template:
metadata:
labels:
app: db
spec:
containers:
- image: postgres:15-alpine
name: postgres
env:
- name: POSTGRES_USER
value: postgres
- name: POSTGRES_PASSWORD
value: postgres
ports:
- containerPort: 5432
name: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: db-data
volumes:
- name: db-data
emptyDir: {}
15 changes: 15 additions & 0 deletions 06-services/clusterip/redis-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: redis
name: redis
spec:
type: ClusterIP
ports:
- name: "redis-service"
port: 6379
targetPort: 6379
selector:
app: redis

28 changes: 28 additions & 0 deletions 06-services/clusterip/redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: redis
name: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- image: redis:alpine
name: redis
ports:
- containerPort: 6379
name: redis
volumeMounts:
- mountPath: /data
name: redis-data
volumes:
- name: redis-data
emptyDir: {}
15 changes: 15 additions & 0 deletions 06-services/clusterip/result-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: result
name: result
spec:
type: NodePort
ports:
- name: "result-service"
port: 5001
targetPort: 80
nodePort: 31001
selector:
app: result
Loading

0 comments on commit 4f5f127

Please sign in to comment.