- It's a container orchestration
- Many servers act like one
- Released in 2015
- Runs on top of Docker
- Provides CLI/API to manage container across servers
- kubectl
- Services
- Clouds: Google Engine, etc
- Many vendors with a "custom distribution"
- Not every solution needs orchestration
- Orchestration is designed to automate changes and monitor the state of things
- Another alternative: Docker Swarm
- Distributions:
- Docker Enterprise
- Rancher
- OpenShift
- Canonical
- VMWare PKS
- Custom vendor distributions pack other tools with Kubernetes
- Most distributions are up to date with the official Kubernetes
- Swarm
- is easy to deploy/manage
- comes with Docker
- 80/20 rule: has 20% of features of Kubernetes for 80% of the use cases
- it runs anywhere Docker runs
- secure by default
- easier to troubleshoot
- Kubernetes
- has more features and it's more flexible
- clouds deploy/manage it for you
- multiple distributions
- widest adoption and community
- flexible
- Kubernetes: the whole orchestration system
- K8s or Kube for short
- Kubectl: CLI to configure Kubernetes and manage apps
- "cube control" => official pronunciation
- Node: single server in the Kubernetes cluster
- Kubelet: Kubernetes agent running on nodes
- Control Plane: Set of containers that manage the cluster
- Includes API server, scheduler, controller managed, etcd, etc.
- Sometimes called "master"
- Pod: one or more containers running together on one node
- Basic unit of deployment
- Controller: for creating/updating pods and other objects
- Many types:
- Deployment
- ReplicaSet
- StatefulSet
- DaemonSet
- Job
- CronJob
- Many types:
- Service: network endpoint to connect to a pod
- A stable address for pod(s)
- Created on top of existing pods
- CoreDNS: allow us to resolve services by name
- Types of services:
- ClusterIP (default):
- only reachable from within the cluster (nodes and pods)
- single, internal virtual IP allocated
- pods can reach service on apps port number
- NodePort:
- high port allocated on each node
- port is open on every node's IP
- anyone can connect (if they can reach the node)
- other pods neet to be updated to this port
- LoadBalancer:
- mostly used on the cloud
- controls a load balancer endpoint external to the cluster
- only available when infra provider gives you a load balancer
- creates CreatePort + ClusterIP services, tells load balancer to send to NodePort
- ExternalName:
- Adds CNAME DNS record to CoreDNS only
- Not used for Pods, but giving pods a DNS name to use for something outside Kubernetes
- Kubernetes Ingress: ???
- ClusterIP (default):
- Namespace: filtered group of objects in cluster
kubectl version
kubectl run
- Creates the pod, the replicaset and the deployment
- Default command gives only 1 replica
kubectl create
kubectl apply
kubectl scale deploy/my-apache --replicas 2
kubectl run my-nginx --image nginx
kubectl run my-apache --image httpd
kubectl run httpenv --image bretfisher/httpenv
kubectl get service
- Look up what IP was allocated
- Only accessible inside the cluster (you'll see no external IP address filled)
- Look up what IP was allocated
kubectl get pods
kubectl get pods -w
kubectl get all
kubectl delete deployment my-nginx
kubectl scale deploy/my-apache --replicas 2
kubectl scale deployment my-apache --replicas 2
kubectl logs deployment/my-apache
kubectl logs deployment/my-apache --follow --tail 1
kubectl logs -l run=my-apache
: Filter logs by deployment labelkubectl describe pod/my-apache-6b4dc47d85-7f9m9
kubectl delete pod/my-apache-6b4dc47d85-7f9m9
- It'll trigger the controller so it'll make sure it the specified replicas running
kubectl expose
: creates a service for existing ports. It's a way to expose them to the outside worldkubectl expose deployment/httpenv --port 8888
kubectl run --generator=run-pod/v1 tmp-shell --rm -it --image bretfisher/netshoot -- bash
curl -X GET httpenv:8888
kubectl expose deployment/httpenv --port 8888 --name httpenv-np --type NodePort
curl -X GET localhost:32088
kubectl expose deployment/httpenv --port 8888 --name httpenv-lb --type LoadBalancer
curl -X GET localhost:8888
kubectl delete services/httpenv services/httpenv-np services/httpenv-lb
kubectl delete deployment/httpenv