\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{mansourj} \pdfinfo{ /Title (kubernetes-ckad.pdf) /Creator (Cheatography) /Author (mansourj) /Subject (Kubernetes - CKAD Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Kubernetes - CKAD Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{mansourj} via \textcolor{DarkBackground}{\uline{cheatography.com/153462/cs/32989/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}mansourj \\ \uline{cheatography.com/mansourj} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 1st November, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{4.6629 cm} x{12.6071 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Alias}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{alias k=kubectl} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k api-resources} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} k explain node & explain is introspection documentation \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k explain node.spec} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Pods}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get po} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get po -o wide} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} k get po \textless{}pod name\textgreater{} -o yaml & output in yaml format \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} k get po \textless{}pod-name\textgreater{} -o yaml \textgreater{} pod.yaml & output in yaml format in a file \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get pods -n \textless{}pod-name\textgreater{}} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get pods -{}-all-namespaces} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} kubectl get pods -A & shorter version of `-{}-all-namespaces` \tn % Row Count 10 (+ 2) % Row 7 \SetRowColor{white} kubectl get events -A | grep error & all events in all namespaces with errors \tn % Row Count 12 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get pod -{}-show-labels} \tn % Row Count 13 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get pod -l \textless{}key\textgreater{}=\textless{}value\textgreater{}} \tn % Row Count 14 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k describe po \textless{}pod name\textgreater{}} \tn % Row Count 15 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k delete po \textless{}pod name\textgreater{}} \tn % Row Count 16 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k delete po -{}-all} \tn % Row Count 17 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k apply -f \textless{}pod.yaml\textgreater{} -n \textless{}namespace-name\textgreater{}} \tn % Row Count 18 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k edit po \textless{}pod-name\textgreater{}} \tn % Row Count 19 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k run nginx -{}-image=nginx -{}-dry-run=client -o yaml \textgreater{} pod.yaml} \tn % Row Count 21 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k exec {[}POD{]} -{}- {[}COMMAND{]}} \tn % Row Count 22 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k exec nginx -{}- ls /} \tn % Row Count 23 (+ 1) % Row 18 \SetRowColor{LightBackground} k exec -it nginx -{}- /bin/sh & Get a shell to the container running in your Pod \tn % Row Count 26 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{If you are not given a pod definition file but a pod, you may extract the definition to a file. \newline \newline In a multicontainer pod, containers are created and destroyed together. \newline \newline initContainers is a property under spec and it has same sub properties like name, image etc. \newline \newline kubectl run command creates the pod and not deployment. There is no imperative command like kubectl create po for pod creation. \newline \newline Pods have a property called restartPolicy whose values can be Always, Never or OnFailure} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Replica set}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k apply -f \textless{}replicaset-definition.yaml\textgreater{}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get rs} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get rs -o wide} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get rs -o yaml} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k delete rs \textless{}replicaset-name\textgreater{}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k scale rs \textless{}replicaset-name\textgreater{} -{}-replicas=6} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k edit rs \textless{}replicaset-name\textgreater{}} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k describe rs \textless{}replicaset-name\textgreater{}} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} k delete po \textless{}rs-po-name\textgreater{} & Delete all pods under rs \tn % Row Count 10 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get rs \textless{}rs-name\textgreater{} -o yaml \textgreater{} rs.yaml} \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\# Editing RS \newline - Either delete and re-create the ReplicaSet or \newline - Update the existing ReplicaSet and then delete all PODs, so new ones with the correct image will be created. \newline \newline The value for labels in spec.selector clause and spec.template.metadata should match in replicaset.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{ConfigMap}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get cm} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} k describe cm \textless{}cm-name\textgreater{} & to check key-value pairs in config map \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} k create cm \textless{}cm-name\textgreater{} -{}-from-file=\textless{}path to file\textgreater{} & colon or equals to as delimiter between keys and values \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k create cm \textless{}cm-name\textgreater{} -{}-from-file=\textless{}directory\textgreater{}} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create cm \textless{}cm-name\textgreater{} -{}-from-literal=\textless{}key1\textgreater{}=\textless{}value1\textgreater{} -{}-from-literal=\textless{}key2\textgreater{}=\textless{}value2\textgreater{}} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\# Properties to remember: \newline configmapkeyref / env, configMapRef / envFrom, volume \newline \newline \# Pods can consume ConfigMaps as environment variables or as configuration files in a volume mounted on one or more of its containers for the application to read. \newline When ConfigMap is created from a file (k create cm \textless{}cm name\textgreater{} -{}-from-file= ) and when that ConfigMap is mounted as volume, \newline then the entire file is available at mount point for the pod. \newline \newline \# Injected into the Pod.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{7.9442 cm} x{9.3258 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Secret}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get secrets} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get secret -{}-all-namespaces} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} k describe secret \textless{}secret-name\textgreater{} & This shows the attributes in secret but hides the values. \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} k get secret \textless{}secret-name\textgreater{} -o yaml & To view the values (encoded). \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create secret generic \textless{}secret-name\textgreater{} -{}-from-literal=\textless{}key1\textgreater{}=\textless{}value1\textgreater{} -{}-from-literal=\textless{}key2\textgreater{}=\textless{}value2\textgreater{}} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k create secret generic \textless{}secret-name\textgreater{} -{}-from-file=\textless{}path to file\textgreater{}} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{echo -n 'string' | base64} \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{echo -n 'encoded string' | base64 -{}-decode} \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Properties to remember: secretkeyref / env, secretref / envFrom, volume \newline \newline A secret can be injected into a pod as file in a volume mounted on one or more of its containers or as container environment variables. \newline \newline While creating secret with the declarative approach (yaml), you must specify the secret key and value in encoded format. \newline When we create secret using imperative approach, secret keys and values are encoded on their own (and decoded as well).} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Taints (on nodes) and Tolerations (on pods)}} \tn % Row 0 \SetRowColor{LightBackground} k taint nodes {[}node\_name{]} \textless{}key\textgreater{}=\textless{}value\textgreater{}:{[}NoSchedule|NoExecute|PreferNoSchedule{]} & Taint effect defines what happens to pods that do not tolerate this taint. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k taint no node01 spray=mortein:NoSchedule} \tn % Row Count 5 (+ 1) % Row 2 \SetRowColor{LightBackground} k describe nodes node01 | grep -i "taint" & To check taints on a node \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{The property tolerations under spec has properties like key, operator, value and effect and their values come inside "" \newline \newline Remove the taint on master, which currently has the taint effect of NoSchedule \newline \$ k taint no master \seqsplit{node-role.kubernetes.io/master:NoSchedule-} \newline \newline Remove from node 'foo' all the taints with key 'dedicated' \newline \$ k taint no foo dedicated-} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Horizontal Pod Auto Scaler}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get hpa} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k delete hpa \textless{}hpa-name\textgreater{}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k autoscale deploy nginx -{}-min=5 -{}-max=10 -{}-cpu-percent=80} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Monitoring}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k top no} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k top po} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k top pod -{}-namespace=default | head -2 | tail -1 | cut -d " " -f1} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k top po -{}-sort-by cpu -{}-no-headers} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Events}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get events} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get events -n kube-system} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get events -w} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{DaemonSets}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get ds} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get ds -{}-all-namespaces} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k describe ds \textless{}ds-name\textgreater{} -n \textless{}ns-name\textgreater{}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k describe ds \textless{}ds-name\textgreater{} -o yaml} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Environment Variables}} \tn % Row 0 \SetRowColor{LightBackground} k run nginx -{}-image=nginx -{}-env=app=web & \# Create an nginx pod and set an environment variable \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{env and envFrom property is an array. \newline env property takes two properties - name and value. value takes only string and will always come in double quotes.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{7.2534 cm} x{10.0166 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Service}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k apply -f \textless{}svc.yaml\textgreater{}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get svc} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get svc -{}-show-labels} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get svc -o wide} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get svc -o yaml} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} k describe svc \textless{}service-name\textgreater{} & To get to know about port, target port etc. \tn % Row Count 7 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k delete svc \textless{}service-name\textgreater{}} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Node}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get no} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get no -o wide} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k describe no \textless{}node-name\textgreater{}} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Network Policy}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get netpol} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k describe netpol \textless{}name\textgreater{}} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Note: While creating network policy, make sure that not only network policy is applied to the correct object but also that it allows access from (ingress) / to correct object (egress). \newline \newline labels and selectors are used. \newline \newline An empty podSelector selects all pods in the namespace.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{7.2534 cm} x{10.0166 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Annotations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k annotate po nginx desc="Hello World"} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k annotate po nginx author=Avnish} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} k annotate po nginx desc- & Remove this annotation from the pod \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k annotate no \textless{}node-name\textgreater{}} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Labels \& Selectors}} \tn % Row 0 \SetRowColor{LightBackground} k get {[}pod|deploy|all{]} -{}-show-labels & Show labels \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} k get label {[}node|pod|deploy|etc{]} \textless{}key\textgreater{}=\textless{}value\textgreater{} & Syntax \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} k label pod nginx env=lab & To label pod \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} k label deploy my-webapp tier=frontend & To label deployment \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} k label node node01 size=large & To label nodes \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} k label po nginx \textless{}key\textgreater{}- & Remove the label \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} k label po nginx env=lab1 -{}-overwrite & To overwrite a label \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get po -{}-selector=app=App1} \tn % Row Count 16 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get po -{}-selector=app!=App1} \tn % Row Count 17 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get all -{}-selector=env=prod} \tn % Row Count 18 (+ 1) % Row 10 \SetRowColor{LightBackground} k get po -{}-selector=env=prod,bu=finance,tier=frontend & Equivalent of \&\& in programming languages \tn % Row Count 21 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Volumes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get pv} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k describe pv} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k delete pv \textless{}pv-name\textgreater{}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get pvc} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k describe pvc} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k delete pvc \textless{}pvc-name\textgreater{}} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Ingress}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get ingress} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k describe ingress \textless{}ingress name\textgreater{}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k edit ingress \textless{}ingress name\textgreater{}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k apply -f \textless{}ingress.yaml\textgreater{}} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.2896 cm} x{8.9804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Logging}} \tn % Row 0 \SetRowColor{LightBackground} k logs -f \textless{}pod-name\textgreater{} \textless{}container-name\textgreater{} & Follow the logs \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} k logs \textless{}pod-name\textgreater{} -{}-previous & Dump pod logs for a previous instantiation of a container \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k logs -{}-tail=20 \textless{}pod-name\textgreater{}} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Deployments}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create deploy nginx -{}-image=nginx -{}-replicas=2} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get deploy} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get deploy -n \textless{}namespace-name\textgreater{}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get deploy \textless{}deployment-name\textgreater{} -o yaml | more} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get deploy -o wide} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k describe deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k apply -f deploy.yaml} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} k apply -f deploy.yaml -{}-record & Record the change-cause in revision history \tn % Row Count 11 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k rollout status deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k rollout history deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k rollout history deploy nginx -{}-revision=2 \# to get detailed history for a specific revision.} \tn % Row Count 15 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k rollout undo deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 16 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k rollout undo deploy \textless{}deployment-name\textgreater{} -{}-to-revision=1} \tn % Row Count 18 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k rollout pause deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 19 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k rollout resume deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 20 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k delete deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 21 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k create deploy nginx -{}-image=nginx -{}-dry-run=client -o yaml \textgreater{} deploy.yaml} \tn % Row Count 23 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k scale deploy \textless{}deployment-name\textgreater{} -{}-replicas=3 \# To scale up / down a deployment. Not recorded in revision history.} \tn % Row Count 26 (+ 3) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k create deploy \textless{}deployment-name\textgreater{} -{}-image=redis -n \textless{}namespace-name\textgreater{}} \tn % Row Count 28 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k edit deploy \textless{}deployment-name\textgreater{} -n \textless{}namespace-name\textgreater{}} \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Deployments (cont)}} \tn % Row 21 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k expose deploy \textless{}deployment-name\textgreater{} -{}-port=80 -{}-type=NodePort|ClusterIp} \tn % Row Count 2 (+ 2) % Row 22 \SetRowColor{white} k autoscale deployment \textless{}deployment-name\textgreater{} -{}-max 6 -{}-min 3 -{}-cpu-percent 50 & Autoscale deployment \tn % Row Count 6 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Deployments can be paused and resumed. When paused, no changes are recorded to revision history. \newline \newline RollingUpdateStrategy in define upto how many pods can be down/up during the update at a time. \newline spec.strategy.type==RollingUpdate|Recreate \newline spec.strategy.rollingUpdate.maxUnavailable \newline spec.strategy.rollingUpdate.maxSurge \newline \newline updating images or new deployements, triggers rollout. A new rollout creates a new deployment revision.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Service Account}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create sa \textless{}sa-name\textgreater{}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get sa} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get sa \textless{}sa-name\textgreater{} -o yaml} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} k describe sa \textless{}sa-name\textgreater{} & Fetch token: gives secret name \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} k describe secret \textless{}secret-name\textgreater{} & Fetch token: gives token stored in secret \tn % Row Count 8 (+ 3) % Row 5 \SetRowColor{white} k run nginx -{}-image=nginx -{}-serviceaccount=myuser -{}-dry-run=client -o yaml \textgreater{} pod.yaml & nginx pod that uses 'myuser' as a service account \tn % Row Count 13 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{When we use service account inside the pod, the secret for that service account is mounted as volume inside the pod. \newline \newline Property to remember: spec -\textgreater{} serviceAccountName \# set at pod level \newline Injected into the Pod. \newline For a deployment, can set service account in pod template. \newline \newline A user makes a request to API server through k using user account. \newline A process running inside a container makes a request to API server using service account. \newline A service account just like user account has certain permissions.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{CronJobs}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get cj} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} k create cj busybox -{}-image=busybox -{}-schedule="{\emph{/1 }} {\emph{ }} *" -{}- /bin/sh -c "date; echo Hello from Kubernetes cluster" & cron job with image busybox that runs on a schedule and writes to standard output \tn % Row Count 7 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{In a cronjob, there are 2 templates - one for job and another for pod. \newline \newline In a cronjob, there are 3 spec sections - one for cronjob, one for job and one for pod (in order). \newline \newline Properties to remember: spec -\textgreater{} \seqsplit{successfulJobHistoryLimit}, spec -\textgreater{} failedJobHistoryLimit} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{10.5347 cm} x{6.7353 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Jobs}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create job busybox -{}-image=busybox -{}- /bin/sh -c "echo hello;sleep 30;echo world"} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get jobs} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} k logs busybox-qhcnx & pod under job \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k delete job \textless{}job-name\textgreater{}} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{restartPolicy defaults to Never. \newline \newline Job has 2 spec sections - one for job and one for pod (in order). \newline \newline restartPolicy has to be OnFailure or Never. If the restartPolicy is OnFailure, a failed container will be re-run on the same pod. If the restartPolicy is Never, a failed container will be re-run on a new pod. \newline \newline Job properties to remember: completions, backoffLimit, parallelism, activeDeadlineSeconds, restartPolicy. \newline \newline By default Pods in a job are created in sequence} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{9.1531 cm} x{8.1169 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Namespace}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get ns} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k get ns -o yaml} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create ns \textless{}namespace-name\textgreater{}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k apply -f \textless{}namespace.yaml\textgreater{}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k get po -n kube-system} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k describe ns \textless{}namespace-name\textgreater{}} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k delete ns \textless{}namespace-name\textgreater{}} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} k config set-context \$(k config current-context) -{}-namespace=dev & To switch to a namespace permanently \tn % Row Count 11 (+ 4) % Row 8 \SetRowColor{LightBackground} k run redis -{}-image=redis -n \textless{}namespace-name\textgreater{} & Create/run in a specific ns \tn % Row Count 14 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k exec -it \textless{}pod-name\textgreater{} -n \textless{}namespace-name\textgreater{} -{}- sh} \tn % Row Count 15 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create ns \textless{}namespace-name\textgreater{} -{}-dry-run=client -o yaml} \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}