All-Things-Docker-and-Kubernetes

Exam Tips and Tricks

Recommendations

General tips:

Checkin process:

Moved to remote desktop environment in June 2022:

Copy/paste:

Terminal:

Miscellaneous recommendations:

Use shortnames and aliases/variables:

Persist Vim settings

Create the ~/.vimrc file.

vim ~/.vimrc  
set expandtab  
set tabstop=2
set shiftwidth=2

This now becomes the default Vim settings when you open a terminal:

Use kubectl to view examples

kubectl run --help
Create and run a particular image in a pod.

Examples:
  # Start a nginx pod.
  kubectl run nginx --image=nginx

  # Start a hazelcast pod and let the container expose port 5701.
  kubectl run hazelcast --image=hazelcast/hazelcast --port=5701

  # Start a hazelcast pod and set environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the
container.
  kubectl run hazelcast --image=hazelcast/hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"

  # Start a hazelcast pod and set labels "app=hazelcast" and "env=prod" in the container.
  kubectl run hazelcast --image=hazelcast/hazelcast --labels="app=hazelcast,env=prod"

  # Dry run. Print the corresponding API objects without creating them.
  kubectl run nginx --image=nginx --dry-run=client

  # Start a nginx pod, but overload the spec with a partial set of values parsed from JSON.
  kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'

  # Start a busybox pod and keep it in the foreground, don't restart it if it exits.
  kubectl run -i -t busybox --image=busybox --restart=Never

  # Start the nginx pod using the default command, but use custom arguments (arg1 .. argN) for that command.
  kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>

  # Start the nginx pod using a different command and custom arguments.
  kubectl run nginx --image=nginx --command -- <cmd> <arg1> ... <argN> 

Sample scenarios

You can use dry run to generate a basic yaml file, then make any necessary changes on that file, and then use the modified file to create the required resources.

Scenario 1: Create resource

Create an nginx pod, set the request memory to 1M and the CPU to 500m can be solved with the following commands:

Save a shortcut:

export do="--dry-run=client -o yaml" 

Then we can do the following:

k run nginx --image=nginx --dry-run=client -oyaml > pod.yaml
vi pod.yaml 
k create -f pod.yaml 

From this:

kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yml

Instead we can just run this:

k run nginx --image=nginx $do > pod.yml

Scenario 2: Deleting pods without waiting

Save shortcut:

export now="--force --grace-period 0"  

Then delete pod podname

k delete pod podname $now 

Scenario 3: Temporary pods

Create a busybox pod, run wget command in it to test a k8s service created in the previous step.

Since this is only for testing, we don’t need the pod to persist after it has completed running wget. We cna use the -rm option which will delete the pod immediately after running the specified command.

$ k run busybox --image=busybox -it -rm -- sh

If you don't see a command prompt, try pressing enter.
/ # wget -O- 172.17.254.255

API Overview

Others:

Resources