Docker

My Workplay on Docker and Kubernetes. Ref : https://github.com/Rohithv07/DockerCasts

View the Project on GitHub

Docker and Kubernetes

My Workplay on docker

Commands to remember :

Kubernetes

Local Setup

Docker Compose Kubernetes
Each entry can optionally get docker compose to build an image Kubernetes expects all images to already be built
Each entry represents a container we want to create One config file per object we want to create
Each entry defines the n/w requirements (Ports) We have to manually sets up all n/w

Note

Get a simple container running on our local K8s cluster running

Config file used to create Objects for example StatefulSet, ReplicaController, Pod, Service. Object will serve different functionalities like running container, monitoring a container, setting up nw etc.

Important Takeaways
Kubernetes is a system to deploy containerized apps
Nodes are individual machines or vm's that run containers
Masters are machines or vm's with a set of programs to manage nodes
Kubernetes didn't build our images - it got them from somewhere else
Kubernetes (the master) decided where to run each container - each node can run a dissimilar set of containers
To deploy something, we update the desired state of the master with a config file
The master works constantly to meet you desired state
Limitations on Updating Config file
Can only change spec.containers[*].image
Can only change spec.initContainers[*].image
Can only change spec.activeDeadlineSeconds
Can only change spec.tolerations

Difference between Pods and Deployment

Pods Deployment
Run a single set of containers that are very close Run a set of identical pods (one or more)
Good for one-off dev purposes Monitors the state of each pod updating as necessary
Rarely used directly in production Good for dev and production

- kubectl delete -f <configfile> :- remove an object (like an imperative update)

Force pods to repull an image without changing the image tag issue#33664 kubernetes repo in github

Configure your VM to use the docker server

minikube docker-env 

#produces the following output
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://ip:2376"
export DOCKER_CERT_PATH="path"
export MINIKUBE_ACTIVE_DOCKERD="minikube"

# To point your shell to minikube's docker-daemon, run:
# eval $(minikube -p minikube docker-env)


Why mess with docker in node :(

For example kubectl logs or kubectl exec -t sh to enable a shell etc.

Path of introducing multicontainer project to K8s world

ClusterIP vs NodePort

Combine ClusterIP and Deployment yaml file

Here we need to give --- 3 consecutive dashes to separate them

apiVersion: apps/v1
kind: Deployment
metadata:
  name: server-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      component: server
  template:
    metadata:
      labels:
        component: server
    spec:
      containers:
        - name: server
          image: imageName
          ports:
            - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: server-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: server
  ports:
    - port: 5000
      targetPort: 5000

Persistent Volume Claim (PVC in K8S world)

Volumes in K8S world (Don’t get confused with docker volumes which is different with K8S volume)

Volumes vs Persistent volume

Persistent volume vs Persistent Volume Claim (PVC)

Access Modes

Secrets

LoadBalancer

Ingress

Some other commands