f:: kubectl
- Kubernetes
- Production-Grade Container Orchestration
Standard Components of Kubernetes
These are the minimum components required for a Kubernetes cluster:
Master Nodes
API Server | - Entry point for cluster - Processes requests and updates etcd - Performs authentication / authorization |
Controller Manager | - Daemon process that implements the control loops built into Kubernetes - e.g. rolling deployments |
Scheduler | Decides where pods should run based on multiple factors - affinity, available resources, labels, QoS, etc. |
Worker Nodes
Agents on every worker
Kubelet | Instantiate pods (group of one or more containers) using PodSpec and insures all pods are running and healthy |
Kube Proxy | - Network proxy and load balancer for Kubernetes Services - Interacts with containers - e.g. Docker |
Standard Add-ons for Kubernetes
These are the Kubernetes add-ons that are required for all but Hello World solutions.
kubectl | Official command line for Kubernetes |
Kube-DNS | - Provisioned as a pod and a service on Kubernetes - Every service gets a DNS entry in Kubernetes - Kube-DNS resolves DNS of all services in the clusters |
Web UI (Dashboard) | Official GUI of Kubernetes |
Metrics Server | - Provides API for cluster wide usage metrics like CPU and memory utilization - Feeds the usage graphs in the Kubernetes Dashboard (GUI) |
Kubernetes Constructs
Namespaces | Virtual segmentation of a single cluster |
Roles | Role based access controls for Kubernetes cluster |
Nodes | Infrastructure fabric of Kubernetes (host of worker and master components) |
Pods | Logical grouping of one or more containers that is managed by Kubernetes |
ReplicaSets | Continuous loop that ensures given number of pods are running |
Ingresses | Manages external HTTP traffic to hosted service |
Deployments | Manages a ReplicaSet, pod definitions/updates and other concepts |
Services | Logical layer that provides IP/DNS/etc. persistence to dynamic pods |
StatefulSets | Suited for stateful applications like databases |
DaemonSet | Ensures a copy of a Pod is running across a set of nodes in a cluster |
Commands
kubectl version | Find the version of the Kubectl command line |
kubectl API version | Print the version of the API Server. |
kubectl cluster-info | IP addresses of master and services |
kubectl cluster-info dump --namespaces | List all the namespace used in Kubernetes. |
kubectl cordon NODE | Mark node as unschedulable. Used for maintenance of cluster. |
kubectl uncordon NODE | Mark node as scheduled. Used after maintenance. |
kubectl drain NODE | Removes pods from node via graceful termination for maintenance. |
kubectl drain NODE --dryrun=true | Find the names of the objects that will be removed |
kubectl taint nodes node1 key=value:NoSchedule | Taint a node so they can only run dedicated workloads or certain pods that need specialized hardware. |
kubectl run nginx --image=nginx --port=8080 | Start instance of nginx |
kubectl get RESOURCE | Print information on Kubernetes resources |
kubectl explain RESOURCE | Print documentation of resources |
kubectl scale --replicas=COUNT rs/foo | Scale a ReplicaSet (rs) named foo |
kubectl rolling-update app-v1 -f app-v2.json | Perform rolling update |
kubectl label pods foo GPU=true | Update the labels of resources |
kubectl delete pod foo | Delete foo pods |
kubectl delete svc foo | Delete foo services |
kubectl create service clusterip foo --tcp=5678:8080 | Create a clusterIP for a service named foo |
kubectl autoscale deployment foo --min=2 --max=10 --cpupercent=70 | Autoscale pod foo with a minimum of 2 and maximum of 10 replicas when CPU utilization is equal to or greater than 70% |
Kubernetes Clusters
Kubernetes coordinates a highly available cluster of computers that are connected to work as a single unit. The abstractions in Kubernetes allow you to deploy containerized applications to a cluster without tying them specifically to individual machines. Kubernetes automates the distribution and scheduling of application containers across a cluster in an efficient way.
A Kubernetes cluster consists of two types of resources:
- The Master is responsible for managing the cluster. The master coordinates all activities in your cluster, such as scheduling applications, maintaining applications’ desired state, scaling applications, and rolling out new updates.
- Nodes are the workers that run applications. Each node has a Kubelet, which is an agent for managing the node and communicating with the Kubernetes master. The node should also have tools for handling container operations, such as Docker or rkt.
Kubernetes Pods
When you create a deployment, Kubernetes created a Pod to host your application instance. A Pod is a Kubernetes abstraction that represents a group of one or more application containers (such as Docker or rkt), and some shared resources for those containers. Those resources include:
- Shared storage, as Volumes
- Networking, as a unique cluster IP address
- Information about how to run each container, such as the container image version or specific ports to use
Pods are the atomic unit on the Kubernetes platform. When we create a Deployment on Kubernetes, that Deployment creates Pods with containers inside them (as opposed to creating containers directly). Each Pod is tied to the Node where it is scheduled, and remains there until termination (according to restart policy) or deletion. In case of a Node failure, identical Pods are scheduled on other available Nodes in the cluster.
Kubernetes Services
A Service in Kubernetes is an abstraction which defines a logical set of Pods and a policy by which to access them. Services enable a loose coupling between dependent Pods. The set of Pods targeted by a Service is usually determined by a LabelSelector.
Although each Pod has a unique IP address, those IPs are not exposed outside the cluster without a Service. Services allow your applications to receive traffic. Services can be exposed in different ways by specifying a type
in the ServiceSpec:
- ClusterIP (default)
- NodePort
- LoadBalancer
- ExternalName