Kubernetes

"Kubernetes is an open source container orchestration engine for automating deployment, scaling, and management of containerized applications."

Getting started: curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - sudo tee </dev/null deb https://apt.kubernetes.io/ kubernetes-xenial main EOF sudo apt -qq update sudo apt install -y ebtables ethtool docker.io sudo apt install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl sudo apt install -y bash-completion kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl >/dev/null source <(kubectl completion bash)

Creating a single control-plane cluster: sudo kubeadm init --pod-network-cidr 192.168.0.0/16 mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml kubectl get node kubectl describe node abc123-node-1a0a kubectl taint nodes --all node-role.kubernetes.io/master- sudo kubeadm join --token : --discovery-token-ca-cert-hash sha256:
 * The control-plane node is the machine where the control plane components run, including etcd (the cluster database) and the API server (which the kubectl CLI communicates with)
 * You need to choose a pod network add-on to use:
 * Calico (--pod-network-cidr=192.168.0.0/16)
 * Flannel (--pod-network-cidr=10.244.0.0/16)
 * To be able to schedule pods on the control-plane node, e.g. for a single-machine Kubernetes cluster for testing:
 * To add new nodes, where your workloads (containers and pods, etc) run, to your cluster run the following as root:

To run an application in the cluster: kubectl run hello-world --image=gcr.io/google-samples/node-hello:1.0 --labels="run=load-balancer-example" --port=8080 --replicas=2

To display information about a Deployment: kubectl get deployments hello-world kubectl describe deployments hello-world

To save information about a Deployment in yaml format: kubectl get deployments hello-world --export -o yaml > hello-world.yaml

To replace a Deployment using a yaml file: kubectl replace -f hello-world.yaml

To display information about a ReplicaSet objects: kubectl get replicasets kubectl describe replicasets

To create a Service object that exposes a deployment: kubectl expose deployment hello-world --type=NodePort --name=example-service

To display information about a Service: kubectl get services example-service kubectl describe services example-service

To list all Pods in all namespaces in plain-text output format with additional information: kubectl get pods --all-namespaces --output=wide

To exec a command inside a Pod: kubectl exec hello-world-1234-1234 -- printenv

To update the size of a Deployment: kubectl scale deployment hello-world --replicas=3

To print the log of a Pod: kubectl logs hello-world-1234-1234

To delete a Service: kubectl delete services example-service

To delete Deployment, ReplicaSet, and Pods that are running an application: kubectl delete deployment hello-world

To re-create a Deployment from a yaml file: kubectl create -f hello-world.yaml

To delete a Pod: kubectl delete pods hello-world-1234-1234

To list all Namespaces: kubectl get namespace

To create a new Namespace: kubectl create namespace name

To get the cluster configuration: kubectl config view

To display endpoint information about the master and services in the cluster: kubectl cluster-info

To creates a proxy server between localhost and the Kubernetes API Server: kubectl proxy --api-prefix=/ &

To list all Secrets: kubectl get secrets --all-namespaces

To view the details of a Secret: kubectl describe secret name

To create a ConfigMap, which is basically a set of key-value pairs: kubectl create configmap name --from-literal=mykey=myvalue --from-file=./myfile --from-file=./mydirectory/

To view the content of a ConfigMap: kubectl get configmap name -o yaml

Source: Kubernetes Documentation