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
SchedulerDecides where pods should run based on multiple factors - affinity, available resources, labels, QoS, etc.

Worker Nodes

Agents on every worker

KubeletInstantiate 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.

kubectlOfficial 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

NamespacesVirtual segmentation of a single cluster
RolesRole based access controls for Kubernetes cluster
NodesInfrastructure fabric of Kubernetes (host of worker and master components)
PodsLogical grouping of one or more containers that is managed by Kubernetes
ReplicaSetsContinuous loop that ensures given number of pods are running
IngressesManages external HTTP traffic to hosted service
DeploymentsManages a ReplicaSet, pod definitions/updates and other concepts
ServicesLogical layer that provides IP/DNS/etc. persistence to dynamic pods
StatefulSetsSuited for stateful applications like databases
DaemonSetEnsures a copy of a Pod is running across a set of nodes in a cluster

Commands

kubectl versionFind the version of the Kubectl command line
kubectl API versionPrint the version of the API Server.
kubectl cluster-infoIP addresses of master and services
kubectl cluster-info dump --namespacesList all the namespace used in Kubernetes.
kubectl cordon NODEMark node as unschedulable. Used for maintenance of cluster.
kubectl uncordon NODEMark node as scheduled. Used after maintenance.
kubectl drain NODERemoves pods from node via graceful termination for maintenance.
kubectl drain NODE --dryrun=trueFind the names of the objects that will be removed
kubectl taint nodes node1 key=value:NoScheduleTaint a node so they can only run dedicated workloads or certain pods that need specialized hardware.
kubectl run nginx --image=nginx --port=8080Start instance of nginx
kubectl get RESOURCEPrint information on Kubernetes resources
kubectl explain RESOURCEPrint documentation of resources
kubectl scale --replicas=COUNT rs/fooScale a ReplicaSet (rs) named foo
kubectl rolling-update app-v1 -f app-v2.jsonPerform rolling update
kubectl label pods foo GPU=trueUpdate the labels of resources
kubectl delete pod fooDelete foo pods
kubectl delete svc fooDelete foo services
kubectl create service clusterip foo --tcp=5678:8080Create a clusterIP for a service named foo
kubectl autoscale deployment foo --min=2 --max=10 --cpupercent=70Autoscale 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