\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{Mansour Javaher (mansourj)} \pdfinfo{ /Title (kubernetes-ckad.pdf) /Creator (Cheatography) /Author (Mansour Javaher (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}{Mansour Javaher (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}Mansour Javaher (mansourj) \\ \uline{cheatography.com/mansourj} \\ \uline{\seqsplit{www}.mansour.co.nz/} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 26th November, 2024.\\ Updated 26th November, 2024.\\ 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{5.5264 cm} x{11.7436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{General commands}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{alias k=kubectl} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} k \seqsplit{api-resources} & List all resource types in the cluster \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} k explain node & Introspect documentation for a resource \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} k explain node.spec & Dive deeper into a resource specification \tn % Row Count 7 (+ 2) \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}{Pods}} \tn % Row 0 \SetRowColor{LightBackground} k get po & List pods \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} k get po -o wide & Include additional details \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} k get po \textless{}pod name\textgreater{} -o yaml & Output a specific pod in YAML format \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} k get po \textless{}pod-name\textgreater{} -o yaml \textgreater{} pod.yaml & Output a specific pod in YAML to a file \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} k get pods -n \textless{}pod-name\textgreater{} & Pods in a specific namespace \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} k get pods -{}-all-namespaces & List pods across all namespaces \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} kubectl get pods -A & Short version of `-{}-all-namespaces` \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} kubectl get events -A | grep error & All events in all namespaces with errors \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} k get pod -{}-show-labels & Show labels for pods \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} k get pod -l \textless{}key\textgreater{}=\textless{}value\textgreater{} & Filter pods by label \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} k describe po \textless{}pod name\textgreater{} & Get details about a pod \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} k delete po \textless{}pod name\textgreater{} & Delete a specific pod \tn % Row Count 23 (+ 2) % Row 12 \SetRowColor{LightBackground} k delete po -{}-all & Delete all pods in the namespace \tn % Row Count 25 (+ 2) % Row 13 \SetRowColor{white} k apply -f \textless{}pod.yaml\textgreater{} -n \textless{}namespace-name\textgreater{} & Apply pod configuration \tn % Row Count 28 (+ 3) % Row 14 \SetRowColor{LightBackground} k edit po \textless{}pod-name\textgreater{} & Edit a pod \tn % Row Count 29 (+ 1) % Row 15 \SetRowColor{white} k run nginx -{}-image=nginx -{}-dry-run=client -o yaml \textgreater{} pod.yaml & Generate pod YAML imperatively \tn % Row Count 33 (+ 4) \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}{Pods (cont)}} \tn % Row 16 \SetRowColor{LightBackground} k exec {[}pod-name{]} -{}- {[}command{]} & Execute a command in a pod \tn % Row Count 2 (+ 2) % Row 17 \SetRowColor{white} k exec nginx -{}- ls / & Execute ls command in the root / \tn % Row Count 4 (+ 2) % Row 18 \SetRowColor{LightBackground} k exec -it nginx -{}- /bin/sh & Get a shell in the container \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Key Notes: \newline - Pods can have initContainers for pre-task operations. \newline - Use restartPolicy (Always, OnFailure, Never) in the pod spec.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{9.3258 cm} x{7.9442 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Replica set}} \tn % Row 0 \SetRowColor{LightBackground} k apply -f \textless{}replicaset-definition.yaml\textgreater{} & Create/Update a ReplicaSet \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} k get rs & List ReplicaSets \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} k get rs -o wide & Get ReplicaSet details \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} k delete rs \textless{}replicaset-name\textgreater{} & Delete a ReplicaSet \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} k scale rs \textless{}replicaset-name\textgreater{} -{}-replicas=6 & Scale replicas \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} k edit rs \textless{}replicaset-name\textgreater{} & Edit a ReplicaSet \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} k describe rs \textless{}replicaset-name\textgreater{} & Get details about a ReplicaSet \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} k delete po \textless{}rs-po-name\textgreater{} & Delete all pods under ReplicaSet \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} k get rs \textless{}rs-name\textgreater{} -o yaml \textgreater{} rs.yaml & Export a ReplicaSet to a YAML file \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Editing ReplicaSet \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.8077 cm} x{8.4623 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{ConfigMap}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k create cm \textless{}cm-name\textgreater{} -{}-from-literal=key=value} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k create cm \textless{}cm-name\textgreater{} -{}-from-file=\textless{}path\textgreater{}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} k describe cm \textless{}cm-name\textgreater{} & Read config map detals \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{ConfigMaps in Kubernetes \newline ConfigMaps can be injected into Pods as: \newline - Environment variables: Use `configMapKeyRef` (for specific keys) or `configMapRef`/`envFrom` (for the whole ConfigMap). \newline - Files in a volume: Mount the ConfigMap as a volume for your application to read.} \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}{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 (values are 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} echo -n 'string' | base64 & How to decode to base64 \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} echo -n 'encoded string' | base64 -{}-decode & how to decode a base64 string \tn % Row Count 16 (+ 3) \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) % Row 3 \SetRowColor{white} kubectl taint nodes master \seqsplit{node-role.kubernetes.io/master:NoSchedule-} & Remove the taint on the master node that has the NoSchedule effect \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} kubectl taint nodes foo dedicated- & Remove all taints with the key dedicated from the node named foo: bash Copy code \tn % Row Count 17 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Tolerations in the spec section have properties like key, operator, value, and effect. Their values are written inside quotation marks ("").} \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}{x{4.3175 cm} x{12.9525 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Monitoring}} \tn % Row 0 \SetRowColor{LightBackground} k top no & Resource usage for nodes \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} k top po & Resource usage for pods \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 & nginx pod and with an ENV set to app=web \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) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k expose deploy \textless{}deploy-name\textgreater{} -{}-port=80 -{}-type=NodePort} \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k expose deploy \textless{}deploy-name\textgreater{} -{}-port=80 -{}-type=NodePort -{}-dry-run=client -o yaml \textgreater{} service.yml} \tn % Row Count 12 (+ 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}{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} k rollout history deploy nginx -{}-revision=2 & to get detailed history for a specific revision.T \tn % Row Count 16 (+ 3) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k rollout undo deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 17 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k rollout undo deploy \textless{}deployment-name\textgreater{} -{}-to-revision=1} \tn % Row Count 19 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k rollout pause deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 20 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k rollout resume deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 21 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k delete deploy \textless{}deployment-name\textgreater{}} \tn % Row Count 22 (+ 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 24 (+ 2) % Row 18 \SetRowColor{LightBackground} k scale deploy \textless{}deployment-name\textgreater{} -{}-replicas=3 & To scale up / down a deployment. Not recorded in revision history. \tn % Row Count 28 (+ 4) % 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 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 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{k edit deploy \textless{}deployment-name\textgreater{} -n \textless{}namespace-name\textgreater{}} \tn % Row Count 2 (+ 2) % Row 21 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{k expose deploy \textless{}deployment-name\textgreater{} -{}-port=80 -{}-type=NodePort|ClusterIp} \tn % Row Count 4 (+ 2) % Row 22 \SetRowColor{LightBackground} k autoscale deployment \textless{}deployment-name\textgreater{} -{}-max 6 -{}-min 3 -{}-cpu-percent 50 & Autoscale deployment \tn % Row Count 8 (+ 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}