Skip to main content

kubernetes

### notes ###

cheat sheet source - https://github.com/dennyzhang/cheatsheet-kubernetes-A4

Common Commands

Events & Metrics

NameCommand
View all eventskubectl get events --all-namespaces
List Events sorted by timestampkubectl get events –sort-by=.metadata.creationTimestamp

Node Maintenance

NameCommand
Mark node as unschedulablekubectl cordon $NDOE_NAME
Mark node as schedulablekubectl uncordon $NDOE_NAME
Drain node in preparation for maintenancekubectl drain $NODE_NAME

Namespace & Security

NameCommand
List authenticated contextskubectl config get-contexts, ~/.kube/config
Set namespace preferencekubectl config set-context <context_name> --namespace=<ns_name>
Load context from config filekubectl get cs --kubeconfig kube_config.yml
Switch contextkubectl config use-context <cluster-name>
Delete the specified contextkubectl config delete-context <cluster-name>
List all namespaces definedkubectl get namespaces
List certificateskubectl get csr
Check user privilegekubectl –as=system:serviceaccount:ns-denny:test-privileged-sa -n ns-denny auth can-i use pods/list
Check user privilegekubectl auth can-i use pods/list
ReferenceLink: kubernetes yaml templates

Network

NameCommand
Temporarily add a port-forwardingkubectl port-forward redis-134 6379:6379
Add port-forwaring for deploymentkubectl port-forward deployment/redis-master 6379:6379
Add port-forwaring for replicasetkubectl port-forward rs/redis-master 6379:6379
Add port-forwaring for servicekubectl port-forward svc/redis-master 6379:6379
Get network policykubectl get NetworkPolicy

Patch

NameSummary
Patch service to loadbalancerkubectl patch svc $svc_name -p '{"spec": {"type": "LoadBalancer"}}'

Extenstions

NameSummary
Enumerates the resource types availablekubectl api-resources
List api groupkubectl api-versions
List all CRDkubectl get crd
List storageclasskubectl get storageclass

Components & Services

Services on Master Nodes

NameSummary
kube-apiserverexposes the Kubernetes API from master nodes
etcdreliable data store for all k8s cluster data
kube-schedulerschedule pods to run on selected nodes
kube-controller-managernode controller, replication controller, endpoints controller, and service account & token controllers

Services on Worker Nodes

NameSummary
kubeletmakes sure that containers are running in a pod
kube-proxyperform connection forwarding
Container RuntimeKubernetes supported runtimes: Docker, rkt, runc and any OCI runtime-spec implementation.

Addons: pods and services that implement cluster features

NameSummary
DNSserves DNS records for Kubernetes services
Web UIa general purpose, web-based UI for Kubernetes clusters
Container Resource Monitoringcollect, store and serve container metrics
Cluster-level Loggingsave container logs to a central log store with search/browsing interface

Tools

NameSummary
kubectlthe command line util to talk to k8s cluster
kubeadmthe command to bootstrap the cluster
kubefedthe command line to control a Kubernetes Cluster Federation
Kubernetes ComponentsLink: Kubernetes Components