Jump to content

Minikube: Difference between revisions

From Haidhi Wiki
Created page with "Minikube buat latihan kubernetes == install (podman) == <syntaxhighlight lang=bash> curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64 minikube config set rootless true minikube start --driver=podman --container-runtime=cri-o </syntaxhighlight>"
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
minikube config set rootless true
minikube config set rootless true
minikube start --driver=podman --container-runtime=cri-o
minikube start --driver=podman --container-runtime=cri-o
</syntaxhighlight>
== cara import image ==
minikube pada dasarnya punya vm sendiri, jadi kita perlu import image docker/podman dari laptop kita ke minikube.
<syntaxhighlight lang=bash>
podman save my-image:latest -o my-image.tar
minikube image load my-image.tar
# konfirmasi
minikube image ls
</syntaxhighlight>
== command-command sakti ==
=== apply ===
<syntaxhighlight lang=bash>
kubectl apply -f file.yaml              # apply satu file
kubectl apply -f ./folder/              # apply semua yaml dalam folder
kubectl apply -f ./folder/ --recursive  # termasuk subfolder
kubectl apply -f https://url/file.yaml  # langsung dari URL
kubectl apply -f file.yaml --dry-run=client  # simulasi tanpa eksekusi
kubectl apply -f file.yaml --dry-run=server  # validasi di server (lebih akurat)
kubectl diff -f file.yaml                # lihat apa yang akan berubah sebelum apply
</syntaxhighlight>
=== delete ===
<syntaxhighlight lang=bash>
kubectl delete -f file.yaml              # delete dari file yaml
kubectl delete -f ./folder/              # delete semua dari folder
kubectl delete pod <name>                # delete pod (akan restart jika ada deployment)
kubectl delete deployment <name>        # delete deployment + pod-nya
kubectl delete service <name>            # delete service
kubectl delete all -l app=myapp          # delete semua resource by label
kubectl delete pod <name> --grace-period=0 --force  # force kill langsung
</syntaxhighlight>
=== restart/redeploy ===
<syntaxhighlight lang=bash>
kubectl rollout restart deployment <name>      # restart semua pod (zero downtime)
kubectl replace --force -f file.yaml            # delete lalu recreate resource
</syntaxhighlight>
=== yang ini hati-hati ===
<syntaxhighlight lang=bash>
kubectl delete all --all                # ⛔ hapus SEMUA di namespace aktif
kubectl delete all --all -A            # ⛔⛔ hapus SEMUA di SEMUA namespace
kubectl delete namespace <name>          # ⛔ hapus namespace + SEMUA isinya
kubectl delete pod <name> --force        # ⚠️ force kill, bisa corrupt state
</syntaxhighlight>
pastikan di namespace yang benar sebelum delete
<syntaxhighlight lang=bash>
kubectl config get-contexts            # lihat namespace aktif saat ini
</syntaxhighlight>
=== 📦 Pods ===
<syntaxhighlight lang=bash>
kubectl get pods                        # list semua pod
kubectl get pods -A                    # semua namespace
kubectl get pods -o wide                # + info node & IP
kubectl get pods --watch                # realtime update
kubectl describe pod <pod-name>        # detail lengkap pod
kubectl delete pod <pod-name>          # hapus pod (auto restart)
</syntaxhighlight>
=== 📜 Logs ===
<syntaxhighlight lang=bash>
kubectl logs <pod-name>                # log pod
kubectl logs <pod-name> -f              # follow/live log
kubectl logs <pod-name> --tail=100      # 100 baris terakhir
kubectl logs <pod-name> -c <container>  # jika multi-container
kubectl logs --previous <pod-name>      # log pod sebelum crash
</syntaxhighlight>
=== 🚀 Deployments ===
<syntaxhighlight lang=bash>
kubectl get deployments                # list deployment
kubectl describe deployment <name>      # detail deployment
kubectl rollout status deployment <name>      # status rollout
kubectl rollout history deployment <name>      # history versi
kubectl rollout undo deployment <name>        # rollback
kubectl scale deployment <name> --replicas=3  # scale up/down
kubectl set image deployment/<name> <container>=<image>:tag  # update image
</syntaxhighlight>
=== 🌐 Services ===
<syntaxhighlight lang=bash>
kubectl get services                    # list service
kubectl get svc                        # shorthand
kubectl describe svc <name>            # detail + endpoint
minikube service <name>                # buka di browser
minikube service list                  # list semua URL
</syntaxhighlight>
=== 🗺️ Semua Resource Sekaligus ===
<syntaxhighlight lang=bash>
kubectl get all                        # pod, svc, deploy, rs
kubectl get all -A                      # semua namespace
kubectl get all -n <namespace>          # namespace tertentu
</syntaxhighlight>
=== 🔧 Exec / Debug Masuk ke Pod ===
<syntaxhighlight lang=bash>
kubectl exec -it <pod-name> -- /bin/sh      # masuk shell
kubectl exec -it <pod-name> -- /bin/bash    # kalau ada bash
kubectl exec <pod-name> -- env              # lihat env vars
kubectl cp <pod-name>:/path/to/file ./file  # copy file keluar
</syntaxhighlight>
== 📊 Resource Usage (CPU/Memory) ===
<syntaxhighlight lang=bash>
kubectl top pods                        # CPU & memory tiap pod
kubectl top nodes                      # CPU & memory tiap node
</syntaxhighlight>
Perlu metrics-server: <code>minikube addons enable metrics-server</code>
=== 🏷️ Namespace ===
<syntaxhighlight lang=bash>
kubectl get namespaces                  # list namespace
kubectl get pods -n kube-system        # lihat sistem internal
kubectl config set-context --current --namespace=<ns>  # ganti default namespace
</syntaxhighlight>
=== 🔍 ConfigMap & Secret ===
<syntaxhighlight lang=bash>
kubectl get configmaps                  # list configmap
kubectl describe configmap <name>      # isi configmap
kubectl get secrets                    # list secret
kubectl describe secret <name>          # detail secret
kubectl get secret <name> -o jsonpath='{.data.<key>}' | base64 -d  # decode secret
</syntaxhighlight>
=== ⚙️ Events & Troubleshooting ===
<syntaxhighlight lang=bash>
kubectl get events                      # semua event di namespace
kubectl get events --sort-by='.lastTimestamp'  # urut by waktu
kubectl get events -A                  # semua namespace
kubectl describe pod <name>            # lihat bagian Events di bawah
</syntaxhighlight>
=== 🩺 Minikube Specific ===
<syntaxhighlight lang=bash>
minikube status                        # status cluster
minikube dashboard                      # buka dashboard GUI
minikube logs                          # log minikube
minikube ssh                            # SSH ke VM minikube
minikube addons list                    # list addon tersedia
minikube image ls                      # list image di minikube
</syntaxhighlight>
=== 💡 Tips Output Format ===
<syntaxhighlight lang=bash>
kubectl get pods -o yaml                # output YAML lengkap
kubectl get pods -o json                # output JSON
kubectl get pod <name> -o jsonpath='{.status.podIP}'  # ambil field spesifik
kubectl get pods --field-selector=status.phase=Running  # filter by status
kubectl get pods -l app=myapp          # filter by label
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 04:02, 27 February 2026

Minikube buat latihan kubernetes

install (podman)

curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64

minikube config set rootless true
minikube start --driver=podman --container-runtime=cri-o

cara import image

minikube pada dasarnya punya vm sendiri, jadi kita perlu import image docker/podman dari laptop kita ke minikube.

podman save my-image:latest -o my-image.tar
minikube image load my-image.tar

# konfirmasi
minikube image ls

command-command sakti

apply

kubectl apply -f file.yaml               # apply satu file
kubectl apply -f ./folder/               # apply semua yaml dalam folder
kubectl apply -f ./folder/ --recursive   # termasuk subfolder
kubectl apply -f https://url/file.yaml   # langsung dari URL

kubectl apply -f file.yaml --dry-run=client   # simulasi tanpa eksekusi
kubectl apply -f file.yaml --dry-run=server   # validasi di server (lebih akurat)

kubectl diff -f file.yaml                # lihat apa yang akan berubah sebelum apply

delete

kubectl delete -f file.yaml              # delete dari file yaml
kubectl delete -f ./folder/              # delete semua dari folder

kubectl delete pod <name>                # delete pod (akan restart jika ada deployment)
kubectl delete deployment <name>         # delete deployment + pod-nya
kubectl delete service <name>            # delete service
kubectl delete all -l app=myapp          # delete semua resource by label

kubectl delete pod <name> --grace-period=0 --force   # force kill langsung

restart/redeploy

kubectl rollout restart deployment <name>       # restart semua pod (zero downtime)
kubectl replace --force -f file.yaml            # delete lalu recreate resource

yang ini hati-hati

kubectl delete all --all                 # ⛔ hapus SEMUA di namespace aktif
kubectl delete all --all -A             # ⛔⛔ hapus SEMUA di SEMUA namespace
kubectl delete namespace <name>          # ⛔ hapus namespace + SEMUA isinya
kubectl delete pod <name> --force        # ⚠️ force kill, bisa corrupt state

pastikan di namespace yang benar sebelum delete

kubectl config get-contexts            # lihat namespace aktif saat ini

📦 Pods

kubectl get pods                        # list semua pod
kubectl get pods -A                     # semua namespace
kubectl get pods -o wide                # + info node & IP
kubectl get pods --watch                # realtime update
kubectl describe pod <pod-name>         # detail lengkap pod
kubectl delete pod <pod-name>           # hapus pod (auto restart)

📜 Logs

kubectl logs <pod-name>                 # log pod
kubectl logs <pod-name> -f              # follow/live log
kubectl logs <pod-name> --tail=100      # 100 baris terakhir
kubectl logs <pod-name> -c <container>  # jika multi-container
kubectl logs --previous <pod-name>      # log pod sebelum crash

🚀 Deployments

kubectl get deployments                 # list deployment
kubectl describe deployment <name>      # detail deployment
kubectl rollout status deployment <name>       # status rollout
kubectl rollout history deployment <name>      # history versi
kubectl rollout undo deployment <name>         # rollback
kubectl scale deployment <name> --replicas=3  # scale up/down
kubectl set image deployment/<name> <container>=<image>:tag  # update image

🌐 Services

kubectl get services                    # list service
kubectl get svc                         # shorthand
kubectl describe svc <name>             # detail + endpoint
minikube service <name>                 # buka di browser
minikube service list                   # list semua URL

🗺️ Semua Resource Sekaligus

kubectl get all                         # pod, svc, deploy, rs
kubectl get all -A                      # semua namespace
kubectl get all -n <namespace>          # namespace tertentu

🔧 Exec / Debug Masuk ke Pod

kubectl exec -it <pod-name> -- /bin/sh       # masuk shell
kubectl exec -it <pod-name> -- /bin/bash     # kalau ada bash
kubectl exec <pod-name> -- env               # lihat env vars
kubectl cp <pod-name>:/path/to/file ./file   # copy file keluar

📊 Resource Usage (CPU/Memory) =

kubectl top pods                        # CPU & memory tiap pod
kubectl top nodes                       # CPU & memory tiap node

Perlu metrics-server: minikube addons enable metrics-server

🏷️ Namespace

kubectl get namespaces                  # list namespace
kubectl get pods -n kube-system         # lihat sistem internal
kubectl config set-context --current --namespace=<ns>  # ganti default namespace

🔍 ConfigMap & Secret

kubectl get configmaps                  # list configmap
kubectl describe configmap <name>       # isi configmap
kubectl get secrets                     # list secret
kubectl describe secret <name>          # detail secret
kubectl get secret <name> -o jsonpath='{.data.<key>}' | base64 -d  # decode secret

⚙️ Events & Troubleshooting

kubectl get events                      # semua event di namespace
kubectl get events --sort-by='.lastTimestamp'   # urut by waktu
kubectl get events -A                   # semua namespace
kubectl describe pod <name>             # lihat bagian Events di bawah

🩺 Minikube Specific

minikube status                         # status cluster
minikube dashboard                      # buka dashboard GUI
minikube logs                           # log minikube
minikube ssh                            # SSH ke VM minikube
minikube addons list                    # list addon tersedia
minikube image ls                       # list image di minikube

💡 Tips Output Format

kubectl get pods -o yaml                # output YAML lengkap
kubectl get pods -o json                # output JSON
kubectl get pod <name> -o jsonpath='{.status.podIP}'  # ambil field spesifik
kubectl get pods --field-selector=status.phase=Running  # filter by status
kubectl get pods -l app=myapp           # filter by label