*********************************** VIM SETUP *********************************** set smarttab set expandtab set shiftwidth=4 set tabstop=4 set number *********************************** k8s Quick Start/Useful Commands *********************************** kubectl run [podNAME] --image=[imageNAME] --restart=Never --rm --command -it -- env #Creates pod with name [podNAME], image used is [imageNAME], when comman is executed it will not restart, will remove after complition, --command allows to pass command for execution, will output stdout, passed command kubectl creat -f [fileNAME.yml] #Creates pod with give parameters from [fileNAME.yml] kubectl create ns [namespaceNAME] #Creates namespaces kubectl set image [resource]/[resourceNAME] [containerNAME]=[imageNAME] #Set new image in resource {pod deployment daemonset} without editing yaml kubectl get pods #Gives pods brife information default namespace kubectl get pods -A #Gives pods brife information about all namespaces kubectl get pods [podNAME] #Gives pods with name brife information about it kubectl get ns #Shows all namespaces kubectl get ns [namespaceNAME] #Gives brife info of namespace [namespaceNAME] kubectl get ns [namespaceNAME] -o yaml #Gives all properties of namespace [namespaceNAME] in yaml format kubectl get all #Prints out all information default namespace kubectl get deployments [deploymentNAME] --show-lables #Shows labels which are set on [deploymentNAME] kubectl get deployments --selector [lableNAME] #Prints out all deployments which has lable [lableNAME] kubectl get all --selector [lableNAME] #Prints out everything {pod,deployment,service...} which has lable [lableNAME] kubectl get pod -l [lableNAME]=[lableVALUE],[lableNAME1]=[lableVALUE1],[lableNAME2]=[lableVALUE2] #This print pods with multiple lables in this example it will print pods of this three lables {lableNAME,lableNAME2,lableNAME2} kubectl describe {deployment|rs|pods} #Gives information about all pods,rs and deployment on host kubectl describe [podNAME] #Gives information about [podNAME] pod on host kubectl describe deployment [deploymentNAME] #Gives information about [deploymentNAME] deployment on host kubectl delete pod [podNAME] #Deletes type=pod and [podNAME] kubectl run [NAME_DEPLOYMENT] --image=[imageNAME] #Creates deployment from nginx image with name of [s kubectl get rs [replicasetNAME] -o yaml #This gives full information about replica kubectl logs [podNAME] #Gives log information about [podNAME] pod on host kubectl scale --replicas=3 deployment [deploymentNAME] #This increas number of pods in deployment and replicasets kubectl create deployment --dry-run --image=[imageNAME] --output=yaml [deploymentNAME] > [NAME.yml] #Creates deployment yaml file to work with using image [imageNAME] and setting deployment name [deploymentNAME] kubectl get deployment [deploymentNAME] -o yaml #Gives output of [deploymentNAME] configuration in yaml format kubectl edit deployment [deploymentNAME] #Editing deployment yaml format, after quiting editor the changes are executing kubectl get deployment --show-labels #Outputs all deployments with there lableso kubectl label deployment [deploymentNAME] state=[lableNAME] #Makes lable on depoyment [deploymentNAME] with lable name [lableNAME] kubectl rollout history deployment [deploymentNAME] #Gives information about deployments revision kubectl rollout history deployment [deploymentNAME] --revision=[desiredREVISION] #Rollbacks to [desiredREVISION] of deployment [deploymentNAME] kubectl create cm [configmapNAME] --from-file [fileNAME] #Creates Configmap from file kubectl run [podNAME] --image=[imageNAME] --dry-run=client -o yaml --restart=Never -- /bin/sh -c "while true; do echo hello; echo hello again;done" > [fileNAME.yaml] kubectl explain pod --recursive #Prints out the options which could be used for creating yaml file. Get the list of resourses all fields and sub-fields kubectl create --namespace=[namespaceNAME] [resourseTYPE] [resourseNAME] #Creates [resourceTYPE] and places it in defined namespace [namespaceNAME] kubectl logs [podNAME] #Prints [podNAME] container stdout kubectl logs -p -c [containerNAME] [podNAME] #Return snapshot of previous terminated [containerNAME] container logs from pod [podNAME] kubectl logs -f -c [containerNAME] podNAME] #Begin streaming following the logs of the [containerNAME] container in pod [podNAME] kubectl logs [jobNAME]/[containerNAME] #Prints output of job [jobNAME] containers kubectl exec -it [podNAME] -c [containerNAME] -- sh #In pod [podNAME] inside of it container [containerNAME] executes command sh passed after -- and is attached to interactive shell kubectl set resources [deploymentNAME/podNAME] -c=[containerNAME] --limits=cpu=200m --limits=memory=512Mi #Set CPU 200m and Memory 512m limit on deploymentNAME/podNAME with containerNAME kubectl get [resourceNAME] -o custom-columns=NAMESPACE:metadata.namespace,NAME:metadata.name #This parses [resourceNAME] json format, on all or specified and gives us two output in columns set in custom-columns option, first is NAMESPACE:metadata.namespace second NAME:metadata.name kubectl run [podNAME] --image=[imageNAME] --port=[portNUMBER] --expose #Expose pod with 80 port and create correct service with cluster IP for this pod. kubectl get [podNAME] -l 'env in (dev,prod)' #Get the pods with labels env=dev and env=prod kubectl label [podNAME] nginx-dev{1..3} app=nginx #label app=nginx for all the pods named nginx-dev1 nginx-dev2 nginx-dev3 in range of 3 kubeadm token create --print-join-command #Pring command for nodes to join cluster cat fileNAME | base64 -w 0 #Will remove newlines echo "CERT" | base64 -d | openssl x509 -text #Output the values from Certifivate in human readable format cat [manifestNAME.yaml] | k get -f - #This will output list of all files which where mentioned in [manifestNAME.yaml] file kubectl exec -it -n kube-system kube-apiserver-controlplane -- kube-apiserver -h | grep -i enable-admission-plugins ##This commands shows us the current enabled admission controllers kubectl delete pod protmerheus-k8s-{0,1} ##This command will delete pod with name protmerheus-k8s-0 and protmerheus-k8s-1