[2] Minikube – podstawy
9 lutego 2021Przedstawię teraz podstawowe komendy i operacje na pojedynczym węźle klastra Kubernetes na maszynie wirtualnej Minikube.
[1] Stwórz i skasuj Pods’y (strąki, pojemniki, kapsuły)
# uruchom kapsułę [test-nginx] [user01@vlsr01 ~]$ minikube start --vm-driver=kvm2 * minikube v1.17.1 na Centos 8 * Using the kvm2 driver based on user configuration * Starting control plane node minikube in cluster minikube * Creating kvm2 VM (CPUs=2, Memory=2200MB, Disk=20000MB) ... * Przygotowywanie Kubernetesa v1.20.2 na Docker 20.10.2... - Generating certificates and keys ... - Booting up control plane ... - Configuring RBAC rules ... * Verifying Kubernetes components... * Enabled addons: storage-provisioner, default-storageclass * Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default # uruchom kapsułę [test-nginx] [user01@vlsr01 ~]$ kubectl create deployment test-nginx --image=nginx/test-nginx deployment.apps/test-nginx created [user01@vlsr01 ~]$ kubectl get pods NAME READY STATUS RESTARTS AGE test-nginx-59ffd87f5-v77x2 0/1 ContainerCreating 0 16s # pokaż zmienne dla kapsuły [test-nginx] [user01@vlsr01 ~]$ kubectl exec test-nginx-59ffd87f5-v77x2 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=test-nginx-59ffd87f5-v77x2 KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1 KUBERNETES_SERVICE_HOST=10.96.0.1 KUBERNETES_SERVICE_PORT=443 KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT=tcp://10.96.0.1:443 KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443 KUBERNETES_PORT_443_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_PORT=443 NGINX_VERSION=1.19.6 NJS_VERSION=0.5.0 PKG_RELEASE=1~buster HOME=/root # dostęp do powłoki kapsuły [test-nginx] [user01@vlsr01 ~]$ kubectl exec -it test-nginx-59ffd87f5-v77x2 -- bash root@test-nginx-59ffd87f5-v77x2:/# hostname test-nginx-59ffd87f5-v77x2 root@test-nginx-59ffd87f5-v77x2:/# exit exit # pokaż logi kapsuły [test-nginx] [user01@vlsr01 ~]$ kubectl logs test-nginx-59ffd87f5-v77x2 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Configuration complete; ready for start up # przeskaluj kapsułę [user01@vlsr01 ~]$ kubectl scale deployment test-nginx --replicas=3 deployment.apps/test-nginx scaled [user01@vlsr01 ~]$ kubectl get pods NAME READY STATUS RESTARTS AGE test-nginx-59ffd87f5-75gs2 1/1 Running 0 9s test-nginx-59ffd87f5-njgqk 1/1 Running 0 9s test-nginx-59ffd87f5-v77x2 1/1 Running 0 6h33m # ustaw usługi [user01@vlsr01 ~]$ kubectl expose deployment test-nginx --type="NodePort" --port 80 service/test-nginx exposed [user01@vlsr01 ~]$ kubectl get services test-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE test-nginx NodePort 10.102.112.127 <none> 80:32232/TCP 10s [user01@vlsr01 ~]$ minikube service test-nginx --url http://192.168.39.101:32232 [user01@vlsr01 ~]$ curl http://192.168.39.101:32232 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> # usuń usługę [user01@vlsr01 ~]$ kubectl delete services test-nginx service "test-nginx" deleted # usuń kapsułę [user01@vlsr01 ~]$ kubectl delete deployment test-nginx deployment.apps "test-nginx" deleted