Skip to content

Instantly share code, notes, and snippets.

@antonmry
Created May 3, 2022 10:42
Show Gist options
  • Save antonmry/c30df97e07e7003a8367cd90c02c8a03 to your computer and use it in GitHub Desktop.
Save antonmry/c30df97e07e7003a8367cd90c02c8a03 to your computer and use it in GitHub Desktop.
Docker and Kubernetes workshop

Docker

Source: https://gist.github.com/bradtraversy/89fad226dc058a41b596d586022a9bd3#file-docker-help-md

Containers

docker version
docker info
docker help

docker container run -it -p 80:80 nginx
docker run -it -p 80:80 nginx

docker container run -d -p 80:80 nginx
docker container run -d -p 80:80 --name nginx-server nginx

docker container ls
docker ps

docker container logs nginx-server
docker container stats nginx-server

docker container stop nginx-server
docker container start nginx-server

docker container run -it --name nginx-bash-test nginx bash
docker container exec -it nginx-server bash

docker container rm nginx-server
docker container rm -f nginx-server
docker rm -f $(docker ps -aq)

Images

docker image ls
docker pull [IMAGE]

docker image build -t nginx-website .
docker container run -d -p 80:80 nginx-website

docker rm -f $(docker ps -aq)
docker image rm nginx-website

Docker Compose

docker-compose up
docker-compose up -d
docker-compose ps
docker-compose stop
docker-compose start
docker-compose down

Kubernetes

Source: https://cloud.google.com/kubernetes-engine/docs/quickstarts/deploy-app-container-image

gcloud config set project pixie-playground
gcloud config set "compute/zone" europe-west3-a
gcloud config set "compute/region" europe-west3

gcloud container clusters create antonmry-pixie-cluster --num-nodes=2 --machine-type=e2-standard-4
gcloud container clusters get-credentials antonmry-pixie-cluster
kubectl get nodes
kubectl get pods --all-namespaces
kubectl apply -f deployment.yaml
kubectl get deployments
kubectl get pods

kubectl apply -f service.yaml
kubectl get services

kubectl scale deployment helloworld-gke --replicas=3
kubectl autoscale deployment helloworld-gke --cpu-percent=80 --min=1 --max=5
gcloud container clusters delete antonmry-pixie-cluster 
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-gke
spec:
replicas: 1
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello-app
image: nginx:latest
ports:
- containerPort: 80
env:
- name: PORT
value: "80"
version: '2'
services:
nginx:
image: nginx
ports:
- '80:80'
FROM nginx:latest
WORKDIR /usr/share/nginx/html
COPY index.html index.html
Hello world!
apiVersion: v1
kind: Service
metadata:
name: hello
spec:
type: LoadBalancer
selector:
app: hello
ports:
- port: 80
targetPort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment