Minikube: Difference between revisions
Appearance
No edit summary |
No edit summary Β |
||
| Line 20: | Line 20: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== command sakti | == command-command sakti == | ||
=== apply === | === apply === | ||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
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