Minikube: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
<source lang="bash">
<syntaxhighlight lang="bash">
sudo mkdir -p /opt/cli/minikube-linux-amd64/bin
sudo mkdir -p /opt/cli/minikube-linux-amd64/bin
sudo wget -cq https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64\
sudo wget -cq https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64\
Line 7: Line 7:
sudo update-alternatives --install /usr/local/bin/minikube minikube\
sudo update-alternatives --install /usr/local/bin/minikube minikube\
  /opt/cli/minikube-linux-amd64/bin/minikube 1980
  /opt/cli/minikube-linux-amd64/bin/minikube 1980
</source>
</syntaxhighlight>


{| class="wikitable sortable"
{| class="wikitable sortable"
Line 25: Line 25:


==Kubectl==
==Kubectl==
<source lang="bash">
<syntaxhighlight lang="bash">
sudo mkdir -p /etc/apt/keyrings
sudo mkdir -p /etc/apt/keyrings
sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg\
sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg\
Line 38: Line 38:
sudo apt update
sudo apt update
sudo apt install kubectl
sudo apt install kubectl
</source>
</syntaxhighlight>


==Cluster==
==Cluster==
<source lang="bash">
<syntaxhighlight lang="bash">
minikube start
minikube start
:'
:'
Line 63: Line 63:
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
'
'
</source>
</syntaxhighlight>


<source lang="bash">
<syntaxhighlight lang="bash">
kubectl get po -A
kubectl get po -A
minikube kubectl -- get po -A
minikube kubectl -- get po -A
Line 78: Line 78:
kube-system  storage-provisioner                1/1    Running  1 (7m43s ago)  8m25s
kube-system  storage-provisioner                1/1    Running  1 (7m43s ago)  8m25s
'
'
</source>
</syntaxhighlight>


==Dashboard==
==Dashboard==
<source lang="bash">
<syntaxhighlight lang="bash">
minikube addons enable metrics-server
minikube addons enable metrics-server
minikube dashboard
minikube dashboard
Line 95: Line 95:
Gtk-Message: 17:34:36.654: Failed to load module "canberra-gtk-module"
Gtk-Message: 17:34:36.654: Failed to load module "canberra-gtk-module"
'
'
</source>
</syntaxhighlight>


==Deploy==
==Deploy==
Line 118: Line 118:


==Example==
==Example==
<source lang='bash'>
<syntaxhighlight lang='bash'>
docker build -t chorke/crawler:1.0.00 -f ./Dockerfile .
docker build -t chorke/crawler:1.0.00 -f ./Dockerfile .
docker tag      chorke/crawler:1.0.00 reg.chorke.org/chorke/crawler:1.0.00
docker tag      chorke/crawler:1.0.00 reg.chorke.org/chorke/crawler:1.0.00
Line 127: Line 127:
minikube image load chorke/crawler:1.0.00
minikube image load chorke/crawler:1.0.00
minikube image ls --format table
minikube image ls --format table
</source>
</syntaxhighlight>


<source lang='bash'>
<syntaxhighlight lang='bash'>
kubectl run crawler --image=chorke/crawler:1.0.00 --image-pull-policy=Never --restart=Never
kubectl run crawler --image=chorke/crawler:1.0.00 --image-pull-policy=Never --restart=Never
kubectl logs crawler
kubectl logs crawler
Line 136: Line 136:
kubectl delete pod crawler -n default
kubectl delete pod crawler -n default
kubectl delete pod crawler
kubectl delete pod crawler
</source>
</syntaxhighlight>


  '''Deployment/NodePort:'''
  '''Deployment/NodePort:'''
Line 152: Line 152:
{|
{|
| valign="top" |
| valign="top" |
<source lang='bash'>
<syntaxhighlight lang='bash'>
minikube start
minikube start
cat /etc/resolv.conf | grep nameserver
cat /etc/resolv.conf | grep nameserver
</source>
</syntaxhighlight>


| valign="top" |
| valign="top" |
<source lang='bash'>
<syntaxhighlight lang='bash'>
minikube addons enable ingress
minikube addons enable ingress
minikube addons enable ingress-dns
minikube addons enable ingress-dns
</source>
</syntaxhighlight>


| valign="top" |
| valign="top" |
<source lang='bash'>
<syntaxhighlight lang='bash'>
nslookup academia.local
nslookup academia.local
nslookup academia.local $(minikube ip)
nslookup academia.local $(minikube ip)
</source>
</syntaxhighlight>


|-
|-
Line 174: Line 174:
|-
|-
|colspan="3"|
|colspan="3"|
<source lang='bash'>
<syntaxhighlight lang='bash'>
kubectl get configmap coredns -n kube-system -o yaml
kubectl get configmap coredns -n kube-system -o yaml
kubectl get configmap coredns -n kube-system -o "jsonpath={.data.Corefile}"
kubectl get configmap coredns -n kube-system -o "jsonpath={.data.Corefile}"
</source>
</syntaxhighlight>


|-
|-
Line 185: Line 185:
|colspan="3"|
|colspan="3"|
'''Volatile Fixes'''
'''Volatile Fixes'''
<source lang='bash'>
<syntaxhighlight lang='bash'>
RESOLVE='/etc/resolv.conf';\
RESOLVE='/etc/resolv.conf';\
printf -v K8S_DNS '%s' $(minikube ip);\
printf -v K8S_DNS '%s' $(minikube ip);\
Line 195: Line 195:
fi;\
fi;\
cat ${RESOLVE}
cat ${RESOLVE}
</source>
</syntaxhighlight>


|-
|-
Line 203: Line 203:
|colspan="3"|
|colspan="3"|
'''Robust Fixes'''
'''Robust Fixes'''
<source lang='bash'>
<syntaxhighlight lang='bash'>
RESOLVE='/etc/systemd/resolved.conf';\
RESOLVE='/etc/systemd/resolved.conf';\
printf -v K8S_DNS '%s' $(minikube ip);\
printf -v K8S_DNS '%s' $(minikube ip);\
Line 216: Line 216:
sudo systemctl restart systemd-resolved
sudo systemctl restart systemd-resolved
sudo systemctl status  systemd-resolved
sudo systemctl status  systemd-resolved
</source>
</syntaxhighlight>


|-
|-
Line 240: Line 240:
|colspan="3"|
|colspan="3"|
  kubectl edit configmap coredns -n kube-system
  kubectl edit configmap coredns -n kube-system
<source lang='properties' line>
<syntaxhighlight lang='properties' line>
apiVersion: v1
apiVersion: v1
data:
data:
Line 246: Line 246:
     .:53 {
     .:53 {
         errors
         errors
</source>
</syntaxhighlight>
----
----
<source lang='properties' line start='25' highlight='4-13'>
<syntaxhighlight lang='properties' line start='25' highlight='4-13'>
         reload
         reload
         loadbalance
         loadbalance
Line 269: Line 269:
   resourceVersion: "300"
   resourceVersion: "300"
   uid: d8eec45d-1452-467f-8861-8811658c773a
   uid: d8eec45d-1452-467f-8861-8811658c773a
</source>
</syntaxhighlight>


|-
|-
Line 287: Line 287:
{|
{|
|valign='top'|
|valign='top'|
<source lang="properties">
<syntaxhighlight lang="properties">
cat <<EOF | kubectl apply -n kubernetes-dashboard -f -
cat <<EOF | kubectl apply -n kubernetes-dashboard -f -
apiVersion: networking.k8s.io/v1
apiVersion: networking.k8s.io/v1
Line 313: Line 313:
                   number: 80
                   number: 80
EOF
EOF
</source>
</syntaxhighlight>


|valign='top'|
|valign='top'|
<source lang="properties">
<syntaxhighlight lang="properties">
cat <<EOF | kubectl delete -n kubernetes-dashboard -f -
cat <<EOF | kubectl delete -n kubernetes-dashboard -f -
apiVersion: networking.k8s.io/v1
apiVersion: networking.k8s.io/v1
Line 342: Line 342:
                   number: 80
                   number: 80
EOF
EOF
</source>
</syntaxhighlight>


|-
|-
Line 415: Line 415:
|-
|-
|colspan="2"|
|colspan="2"|
<source lang='bash'>
<syntaxhighlight lang='bash'>
docker container inspect minikube \
docker container inspect minikube \
--format="{{ (index (index .NetworkSettings.Ports \"8443/tcp\") 0).HostPort }}"
--format="{{ (index (index .NetworkSettings.Ports \"8443/tcp\") 0).HostPort }}"


docker container ls --filter=name=minikube --format="{{.Ports}}" | tr , \\n
docker container ls --filter=name=minikube --format="{{.Ports}}" | tr , \\n
</source>
</syntaxhighlight>
|-
|-
|colspan="2"|
|colspan="2"|
Line 474: Line 474:
|-
|-
|valign="top"|
|valign="top"|
<source lang='bash'>
<syntaxhighlight lang='bash'>
minikube addons enable metallb
minikube addons enable metallb
minikube addons enable olm
minikube addons enable olm
minikube addons list
minikube addons list
</source>
</syntaxhighlight>


|valign="top"|
|valign="top"|
<source lang='bash'>
<syntaxhighlight lang='bash'>
minikube addons enable default-storageclass
minikube addons enable default-storageclass
minikube addons enable metrics-server
minikube addons enable metrics-server
minikube addons configure metallb
minikube addons configure metallb
</source>
</syntaxhighlight>
|-
|-
|colspan="2"|
|colspan="2"|
Line 491: Line 491:
|-
|-
|valign="top"|
|valign="top"|
<source lang='bash'>
<syntaxhighlight lang='bash'>
minikube addons enable storage-provisioner
minikube addons enable storage-provisioner
minikube addons enable dashboard
minikube addons enable dashboard


minikube ssh
minikube ssh
</source>
</syntaxhighlight>


|valign="top"|
|valign="top"|

Revision as of 20:30, 26 May 2024

sudo mkdir -p /opt/cli/minikube-linux-amd64/bin
sudo wget -cq https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64\
 -O /opt/cli/minikube-linux-amd64/bin/minikube

sudo chmod +x /opt/cli/minikube-linux-amd64/bin/minikube
sudo update-alternatives --install /usr/local/bin/minikube minikube\
 /opt/cli/minikube-linux-amd64/bin/minikube 1980
Order Port Type Internal IP Internal Port External IP External Port
1 TCP 0.0.0.0 32443 127.0.0.1 49153
2 TCP 0.0.0.0 8443 127.0.0.1 49154
3 TCP 0.0.0.0 5000 127.0.0.1 49155
4 TCP 0.0.0.0 2376 127.0.0.1 49156
5 TCP 0.0.0.0 22 127.0.0.1 49157

Kubectl

sudo mkdir -p /etc/apt/keyrings
sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg\
 https://packages.cloud.google.com/apt/doc/apt-key.gpg

cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list >/dev/null
deb [arch=$(dpkg --print-architecture)\
 signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg]\
 https://apt.kubernetes.io/ kubernetes-xenial main
EOF

sudo apt update
sudo apt install kubectl

Cluster

minikube start
:'
😄  minikube v1.29.0 on Ubuntu 22.04
✨  Automatically selected the docker driver. Other choices: kvm2, qemu2, none, ssh
📌  Using Docker driver with root privileges
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
💾  Downloading Kubernetes v1.26.1 preload ...
    > preloaded-images-k8s-v18-v1...:  397.05 MiB / 397.05 MiB  100.00% 33.42 M
    > gcr.io/k8s-minikube/kicbase...:  407.19 MiB / 407.19 MiB  100.00% 7.46 Mi
🔥  Creating docker container (CPUs=2, Memory=5900MB) ...
🐳  Preparing Kubernetes v1.26.1 on Docker 20.10.23 ...
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
🔎  Verifying Kubernetes components...
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
'
kubectl get po -A
minikube kubectl -- get po -A
:'
NAMESPACE     NAME                               READY   STATUS    RESTARTS        AGE
kube-system   coredns-64897985d-thxhw            1/1     Running   0               8m14s
kube-system   etcd-minikube                      1/1     Running   0               8m26s
kube-system   kube-apiserver-minikube            1/1     Running   0               8m26s
kube-system   kube-controller-manager-minikube   1/1     Running   0               8m26s
kube-system   kube-proxy-xqfl2                   1/1     Running   0               8m13s
kube-system   kube-scheduler-minikube            1/1     Running   0               8m26s
kube-system   storage-provisioner                1/1     Running   1 (7m43s ago)   8m25s
'

Dashboard

minikube addons enable metrics-server
minikube dashboard
:'
🔌  Enabling  ...
    ▪ Using image kubernetesui/metrics-scraper:v1.0.7
    ▪ Using image kubernetesui/dashboard:v2.3.1
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:36403/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
Gtk-Message: 17:34:36.652: Failed to load module "canberra-gtk-module"
Gtk-Message: 17:34:36.654: Failed to load module "canberra-gtk-module"
'

Deploy

Deployment/NodePort:
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-minikube --type=NodePort --port=8080

kubectl port-forward service/hello-minikube 7080:8080
http://localhost:7080/

kubectl get services      hello-minikube
kubectl delete services   hello-minikube
kubectl delete deployment hello-minikube
Deployment/LoadBalancer:
kubectl create deployment balanced --image=k8s.gcr.io/echoserver:1.4  
kubectl expose deployment balanced --type=LoadBalancer --port=8080

kubectl get services      balanced
kubectl delete services   balanced
kubectl delete deployment balanced

Example

docker build -t chorke/crawler:1.0.00 -f ./Dockerfile .
docker tag      chorke/crawler:1.0.00 reg.chorke.org/chorke/crawler:1.0.00
docker push     reg.chorke.org/chorke/crawler:1.0.00
docker pull     hub.chorke.org/chorke/crawler:1.0.00
docker tag      hub.chorke.org/chorke/crawler:1.0.00 chorke/crawler:1.0.00

minikube image load chorke/crawler:1.0.00
minikube image ls --format table
kubectl run crawler --image=chorke/crawler:1.0.00 --image-pull-policy=Never --restart=Never
kubectl logs crawler
kubectl get pod

kubectl delete pod crawler -n default
kubectl delete pod crawler
Deployment/NodePort:
kubectl create deployment crawler --image=chorke/crawler:1.0.00
kubectl expose deployment crawler --type=NodePort --port=1983

kubectl port-forward service/crawler 1983:1983
http://localhost:1983/crawler

kubectl get services      crawler
kubectl delete services   crawler
kubectl delete deployment crawler

Ingress DNS

minikube start
cat /etc/resolv.conf | grep nameserver
minikube addons enable ingress
minikube addons enable ingress-dns
nslookup academia.local
nslookup academia.local $(minikube ip)

kubectl get configmap coredns -n kube-system -o yaml
kubectl get configmap coredns -n kube-system -o "jsonpath={.data.Corefile}"

Volatile Fixes

RESOLVE='/etc/resolv.conf';\
printf -v K8S_DNS '%s' $(minikube ip);\
if  [ -f ${RESOLVE} ]&&[ "$(grep -c ${K8S_DNS} ${RESOLVE})" == 0 ];then\
 cat << EOF | sudo tee -a ${RESOLVE} >/dev/null

nameserver ${K8S_DNS}
EOF
fi;\
cat ${RESOLVE}

Robust Fixes

RESOLVE='/etc/systemd/resolved.conf';\
printf -v K8S_DNS '%s' $(minikube ip);\
if  [ -f ${RESOLVE} ]&&[ "$(grep -c ${K8S_DNS} ${RESOLVE})" == 0 ];then\
 cat << EOF | sudo tee -a ${RESOLVE} >/dev/null

# k8s coredns
DNS=${K8S_DNS}
EOF
fi;\
cat ${RESOLVE}
sudo systemctl restart systemd-resolved
sudo systemctl status  systemd-resolved

sudo systemctl restart NetworkManager.service
systemctl status NetworkManager.service
systemctl status systemd-resolved
systemctl status dnsmasq
cat /etc/resolv.conf | grep nameserver
nmcli dev show | grep DNS
journalctl -u dnsmasq
tail /var/log/syslog

kubectl edit configmap coredns -n kube-system
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors

        reload
        loadbalance
    }
    k8s.local:53 {
        errors
        cache 30
        forward . 192.168.49.2
    }
    academia.local:53 {
        errors
        cache 30
        forward . 192.168.49.2
    }
kind: ConfigMap
metadata:
  creationTimestamp: "2023-07-04T00:08:54Z"
  name: coredns
  namespace: kube-system
  resourceVersion: "300"
  uid: d8eec45d-1452-467f-8861-8811658c773a

kubectl run -i --tty --rm debug --image=busybox --restart=Never -- nslookup academia.local
kubectl run -i --tty --rm debug --image=busybox --restart=Never -- ping academia.local

kubectl run -i --tty --rm debug --image=alpine  --restart=Never -- nslookup academia.local
kubectl run -i --tty --rm debug --image=alpine  --restart=Never -- ping academia.local

Ingress DNS » Dashboard


cat <<EOF | kubectl apply -n kubernetes-dashboard -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  labels:
    helm.sh/chart: kubernetes-dashboard-1.0.0
    app.kubernetes.io/name: kubernetes-dashboard
    app.kubernetes.io/instance: kubernetes-dashboard
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/managed-by: Helm
spec:
  ingressClassName: nginx
  rules:
    - host: "www.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: kubernetes-dashboard
                port:
                  number: 80
EOF
cat <<EOF | kubectl delete -n kubernetes-dashboard -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  labels:
    helm.sh/chart: kubernetes-dashboard-1.0.0
    app.kubernetes.io/name: kubernetes-dashboard
    app.kubernetes.io/instance: kubernetes-dashboard
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/managed-by: Helm
spec:
  ingressClassName: nginx
  rules:
    - host: "www.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: kubernetes-dashboard
                port:
                  number: 80
EOF

Knowledge

minikube stop
minikube start
minikube pause

minikube delete
minikube unpause
minikube addons list
minikube delete --all
minikube docker-env
minikube image ls --format table
minikube config set memory 16384
 
minikube start --cpus 8 --memory 16384
eval $(minikube -p minikube docker-env)
minikube start -p aged --kubernetes-version=v1.16.1
minikube start -p aged --kubernetes-version=v1.24.0

docker ps -a
docker images
docker image ls
docker network ls

docker rm $(docker ps -a -q)
docker stop $(docker ps -a -q)

docker build\
 -t chorke/crawler:1.0.00 -f ./Dockerfile .

docker logs crawler
docker stop crawler && docker rm crawler
kubectl get pod
kubectl cluster-info
kubectl get namespaces
kubectl -n kube-system get svc -o wide

minikube image ls --format table
minikube image load chorke/crawler:1.0.00

kubectl run crawler --image=chorke/crawler:1.0.00\
 --image-pull-policy=Never --restart=Never

kubectl logs crawler
kubectl delete pod crawler

docker container inspect minikube \
--format="{{ (index (index .NetworkSettings.Ports \"8443/tcp\") 0).HostPort }}"

docker container ls --filter=name=minikube --format="{{.Ports}}" | tr , \\n

kubectl get po -A
kubectl explain pods
kubectl get services
kubectl get services crawler
kubectl describe pods crawler
kubectl get pods --all-namespaces

kubectl get services
kubectl get services -n default
kubectl get services --all-namespaces

kubectl delete pod crawler
kubectl delete -n default pod crawler

kubectl delete services crawler
kubectl delete deployment crawler

kubectl get nodes
kubectl get pods -o wide
kubectl get po,jobs,cronjob
minikube kubectl -- get po -A
minikube kubectl -- explain pods
minikube kubectl -- get services
minikube kubectl -- get service crawler
minikube kubectl -- describe pods crawler
minikube kubectl -- get pods --all-namespaces 

minikube service --all
minikube service list -n default
minikube service list

minikube kubectl -- delete pod crawler
minikube kubectl -- delete -n default pod crawler

minikube kubectl -- delete services crawler
minikube kubectl -- delete deployment crawler

minikube kubectl -- get nodes
minikube kubectl -- get pods -o wide
minikube kubectl -- get po,jobs,cronjob

minikube addons enable metallb
minikube addons enable olm
minikube addons list
minikube addons enable default-storageclass
minikube addons enable metrics-server
minikube addons configure metallb

minikube addons enable storage-provisioner
minikube addons enable dashboard

minikube ssh
minikube addons enable ingress-dns
minikube addons enable ingress

ping host.minikube.internal

kubectl get configmap coredns -n kube-system -o yaml
nslookup academia.local $(minikube ip)

References