[2] MicroK8s – Alokacja

11 lutego 2021 Wyłączono przez Adam [zicherka] Nogły

Przedstawię teraz podstawowe czynności i operacja ne MicroK8s

[1] Stwórz i skasuj pojemnik 😉 (kurde, nie wiem jak to po polsku nazwać, po angielsku chodzi oczywiście o PODS’y).

# uruchomimy teraz podsa [test-nginx]
[root@vlsr01 ~]# microk8s kubectl create deployment test-nginx --image=nginx
deployment.apps/test-nginx created

[root@vlsr01 ~]# microk8s kubectl get pods
NAME READY STATUS RESTARTS AGE
test-nginx-59ffd87f5-4x7mr 0/1 ContainerCreating 0 13s

# pokaż dostępne zmienne dla [test-nginx]
[root@vlsr01 ~]# microk8s kubectl exec test-nginx-59ffd87f5-4x7mr -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=test-nginx-59ffd87f5-4x7mr
NGINX_VERSION=1.19.6
NJS_VERSION=0.5.0
PKG_RELEASE=1~buster
KUBERNETES_PORT=tcp://10.152.183.1:443
KUBERNETES_PORT_443_TCP=tcp://10.152.183.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.152.183.1
KUBERNETES_SERVICE_HOST=10.152.183.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
HOME=/root

# dostęp do powłoki podsa [test-nginx]
[root@vlsr01 ~]# microk8s kubectl exec -it test-nginx-59ffd87f5-4x7mr -- bash
root@test-nginx-59ffd87f5-4x7mr:/# hostname
test-nginx-59ffd87f5-4x7mr
root@test-nginx-59ffd87f5-4x7mr:/# exit
exit

# pokaż logi [test-nginx]
[root@vlsr01 ~]# microk8s kubectl logs test-nginx-59ffd87f5-4x7mr
/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 podsa
[root@vlsr01 ~]# microk8s kubectl scale deployment test-nginx --replicas=3
deployment.apps/test-nginx scaled
[root@vlsr01 ~]# microk8s kubectl get pods
NAME READY STATUS RESTARTS AGE
test-nginx-59ffd87f5-4x7mr 1/1 Running 0 5m40s
test-nginx-59ffd87f5-w28gh 1/1 Running 0 9s
test-nginx-59ffd87f5-l2qks 1/1 Running 0 9s

# ustaw usługi
[root@vlsr01 ~]# microk8s kubectl expose deployment test-nginx --type="NodePort" --port 80
service/test-nginx exposed
[root@vlsr01 ~]# microk8s kubectl get services test-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
test-nginx NodePort 10.152.183.223 <none> 80:32083/TCP 9s

# sprawdź dostęp
[root@vlsr01 ~]# curl 10.152.183.223
<!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>

# skasuj usługę
[root@vlsr01 ~]# microk8s kubectl delete services test-nginx
service "test-nginx" deleted

# skasuj podsa
[root@vlsr01 ~]# microk8s kubectl delete deployment test-nginx
deployment.apps "test-nginx" deleted