#### Divers kubectl : ```shell kubectl get pods kubectl --namespace kube-system get pods kubectl get all (dans le namespace par défaut) kubectl get pod --all-namespaces kubectl config set-context --current --namespace default kubectl get services --all-namespaces ``` #### Récuperer toutes les api dispos sur kubectl : ```shell kubectl api-resources ``` #### Créer un token sur un user : ```shell kubectl -n kubernetes-namespace create token user ``` #### Se connecter sur un pod : ```shell kubectl exec --stdin --tty <pod> -- /bin/bash (par exemple) ``` #### Obtenir des logs sur un pod ```shell kubectl logs mariadb-deployment-d7897d899-kv4z9 ``` #### Passer des commandes sur le cluster en démarrant une image debian ephémère : ```shell kubectl run debianpod -i --tty --image debian:bullseye --restart=Never -- bash ``` #### Par exemple utilisation client mysql sur une debian éphémère : ``` shell apt install mariadb-client mysql -uradmin -pXXXXXX -hmariadb.mariadb.svc.cluster.local ``` ### Créer un secret "from-literal" : ```shell kubectl create secret generic my-test-secret --from-literal=rootpassword=alphabeta ``` #### Le Supprimer : ```shell kubectl delete secret my-test-secret ``` #### Ensuite pour le récupérer : ```shell kubectl get secret my-test-secret -o go-template='{{.data}}' map[rootpassword:YWxwaGFiZXRh] echo "YWxwaGFiZXRh" | base64 -d alphabeta ``` ### Visualiser les labels des nodes ```shell kubectl get nodes --show-labels ``` ... le seter : ```shell kubectl label nodes <your-node-name> label=value ``` ### Affecter un label à quelque chose (des pods par exemple) ```yaml spec: nodeSelector: label: value ``` ### Exsemple de Security Context ```shell image: toto:version volumesMount: (...) securityContext: privileged: true ``` ### Affinité sur un Node particulier (exemple alice) ```shell kubectl label nodes alice clefnode=primary (par exemple) kubectl get node alice --show-labels ``` ... et ensuite ```yaml affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: # preferred marche aussi, autant coté nodeAffinity que sur podAffinity nodeSelectorTerms: - matchExpressions: - key: clefnode operator: In values: - primary # options possibles sur le pod avec labelSelector # - labelSelector # matchLabels: # app: backend (par exemple) # topologyKey : "kubernetes.io/hostname" (forcer sur les pods sur le même serveur) ``` #### Avoir des explications sur une spec ```shell kubectl explain pod.spec.affinity.nodeAffinity (par exemple) ``` #### Forcer la suppression de pv/pvc : ```shell kubectl patch pv <pv_name> -p '{"metadata":{"finalizers":null}}' kubectl delete pv <pv_name> --grace-period=0 --force PVC_NAME="<pvc-name>"; kubectl get pods,deployments,statefulsets,daemonsets,replicasets,jobs,cronjobs --all-namespaces -o json | jq --arg PVC "$PVC_NAME" '.items[] | select(.spec.template.spec.volumes[]?.persistentVolumeClaim.claimName == $PVC) | .metadata.namespace + "/" + .metadata.name + " (" + .kind + ")"' ```
