Minikube: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(128 intermediate revisions by the same user not shown)
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
curl -sLO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo wget -cq https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64\
sudo install minikube-linux-amd64 /opt/cli/minikube-linux-amd64/bin/minikube
-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\
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
rm -rf minikube-linux-amd64
</syntaxhighlight>
</source>


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


==Kubectl==
==Kubectl==
<source lang="bash">
<syntaxhighlight lang="bash">
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo mkdir -p /etc/apt/keyrings
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key\
deb https://apt.kubernetes.io/ kubernetes-xenial main
| sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.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-apt-keyring.gpg]\
https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /
EOF
EOF
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
:'
:'
😄  minikube v1.25.2 on Ubuntu 22.04
😄  minikube v1.29.0 on Ubuntu 22.04
✨  Automatically selected the docker driver. Other choices: none, ssh
✨  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
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
🚜  Pulling base image ...
💾  Downloading Kubernetes v1.23.3 preload ...
💾  Downloading Kubernetes v1.26.1 preload ...
     > preloaded-images-k8s-v17-v1...: 505.68 MiB / 505.68 MiB  100.00% 4.60 MiB
     > preloaded-images-k8s-v18-v1...: 397.05 MiB / 397.05 MiB  100.00% 33.42 M
     > gcr.io/k8s-minikube/kicbase: 379.06 MiB / 379.06 MiB  100.00% 2.47 MiB p/
     > gcr.io/k8s-minikube/kicbase...: 407.19 MiB / 407.19 MiB  100.00% 7.46 Mi
🔥  Creating docker container (CPUs=2, Memory=6900MB) ...
🔥  Creating docker container (CPUs=2, Memory=5900MB) ...
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
🐳  Preparing Kubernetes v1.26.1 on Docker 20.10.23 ...
    ▪ kubelet.housekeeping-interval=5m
     ▪ Generating certificates and keys ...
     ▪ Generating certificates and keys ...
     ▪ Booting up control plane ...
     ▪ Booting up control plane ...
     ▪ Configuring RBAC rules ...
     ▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
🔗 Configuring bridge CNI (Container Networking Interface) ...
     ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
     ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
🌟  Enabled addons: storage-provisioner, default-storageclass
🔎  Verifying Kubernetes components...
🏄  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 70: 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 dashboard
minikube dashboard
:'
:'
Line 86: 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==
'''Deployment/NodePort:'''
  kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
  kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
  kubectl expose deployment hello-minikube --type=NodePort --port=8080
  kubectl expose deployment hello-minikube --type=NodePort --port=8080
 
   
  kubectl get services hello-minikube
minikube service hello-minikube
 
  kubectl port-forward service/hello-minikube 7080:8080
  kubectl port-forward service/hello-minikube 7080:8080
  http://localhost:7080/
  http://localhost:7080/
kubectl get services      hello-minikube
kubectl delete services  hello-minikube
kubectl delete deployment hello-minikube


  '''LoadBalancer deployments'''
  '''Deployment/LoadBalancer:'''
  kubectl create deployment balanced --image=k8s.gcr.io/echoserver:1.4   
  kubectl create deployment balanced --image=k8s.gcr.io/echoserver:1.4   
  kubectl expose deployment balanced --type=LoadBalancer --port=8080
  kubectl expose deployment balanced --type=LoadBalancer --port=8080
kubectl get services      balanced
kubectl delete services  balanced
kubectl delete deployment balanced
==Example==
<syntaxhighlight lang='bash'>
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
</syntaxhighlight>
<syntaxhighlight lang='bash'>
kubectl run crawler --image=chorke/crawler:1.0.00 --image-pull-policy=Never --restart=Never
kubectl logs crawler
kubectl get pod


minikube tunnel
kubectl delete pod crawler -n default
kubectl get services balanced
kubectl delete pod crawler
</syntaxhighlight>


==Example==
'''Deployment/NodePort:'''
  docker build -t chorke/crawler:1.0.00 -f ./Dockerfile .
  kubectl create deployment crawler --image=chorke/crawler:1.0.00
  minikube image load chorke/crawler:1.0.00
  kubectl expose deployment crawler --type=NodePort --port=1983
   
   
  kubectl run crawler --image=chorke/crawler:1.0.00 --image-pull-policy=Never --restart=Never
  kubectl port-forward service/crawler 1983:1983
  minikube image ls --format table
  http://localhost:1983/crawler
   
   
  kubectl logs crawler
  kubectl get services      crawler
  kubectl delete pod crawler
  kubectl delete services  crawler
kubectl delete deployment crawler
 
==Ingress DNS==
{|
| valign="top" |
<syntaxhighlight lang='bash'>
minikube start
cat /etc/resolv.conf | grep nameserver
</syntaxhighlight>
 
| valign="top" |
<syntaxhighlight lang='bash'>
minikube addons enable ingress
minikube addons enable ingress-dns
</syntaxhighlight>
 
| valign="top" |
<syntaxhighlight lang='bash'>
nslookup academia.local
nslookup academia.local $(minikube ip)
</syntaxhighlight>
 
|-
|colspan="3"|
----
|-
|colspan="3"|
<syntaxhighlight lang='bash'>
kubectl get configmap coredns -n kube-system -o yaml
kubectl get configmap coredns -n kube-system -o "jsonpath={.data.Corefile}"
</syntaxhighlight>
 
|-
|colspan="3"|
----
|-
|colspan="3"|
'''Volatile Fixes'''
<syntaxhighlight lang='bash'>
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}
</syntaxhighlight>
 
|-
|colspan="3"|
----
|-
|colspan="3"|
'''Robust Fixes'''
<syntaxhighlight lang='bash'>
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
</syntaxhighlight>
 
|-
|colspan="3"|
----
|-
|colspan="2"|
sudo systemctl restart NetworkManager.service
systemctl status NetworkManager.service
systemctl status systemd-resolved
systemctl status dnsmasq
 
| valign="top" |
cat /etc/resolv.conf | grep nameserver
nmcli dev show | grep DNS
journalctl -u dnsmasq
tail /var/log/syslog
 
|-
|colspan="3"|
----
|-
|colspan="3"|
kubectl edit configmap coredns -n kube-system
<syntaxhighlight lang='properties' line>
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
</syntaxhighlight>
----
<syntaxhighlight lang='properties' line start='25' highlight='4-13'>
        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
</syntaxhighlight>
 
|-
|colspan="3"|
----
|-
|colspan="3"|
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===
----
{|
|valign='top'|
<syntaxhighlight lang="yaml">
cat << YML | kubectl apply -n kubernetes-dashboard -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: kubernetes-dashboard
    app.kubernetes.io/instance: kubernetes-dashboard
spec:
  ingressClassName: nginx
  rules:
    - host: "www.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: kubernetes-dashboard
                port:
                  number: 80
YML
</syntaxhighlight>
 
|valign='top'|
<syntaxhighlight lang="yaml">
cat <<YML | kubectl delete -n kubernetes-dashboard -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: kubernetes-dashboard
    app.kubernetes.io/instance: kubernetes-dashboard
spec:
  ingressClassName: nginx
  rules:
    - host: "www.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: kubernetes-dashboard
                port:
                  number: 80
YML
</syntaxhighlight>
 
|-
|colspan='2'|
----
|-
|valign='top'|
 
|valign='top'|
 
|}
 
==Mounts » 9P==
'''9P mounts''' are flexible and work across all hypervisors, but '''suffers from performance and reliability issues''' when used with large folders '''(>600 files)'''.
{|
|valign='top'|
<syntaxhighlight lang="bash">
MINIKUBE_BRIDGE="br-$(docker network ls -fname=minikube --format=json|jq -r '.ID')"
sudo ufw allow in on ${MINIKUBE_BRIDGE}
sudo ufw status numbered
sudo ufw reload
</syntaxhighlight>
 
|valign='top'|
<syntaxhighlight lang="bash">
cat << EXE | sudo -i -u minikube bash
      mkdir -p ${HOME}/volumes
minikube mount ${HOME}/volumes:/var/minikube --port=1980
EXE
</syntaxhighlight>
 
|}
 
==Tunnel==
{|
|valign='top'|
<syntaxhighlight lang="bash">
# check minikube user either exists or not
cat /etc/passwd|grep minikube
sudo usermod -aG sudo minikube
</syntaxhighlight>
 
|valign='top'|
<syntaxhighlight lang="bash">
# minikube no-password sudo access add to EOL
sudo visudo
minikube ALL=(ALL) NOPASSWD: ALL
</syntaxhighlight>
 
|valign='top'|
<syntaxhighlight lang="bash">
# login to minikube user and start tunneling
sudo -i -u minikube
minikube tunnel
</syntaxhighlight>
|}
 
==Playground==
{|
|valign="top"|
minikube image rm docker.io/jenkins/jenkins:2.452.1-jdk17
minikube image ls
 
|valign="top"|
minikube config view host-only-cidr
minikube config get  host-only-cidr
 
|valign="top"|
minikube config list
minikube status
 
|-
|colspan="3"|
----
|-
|valign="top"|
cat ~/.minikube/machines/minikube/config.json|jq -r '.Driver.NodeConfig.Memory'
cat ~/.minikube/machines/minikube/config.json|jq -r '.Driver.NodeConfig.CPU'
 
|valign="top"|
minikube config set memory 16384
minikube config get memory
 
|valign="top"|
minikube config view  memory
minikube config unset memory
 
|-
|colspan="3"|
----
|-
|valign="top"|
<syntaxhighlight lang="bash">
SYSTEM_RAM_LIMIT=$(awk '/^MemTotal:/ { print int($2/1024); }' /proc/meminfo)
SYSTEM_CPU_LIMIT=$(getconf _NPROCESSORS_ONLN)
minikube config view
minikube config
</syntaxhighlight>
 
|valign="top" colspan="2"|
<syntaxhighlight lang="bash">
minikube config set memory $((${SYSTEM_RAM_LIMIT}-1024*4))
minikube config set cpus  $((${SYSTEM_CPU_LIMIT}-4))
minikube config set host-only-cidr 10.20.23.1/24
minikube delete && minikube start
</syntaxhighlight>
 
|-
|colspan="3"|
----
|-
|valign="top"|
<syntaxhighlight lang="bash">
minikube start && minikube config view;\
for p in ingress ingress-dns dashboard metrics-server;\
do minikube addons enable ${p};done
</syntaxhighlight>
 
|valign="top" |
<syntaxhighlight lang="bash">
minikube stop && minikube start
minikube config view
minikube addons list
</syntaxhighlight>
 
|valign="top" |
kubectl cluster-info dump
kubectl cluster-info
kubectl plugin list
 
|-
|colspan='3'|
----
|-
|valign='top'|
<syntaxhighlight lang="bash">
kubectl config set-context  minikube --cluster=minikue
kubectl config set-context  minikube
kubectl config get-contexts
kubectl config get-clusters
kubectl config view
</syntaxhighlight>
 
|valign="top" colspan="2"|
<syntaxhighlight lang="bash">
minikube start -p v1.27 --kubernetes-version v1.27.0
minikube start -p v1.30 --kubernetes-version v1.30.0
minikube profile v1.30
minikube profile list
minikube profile
</syntaxhighlight>
 
|-
|colspan='3'|
----
|-
|valign='top'|
sudo -i -u minikube minikube status
sudo -i -u minikube minikube ip
minikube stop  -p v1.27
minikube delete -p v1.27
minikube tunnel
 
|valign='top'|
 
|valign='top'|
 
|}


==Knowledge==
==Knowledge==
Line 122: Line 520:
  minikube pause
  minikube pause
   
   
minikube delete
  minikube unpause
  minikube unpause
  minikube addons list
  minikube addons list
Line 131: Line 530:
  minikube config set memory 16384
  minikube config set memory 16384
    
    
minikube start --cpus 8 --memory 16384
  eval $(minikube -p minikube docker-env)
  eval $(minikube -p minikube docker-env)
  minikube start -p aged --kubernetes-version=v1.16.1
  minikube start -p aged --kubernetes-version=v1.16.1
Line 152: Line 552:
   
   
  docker logs crawler
  docker logs crawler
docker stop crawler && docker rm crawler


|valign="top"|
|valign="top"|
Line 166: Line 567:
   
   
  kubectl logs crawler
  kubectl logs crawler
kubectl delete pod crawler


|-
|-
Line 172: Line 574:
|-
|-
|colspan="2"|
|colspan="2"|
docker container inspect minikube \
<syntaxhighlight lang='bash'>
--format="{{ (index (index .NetworkSettings.Ports \"8443/tcp\") 0).HostPort }}"
docker container inspect minikube \
--format="{{ (index (index .NetworkSettings.Ports \"8443/tcp\") 0).HostPort }}"
 
docker container ls --filter=name=minikube --format="{{.Ports}}" | tr , \\n
</syntaxhighlight>
|-
|colspan="2"|
----
|-
|valign="top"|
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
 
|valign="top"|
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
 
|-
|colspan="2"|
----
|-
|valign="top"|
<syntaxhighlight lang='bash'>
minikube addons enable metallb
minikube addons enable olm
minikube addons list
</syntaxhighlight>
 
|valign="top"|
<syntaxhighlight lang='bash'>
minikube addons enable default-storageclass
minikube addons enable metrics-server
minikube addons configure metallb
</syntaxhighlight>
 
|-
|colspan="2"|
----
|-
|valign="top"|
<syntaxhighlight lang='bash'>
minikube addons enable storage-provisioner
minikube addons enable dashboard
 
minikube ssh
</syntaxhighlight>
 
|valign="top"|
minikube addons enable ingress-dns
minikube addons enable ingress
   
   
  docker container ls --filter=name=minikube --format="{{.Ports}}" | tr , \\n
  ping '''host.minikube.internal'''
 
|-
|colspan="2"|
----
|-
|colspan="2"|
kubectl get configmap coredns -n kube-system -o yaml
nslookup academia.local $(minikube ip)
 
|-
|colspan="2"|
----
|-
|valign="top"|
<syntaxhighlight lang='bash'>
getconf _NPROCESSORS_CONF
getconf _NPROCESSORS_ONLN
nproc --all
</syntaxhighlight>
 
|valign="top"|
grep ^cpu\\scores /proc/cpuinfo | uniq |  awk '{print $4}'
python -c 'import os; print(os.cpu_count())'
grep -c ^processor /proc/cpuinfo
 
|-
|colspan="2"|
----
|-
|valign="top"|
<syntaxhighlight lang='bash'>
awk '/^MemAvailable:/ { print $2/1024; }' /proc/meminfo
awk '/^MemTotal:/ { print $2/1024; }' /proc/meminfo
awk '/^MemFree:/ { print $2/1024; }' /proc/meminfo
</syntaxhighlight>
 
|valign="top"|


|}
|}
Line 214: Line 738:
* [https://minikube.sigs.k8s.io/docs/handbook/host-access/ Minikube Host Access]
* [https://minikube.sigs.k8s.io/docs/handbook/host-access/ Minikube Host Access]
* [https://minikube.sigs.k8s.io/docs/handbook/dashboard/ Minikube Dashboard]
* [https://minikube.sigs.k8s.io/docs/handbook/dashboard/ Minikube Dashboard]
* [https://minikube.sigs.k8s.io/docs/handbook/registry/ Minikube Registry]
* [[Minikube Registry]]
* [https://minikube.sigs.k8s.io/docs/handbook/addons/ Minikube Addons]
* [https://minikube.sigs.k8s.io/docs/handbook/addons/ Minikube Addons]


Line 233: Line 757:


| valign="top" |
| valign="top" |
* [https://www.bluematador.com/blog/safely-removing-pods-from-a-kubernetes-node Safely Delete Pods From a Kubernetes Node]
* [https://docs.oracle.com/en/operating-systems/olcne/1.1/orchestration/kubectl-setup-master.html Setting up the <code>kubectl</code> on a Master Node]
* [https://medium.com/@edmond.dantes/setup-minikube-with-docker-driver-2e27dc03f196 Setup Minikube with docker driver]
* [https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/ K8s » DNS Service » Customizing]
* [https://minikube.sigs.k8s.io/docs/handbook/addons/ingress-dns/ K8s » Minikube » Ingress DNS]
* [https://kubernetes.io/docs/reference/kubectl/cheatsheet/ <code>kubectl</code> Cheat Sheet]
* [https://minikube.sigs.k8s.io/docs/commands/ Minikube Commands]
* [https://stackoverflow.com/questions/66016567 Minikube Uninstall]
* [https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/ Minikube Ingress]
| valign="top" |
* [https://www.digitalocean.com/community/tutorials/how-to-use-minikube-for-local-kubernetes-development-and-testing K8s » Minikube » Development & Testing]
* [https://medium.com/kubernetes-tutorials/kubernetes-dns-for-services-and-pods-664804211501 K8s » DNS for Services and Pods]
* [https://stackoverflow.com/questions/50952240/ K8s » Connect to Host Database]
* [https://medium.com/@pczarkowski/kubernetes-tip-run-an-interactive-pod-d701766a12 K8s » Interactive Pod]
* [https://spacelift.io/blog/restart-kubernetes-pods-with-kubectl K8s » Restart Pods]
* [[Kubectl]]
* [[Helm]]
* [[Istio]]
* [[K8s]]
|-
| colspan="3" |
----
|-
| valign="top" |
* [https://magda.io/docs/how-to-setup-https-to-local-cluster.html Minikube » Create Self-Signed Cert Issuer]
* [https://stackoverflow.com/questions/63559779/ Minikube » Local FS As Persistent Volume]
* [https://minikube.sigs.k8s.io/docs/handbook/untrusted_certs/ Minikube » Untrusted Root Certificates]
* [https://github.com/kubernetes/minikube/issues/15616 Minikube » Clusters » Communication]
* [https://minikube.sigs.k8s.io/docs/tutorials/local_path_provisioner/ Minikube » Local Path Provisioner]
* [https://medium.com/@abdulfayis/storage-orchestration-for-kubernetes-c6370f943e23 K8s » Storage » Orchestration]
* [https://kubernetes.io/docs/concepts/storage/volumes/#hostpath K8s » Volume » HostPath]
* [https://kubernetes.io/docs/concepts/storage/volumes/#local K8s » Volume » Local]
* [https://jeyaramashok.github.io/posts/minikube-profiles/ Minikube » Profiles]
* [https://minikube.sigs.k8s.io/docs/commands/profile/ Minikube » Profile]
| valign="top" |
* [https://stackoverflow.com/questions/48534980/ Minikube » Mount Host directory into Pod]
* [https://itnext.io/setting-up-self-signed-https-access-to-local-dev-k8s-cluster-in-minikube-539bc62ad62f Minikube » Setting Up Self-Signed HTTPS]
* [https://stackoverflow.com/questions/55357287/ K8s » Patch » Node Selector On The Fly]
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]]
* [[K8s/Swiss Knife|K8s » Swiss Knife]]
* [[K8s/Ingress|K8s » Ingress]]
* [[K8s/Service|K8s » Service]]
* [[K8s/Run|K8s » Run]]
| valign="top" |
|-
| colspan="3" |
----
|-
| valign="top" |
* [https://stackoverflow.com/questions/6481005/ Bash » Get the number of CPUs in Linux]
* [https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/ <code>kubectl</code> » Extend with plugins]
* [https://unix.stackexchange.com/questions/415519/ Bash » Available memory]
* [[Minikube Ingress DNS]]
* [[Minikube Systemd]]
* [[Minikube Registry]]
* [[Minikube Tunnel]]
* [[Free Up RAM]]
* [[CIDR]]
* [[UFW]]
| valign="top" |
* [[Swap Space]]


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


|}
|}

Latest revision as of 21:11, 5 October 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
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key\
 | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.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-apt-keyring.gpg]\
 https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /
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 << YML | kubectl apply -n kubernetes-dashboard -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: kubernetes-dashboard
    app.kubernetes.io/instance: kubernetes-dashboard
spec:
  ingressClassName: nginx
  rules:
    - host: "www.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: kubernetes-dashboard
                port:
                  number: 80
YML
cat <<YML | kubectl delete -n kubernetes-dashboard -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: kubernetes-dashboard
    app.kubernetes.io/instance: kubernetes-dashboard
spec:
  ingressClassName: nginx
  rules:
    - host: "www.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: kubernetes-dashboard
                port:
                  number: 80
YML

Mounts » 9P

9P mounts are flexible and work across all hypervisors, but suffers from performance and reliability issues when used with large folders (>600 files).

MINIKUBE_BRIDGE="br-$(docker network ls -fname=minikube --format=json|jq -r '.ID')"
sudo ufw allow in on ${MINIKUBE_BRIDGE}
sudo ufw status numbered
sudo ufw reload
cat << EXE | sudo -i -u minikube bash
      mkdir -p ${HOME}/volumes
minikube mount ${HOME}/volumes:/var/minikube --port=1980
EXE

Tunnel

# check minikube user either exists or not
cat /etc/passwd|grep minikube
sudo usermod -aG sudo minikube
# minikube no-password sudo access add to EOL
sudo visudo
minikube ALL=(ALL) NOPASSWD: ALL
# login to minikube user and start tunneling
sudo -i -u minikube
minikube tunnel

Playground

minikube image rm docker.io/jenkins/jenkins:2.452.1-jdk17
minikube image ls
minikube config view host-only-cidr
minikube config get  host-only-cidr
minikube config list
minikube status

cat ~/.minikube/machines/minikube/config.json|jq -r '.Driver.NodeConfig.Memory'
cat ~/.minikube/machines/minikube/config.json|jq -r '.Driver.NodeConfig.CPU'
minikube config set memory 16384
minikube config get memory
minikube config view  memory
minikube config unset memory

SYSTEM_RAM_LIMIT=$(awk '/^MemTotal:/ { print int($2/1024); }' /proc/meminfo)
SYSTEM_CPU_LIMIT=$(getconf _NPROCESSORS_ONLN)
minikube config view
minikube config
minikube config set memory $((${SYSTEM_RAM_LIMIT}-1024*4))
minikube config set cpus   $((${SYSTEM_CPU_LIMIT}-4))
minikube config set host-only-cidr 10.20.23.1/24
minikube delete && minikube start

minikube start && minikube config view;\
for p in ingress ingress-dns dashboard metrics-server;\
do minikube addons enable ${p};done
minikube stop && minikube start
minikube config view
minikube addons list
kubectl cluster-info dump
kubectl cluster-info
kubectl plugin list

kubectl config set-context  minikube --cluster=minikue
kubectl config set-context  minikube
kubectl config get-contexts
kubectl config get-clusters
kubectl config view
minikube start -p v1.27 --kubernetes-version v1.27.0
minikube start -p v1.30 --kubernetes-version v1.30.0
minikube profile v1.30
minikube profile list
minikube profile

sudo -i -u minikube minikube status
sudo -i -u minikube minikube ip
minikube stop   -p v1.27
minikube delete -p v1.27
minikube tunnel

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)

getconf _NPROCESSORS_CONF
getconf _NPROCESSORS_ONLN
nproc --all
grep ^cpu\\scores /proc/cpuinfo | uniq |  awk '{print $4}'
python -c 'import os; print(os.cpu_count())'
grep -c ^processor /proc/cpuinfo

awk '/^MemAvailable:/ { print $2/1024; }' /proc/meminfo
awk '/^MemTotal:/ { print $2/1024; }' /proc/meminfo
awk '/^MemFree:/ { print $2/1024; }' /proc/meminfo

References