Entrada

Kubernetes comandos y notas

Comados utililes para recurdar cuando estas trabajando en kubernetes y todas sus piezas involucradas como pods, containers, deploys, servicios, configs, balanceadores entre otros.

Minikube

Iniciar minikube

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ kubectl cluster-info😄  minikube v1.31.2 on Debian 12.1
✨  Using the docker driver based on existing profile
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
🔄  Restarting existing docker container for "minikube" ...
🐳  Preparing Kubernetes v1.27.4 on Docker 24.0.4 ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image docker.io/kubernetesui/dashboard:v2.7.0
    ▪ Using image docker.io/kubernetesui/metrics-scraper:v1.0.8
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
💡  Some dashboard features require the metrics-server addon. To enable all features please run:

	minikube addons enable metrics-server	


🌟  Enabled addons: default-storageclass, storage-provisioner, dashboard
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Status del minikube

1
2
3
4
5
6
7
8
$ minikube statusminikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured


Cluster

Ver datos del cluster

1
2
3
4
5
$ kubectl cluster-info
Kubernetes control plane is running at https://192.168.49.2:8443
CoreDNS is running at https://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

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

Nodes

Ver datos de los nodos

1
2
3
$ kubectl get nodes
NAME       STATUS   ROLES           AGE    VERSION
minikube   Ready    control-plane   4h6m   v1.27.4
1
2
3
$ kubectl get nodes -o wide
NAME       STATUS   ROLES           AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
minikube   Ready    control-plane   2d    v1.27.4   192.168.49.2   <none>        Ubuntu 22.04.2 LTS   6.1.0-11-amd64   docker://24.0.4

Pods

Ver datos de los pods

1
2
3
$ kubectl get pods
NAME                                        READY   STATUS    RESTARTS   AGE
despliegue-etiquetas-7b9cdb5bf8-2wjvm       1/1     Running   0          5h55m

Ver informacion detallada de un pod

1
$ kubectl describe  pod hola-mundo

Eliminar un pod

1
$ kubectl delete -f hola_mundo.yaml 

Entrar a un pod

1
$ kubectl exec -i -t web-configurada-59c9865d66-bkcmz -- /bin/ash

Services

Ver servicios

1
2
3
4
5
6
$ kubectl get service
NAME                TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes          ClusterIP      10.96.0.1        <none>        443/TCP        2d
kubeview            LoadBalancer   10.106.130.64    <pending>     80:31027/TCP   17h
mi-servicio         ClusterIP      10.104.110.72    <none>        80/TCP         107s
servicio-nodeport   NodePort       10.107.231.156   <none>        80:30007/TCP   10s

Deployments

Ver deployments

1
2
3
4
$ kubectl get deployment
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
kubeview   1/1     1            1           17h
mi-web     2/2     2            2           63m

Reiniciar un deploy Útil cuando se cambia la configuración y quieres aplicar nuevamente

1
$ kubectl rollout restart deployment web-configurada

Container

Ejecutar un comando en el contenedor de un pod

1
2
$ kubectl exec -i -t web-configurada-7f7d8dfd8c-kvmc6 -- cat /etc/nginx/templates/default.conf.template
$ kubectl exec -i -t web-configurada-59c9865d66-bkcmz -- env
Esta entrada está licenciada bajo CC BY 4.0 por el autor.