Kubernetes
1. What Kubernetes is
Kubernetes is a platform which allows to run and manage containerized applications.
2. Kubernetes concepts
Annotation
Allows to store addition information with a Kubernetes object; can have a big size.
ConfigMap
Stores environment variables.
CronJob
Used for background tasks run on time; under different conditions may run 0, 1 or more than 1 time.
DaemonSet
Runs a copy of a pod on each node; usually used for logging and metric collection.
Deployment
Updates a replica set or a pod; implements rolling updates and rolbacks.
Job
Creates one or more pods and ensures they are successfully terminated after execution; can restart if it fails.
HorizontalPodAutoscaler
Scales deployment or replica set basing on CPU usage or other metrics.
Ingress
Is a router that accepts incoming traffic and maps URLs to services; can implement TLS termination.
Label
Are key-value pairs that are used to identify Kubernetes objects.
Name
Every object in Kubernetes has a human-readable name and unique id (UID).
Namespace
Allow to organize a set of Kubernetes resources inside a Kubernetes cluster into a virtual cluster; nodes and persistent volumes doesn't belong to a namespace.
Pod
Runs one or more containers with the same IP Address.
ReplicaSet
Allows to run multiple copies of a pod for higher availability.
Secret
Used to store backend credentials.
Service
Allows to address a collection of pods for network communication.
Volume
Is a directory that is accessible to all containers in a pod.
Liveness probe
Liveness probe checks if a pod is working: if not then Kubernetes restarts the pod.
Readiness probe
Readiness probe checks if a pod is able to serve requests: if not then Kubernetes will not send requests to the service. Pod can accept traffic only if all containers are ready.
3. Kubernetes commands
Useful aliases
kp='kubectl -n my-namespace --kubeconfig ~/.kube/config-prod'
kp-port-forward='kp port-forward svc/elasticsearch-master 9200:9200'
Show pods in all namespaces
kp get pod -A
Show services
kp get service
Show deployments
kp get deployment
Show nodes
kp get node
Show persistence volume claims
kp get pvc
Run shell in a pod container
kp exec -ti pod-name -c container-name -- /bin/bash
Copy a file from a pod
kp cp -c container-name pod-name:/srv/app/file_name.log file_name.log
Double dash in a command
The double dash ( -- ) in kubectl command separates the arguments you want to pass to the command from the kubectl arguments.
4. Kubernetes service types
ClusterIP
Default service type; exposes service by IP inside Kubernetes cluster.
NodePort
Exposes service externally using each node IP address and a predefined port.
LoadBalancer
Exposes service externally with a load balancer per one service.
ExternalName
Works like a proxy for an external service by DNS name.
5. Kubernetes volume types
EmptyDir
Not persistent (when pod is restarted its data is lost), starts empty and allows to share folder between containers of the same pod (when explicitly mounted).
GitRepo
Not persistent, starts with data from a public Git repo and allows to share folder between containers of the same pod
Secret
In-memory directory to pass credentials to pods.
HostPath
Persistent on a node, usually is used with DaemonSet.
PersistentVolume
Persistent, created by admin with a given technology (like GCEPersistentDisk), capacity and access modes.
PersistentVolumeClaim
Abstracts away from a given technology by pointing to PersistentVolume.