First deploy

Let us start to understand how kubectl works

kubectl get RESOURCE
get
returns the list of the required resource
(e.g. pods, namespaces, nodes)
kubectl get namespaces

NAME					STATUS	AGE
default					Active	39m
kube-node-lease			Active	39m
kube-public				Active	39m
kube-system				Active	39m
kubernetes-dashboard	Active	34m
	

Let us try to deploy our first pod

kubectl run NAME --image=CONTAINER_IMAGE
run
requires to deploy a pod on the cluster

We deploy a simple pod of one container

kubectl run nginx --image=nginx

pod/nginx created
	
kubectl get pods

NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          10s
	

Our first pod is deployed 🥳

Now, we understand why we should not
deploy pods in this way

If a pod fails then no particular operation will be undertaken by the cluster to rescue it

We need to introduce some other resources to guarantee high availability (HA) of the deployed services (stand by)

Let us introduce another useful command
to get all the information about a specific resource

kubectl describe RESOURCE_TYPE RESOURCE_NAME
describe
returns a lot of information about the required resource
kubectl describe pod nginx

Name:         nginx
Namespace:    default
Priority:     0
Node:         sailor_uranus/172.17.0.2
[...]
Status:       Running
IP:           172.18.0.3
Containers:
  nginx:
    Image:          nginx:latest
    Ready:          True
    Restart Count:  0
[...]
	

One of the most useful pieces of information provided
by the command describe can be found at the bottom


Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  25s   default-scheduler  Successfully assigned default/nginx to sailor_uranus
  Normal  Pulling    22s   kubelet            Pulling image "nginx:latest"
  Normal  Pulled     21s   kubelet            Successfully pulled image "nginx:latest" in 1.519s
  Normal  Created    20s   kubelet            Created container nginx
  Normal  Started    20s   kubelet            Started container nginx
	

This list reports all the events about the resource;
it is really useful for debug

An important concept under K8s,
that you may have noticed:

Any resource can be defined in a declarative way

We can get the declarative definition of a resource
exploiting the command get

kubectl get RESOURCE_TYPE RESOURCE_NAME -o=yaml
get RESOURCE_TYPE RESOURCE_NAME
returns all resource specifications in the required format (yaml or json)
kubectl get pods nginx -o=yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  [...]
spec:
  containers:
  - image: nginx:latest
    imagePullPolicy: Always
    name: nginx
    resources: {}
    [...]
	

If we have a declarative yaml (or json) file
of a resource we can deploy it

kubectl apply (-f FILENAME | -k DIRECTORY)
apply
given a resource(s) specifications file(or directory)
this will be deployed if it does not exist yet