Autocomplétion:

apt-get install bash-completion
echo 'source <(kubectl completion bash)' >>~/.bashrc
source ~/.bashrc

Alias pour tapez "ku" au lieu de "kubectl" :

echo "alias ku='kubectl' " >> ~/.bashrc
echo "alias kuzybox='kubectl run -i --rm --tty debug --image=busybox --restart=Never -- sh' " >> ~/.bashrc
source ~/.bashrc    

Installation des utilitaires kubectx et kubens:

sudo git clone https://github.com/ahmetb/kubectx /opt/kubectx
sudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx
sudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens
echo "source /opt/kubectx/completion/kubectx.bash" >> ~/.bashrc
echo "source /opt/kubectx/completion/kubens.bash" >> ~/.bashrc
source ~/.bashrc

Test de votre connexion au cluster :

$ kubectl cluster-info
Kubernetes master is running at https://pcxxxxxxj.c1.gra7.k8s.ovh.net
CoreDNS is running at https://pxxxxxxj.c1.gra7.k8s.ovh.net/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://pxxxxj.c1.gra7.k8s.ovh.net/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Lister les éléments de votre cluster:

$ kubectl get all
NAME                  TYPE           CLUSTER-IP    EXTERNAL-IP      PORT(S)        AGE
service/hello-world   LoadBalancer   10.3.89.177   51.21x.xxx.xx2   80:31634/TCP   13d
service/kubernetes    ClusterIP      10.3.0.1      <none>           443/TCP        2d15h

NAME                     DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/fluentd   0         0         0       0            0           type=prod       6d19h

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-world-deployment   0/0     0            0           2d16h

NAME                                                DESIRED   CURRENT   READY   AGE
replicaset.apps/hello-world-deployment-6fcbdc8f79   0         0         0       2d16h

Pour commencer simplement sans se ruiner, nous avons un seul noeud (équivalent à une machine dans l'ancien monde) :

$ ku get node
NAME                                        STATUS   ROLES    AGE   VERSION
node-43b8731c-9a45-452f-8521-e9c683196b7d   Ready    <none>   13d   v1.18.6

Un déploiement hello-world a été installé et le résultat est un pod ( containeur créé à prtir d'une image linux alpine ) qui tourne sur le cluster:

$ ku get pod 
NAME                                      READY   STATUS    RESTARTS   AGE
hello-world-deployment-6fcbdc8f79-t9ngq   1/1     Running   0          4m30s

Connectons nous au shell linux sur le pod pour connaître son adresse IP interne:

$ ku exec -it hello-world-deployment-6fcbdc8f79-t9ngq -- sh
/ # ip a s 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
3: eth0@if27: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP 
    link/ether c2:99:f0:cf:40:d4 brd ff:ff:ff:ff:ff:ff
    inet 10.2.0.11/32 scope global eth0
       valid_lft forever preferred_lft forever

On veut se déplacer dans le cluster sur un pod avec plein d'outils :

kubectl run -i --tty --rm debug --image=busybox --restart=Never -- sh
If you don't see a command prompt, try pressing enter.
/ # wget  10.2.0.11:80
Connecting to 10.2.0.11:80 (10.2.0.11:80)
saving to 'index.html'
index.html           100% |************************************************************************|   241  0:00:00 ETA
'index.html' saved
/ # 

Depuis un autre terminal, détail du pod busybox:

$ ku get pod -o wide
NAME    READY   STATUS    RESTARTS   AGE   IP          NODE                                        NOMINATED NODE   READINESS GATES
debug   1/1     Running   0          41s   10.2.0.14   node-43b8731c-9a45-452f-8521-e9c683196b7d   <none>           <none>

$ ku describe pod debug
Name:         debug
Namespace:    default
Priority:     0
Node:         node-43b8731c-9a45-452f-8521-e9c683196b7d/51.210.250.33
Start Time:   Mon, 21 Sep 2020 15:26:52 +0200
Labels:       run=debug
Annotations:  cni.projectcalico.org/podIP: 10.2.0.14/32
Status:       Running
IP:           10.2.0.14
IPs:
  IP:  10.2.0.14
Containers:
  debug:
    Container ID:  docker://72bb1d9e18724beebccde975ae5c2ba3c3d5f405f61b8451b6fd75445471fb0f
    Image:         busybox
    Image ID:      docker-pullable://busybox@sha256:d366a4665ab44f0648d7a00ae3fae139d55e32f9712c67accd604bb55df9d05a
    Port:          <none>
    Host Port:     <none>
    Args:
      sh
    State:          Running
      Started:      Mon, 21 Sep 2020 15:26:54 +0200
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-hxsbv (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-hxsbv:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-hxsbv
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From                                                Message
  ----    ------     ----  ----                                                -------
  Normal  Scheduled  66s   default-scheduler                                   Successfully assigned default/debug to node-43b8731c-9a45-452f-8521-e9c683196b7d
  Normal  Pulling    65s   kubelet, node-43b8731c-9a45-452f-8521-e9c683196b7d  Pulling image "busybox"
  Normal  Pulled     64s   kubelet, node-43b8731c-9a45-452f-8521-e9c683196b7d  Successfully pulled image "busybox"
  Normal  Created    64s   kubelet, node-43b8731c-9a45-452f-8521-e9c683196b7d  Created container debug
  Normal  Started    64s   kubelet, node-43b8731c-9a45-452f-8521-e9c683196b7d  Started container debug

Pour détruire le pod qui a été déployé :

 $ ku delete deploy hello-world-deployment
deployment.apps "hello-world-deployment" deleted
 $ ku get all
NAME                                          READY   STATUS        RESTARTS   AGE
pod/debug                                     1/1     Running       0          2m43s
pod/hello-world-deployment-6fcbdc8f79-t9ngq   0/1     Terminating   0          18m

NAME                  TYPE           CLUSTER-IP    EXTERNAL-IP      PORT(S)        AGE
service/hello-world   LoadBalancer   10.3.89.177   51.2xx.xxx.222   80:31634/TCP   13d
service/kubernetes    ClusterIP      10.3.0.1      <none>           443/TCP        2d16h

NAME                     DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/fluentd   0         0         0       0            0           type=prod       6d19h

HELM:

$ curl -L https://git.io/get_helm.sh | bash
Downloading https://get.helm.sh/helm-v2.16.12-linux-amd64.tar.gz
Preparing to install helm and tiller into /usr/local/bin    
helm installed into /usr/local/bin/helm
tiller installed into /usr/local/bin/tiller
Run 'helm init' to configure helm.
$ helm init
$ helm ls
Error: configmaps is forbidden: User "system:serviceaccount:kube-system:default" cannot list resource "configmaps" in API group "" in the namespace "kube-system"

STERN = le tail de Kubernetes :

 $ sudo curl -L -o /usr/local/bin/stern https://github.com/wercker/stern/releases/download/1.10.0/stern_linux_amd64
 $ sudo chmod +x /usr/local/bin/stern
 $ stern hello-world-deployment-6fcbdc8f79-lsmxs
+ hello-world-deployment-6fcbdc8f79-lsmxs › hello-world
hello-world-deployment-6fcbdc8f79-lsmxs hello-world 2020/09/21 13:54:00 [error] 12#12: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 51.210.250.33, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "51.210.211.222", referrer: "http://51.210.211.222/"
hello-world-deployment-6fcbdc8f79-lsmxs hello-world 51.210.250.33 - - [21/Sep/2020:13:54:00 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://51.210.211.222/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36" "-"
hello-world-deployment-6fcbdc8f79-lsmxs hello-world 51.210.250.33 - - [21/Sep/2020:13:54:58 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36" "-"
hello-world-deployment-6fcbdc8f79-lsmxs hello-world 51.210.250.33 - - [21/Sep/2020:13:59:31 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36" "-"