-
Notifications
You must be signed in to change notification settings - Fork 0
[KUBERNETES] CHEATSHEET
fourslickz edited this page Apr 15, 2026
·
5 revisions
doctl kubernetes cluster kubeconfig save <cluster-name>
kubectl config get-contexts
kubectl config use-context <context>
kubectl get nodes -o wide
kubectl cordon <node>
kubectl uncordon <node>
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
kubectl describe node <node>
kubectl get pods -A
kubectl describe pod <name>
kubectl apply -f app.yaml
kubectl delete -f app.yaml
kubectl rollout restart deployment <name>
kubectl rollout status deployment <name>
kubectl get ns
kubectl create ns staging
kubectl -n staging get pods
kubectl config set-context --current --namespace=staging
kubectl logs <pod>
kubectl logs <pod> -f
kubectl logs <pod> -c <container>
kubectl exec -it <pod> -- /bin/sh
kubectl debug <pod> -it --image=busybox
kubectl autoscale deploy app --min=2 --max=10 --cpu-percent=70
kubectl get hpa
doctl kubernetes node-pool list <cluster-id>
doctl kubernetes node-pool update <cluster-id> <pool-id> --auto-scale --min-nodes 2 --max-nodes 6
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-data
spec:
accessModes:
- ReadWriteOnce
storageClassName: do-block-storage
resources:
requests:
storage: 10GiapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app
spec:
ingressClassName: nginx
rules:
- host: app.domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-svc
port:
number: 80kubectl create secret generic db-secret --from-literal=DB_USER=root --from-literal=DB_PASS=pass123
kubectl create configmap app-config --from-file=config.json
- Gunakan namespace per aplikasi
- Pakai HPA + node autoscaling
- Tetapkan resource requests & limits
- Gunakan 1 ingress LB untuk hemat biaya
- DO CSI storage untuk PV
- Gunakan firewall DO
- Monitoring pakai Prometheus + DO metrics
- Rolling update wajib
1. ayo-pramuka
2. cert-manager
3. default
4. envoy-gateway-system
5. kube-node-lease
6. kube-public
7. kube-system
gateway.networking.k8s.io -> HTTPRoute
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
annotations:
cert-manager.io/cluster-issuer: letsencrypt
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"gateway.networking.k8s.io/v1","kind":"HTTPRoute","metadata":{"annotations":{"cert-manager.io/cluster-issuer":"letsencrypt","kubernetes.io/tls-acme":"true"},"name":"ayo-pramuka-production","namespace":"ayo-pramuka"},"spec":{"hostnames":["v2.ayopramuka-kwarnas.id"],"parentRefs":[{"name":"gateway","namespace":"envoy-gateway-system"}],"rules":[{"backendRefs":[{"kind":"Service","name":"ayo-pramuka-vue-service","port":80}],"filters":[{"type":"URLRewrite","urlRewrite":{"path":{"replacePrefixMatch":"/","type":"ReplacePrefixMatch"}}}],"matches":[{"path":{"type":"PathPrefix","value":"/"}}],"timeouts":{"request":"600s"}},{"backendRefs":[{"kind":"Service","name":"ayo-pramuka-dkn-vue-service","port":80}],"filters":[{"type":"URLRewrite","urlRewrite":{"path":{"replacePrefixMatch":"/","type":"ReplacePrefixMatch"}}}],"matches":[{"path":{"type":"PathPrefix","value":"/dewan-kerja"}}],"timeouts":{"request":"600s"}},{"backendRefs":[{"kind":"Service","name":"ayo-pramuka-kegiatan-vue-service","port":80}],"filters":[{"type":"URLRewrite","urlRewrite":{"path":{"replacePrefixMatch":"/","type":"ReplacePrefixMatch"}}}],"matches":[{"path":{"type":"PathPrefix","value":"/kegiatan-pramuka"}}],"timeouts":{"request":"600s"}},{"backendRefs":[{"kind":"Service","name":"ayo-pramuka-pendataan-vue-service","port":80}],"filters":[{"type":"URLRewrite","urlRewrite":{"path":{"replacePrefixMatch":"/","type":"ReplacePrefixMatch"}}}],"matches":[{"path":{"type":"PathPrefix","value":"/dokumen"}}],"timeouts":{"request":"600s"}},{"backendRefs":[{"kind":"Service","name":"ayo-pramuka-auth-vue-service","port":3000}],"filters":[{"type":"URLRewrite","urlRewrite":{"path":{"replacePrefixMatch":"/","type":"ReplacePrefixMatch"}}}],"matches":[{"path":{"type":"PathPrefix","value":"/jelajah"}}],"timeouts":{"request":"600s"}},{"backendRefs":[{"kind":"Service","name":"ayo-pramuka-auth-vue-service","port":3000}],"filters":[{"type":"URLRewrite","urlRewrite":{"path":{"replacePrefixMatch":"/auth/signin","type":"ReplacePrefixMatch"}}}],"matches":[{"path":{"type":"PathPrefix","value":"/auth/signin"}}],"timeouts":{"request":"600s"}}]}}
kubernetes.io/tls-acme: 'true'
creationTimestamp: '2026-04-07T01:53:23Z'
generation: 1
name: ayo-pramuka-production
namespace: ayo-pramuka
resourceVersion: '3195584'
uid: fa350146-bc01-4489-9215-de9396be93f5
selfLink: >-
/apis/gateway.networking.k8s.io/v1/namespaces/ayo-pramuka/httproutes/ayo-pramuka-production
status:
parents:
- conditions:
- lastTransitionTime: '2026-04-15T13:50:58Z'
message: Route is accepted
observedGeneration: 1
reason: Accepted
status: 'True'
type: Accepted
- lastTransitionTime: '2026-04-15T13:50:58Z'
message: >-
Failed to process route rule 3 backendRef 0: service
ayo-pramuka/ayo-pramuka-pendataan-vue-service not found.
observedGeneration: 1
reason: BackendNotFound
status: 'False'
type: ResolvedRefs
controllerName: gateway.envoyproxy.io/gatewayclass-controller
parentRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway
namespace: envoy-gateway-system
spec:
hostnames:
- v2.ayopramuka-kwarnas.id
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: gateway
namespace: envoy-gateway-system
rules:
- backendRefs:
- group: ''
kind: Service
name: ayo-pramuka-vue-service
port: 80
weight: 1
filters:
- type: URLRewrite
urlRewrite:
path:
replacePrefixMatch: /
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /
timeouts:
request: 600s
- backendRefs:
- group: ''
kind: Service
name: ayo-pramuka-dkn-vue-service
port: 80
weight: 1
filters:
- type: URLRewrite
urlRewrite:
path:
replacePrefixMatch: /
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /dewan-kerja
timeouts:
request: 600s
- backendRefs:
- group: ''
kind: Service
name: ayo-pramuka-kegiatan-vue-service
port: 80
weight: 1
filters:
- type: URLRewrite
urlRewrite:
path:
replacePrefixMatch: /
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /kegiatan-pramuka
timeouts:
request: 600s
- backendRefs:
- group: ''
kind: Service
name: ayo-pramuka-pendataan-vue-service
port: 80
weight: 1
filters:
- type: URLRewrite
urlRewrite:
path:
replacePrefixMatch: /
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /dokumen
timeouts:
request: 600s
- backendRefs:
- group: ''
kind: Service
name: ayo-pramuka-auth-vue-service
port: 3000
weight: 1
filters:
- type: URLRewrite
urlRewrite:
path:
replacePrefixMatch: /
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /jelajah
timeouts:
request: 600s
- backendRefs:
- group: ''
kind: Service
name: ayo-pramuka-auth-vue-service
port: 3000
weight: 1
filters:
- type: URLRewrite
urlRewrite:
path:
replacePrefixMatch: /auth/signin
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /auth/signin
timeouts:
request: 600s
kubectl get svc -n ayopramuka
kubectl get httproute -n ayopramuka
kubectl get httproute ayo-pramuka-passport-staging -n ayopramuka -o yaml > backup-passport.yaml
kubectl edit httproute ayo-pramuka-passport-staging -n ayopramuka
kubectl get svc -n ayopramuka
kubectl delete deployment ayo-pramuka-service-gamification -n ayopramuka
kubectl delete svc ayo-pramuka-service-gamification -n ayopramuka
kubectl get endpoints ayo-pramuka-gamification-service -n ayopramuka
kubectl get svc ayo-pramuka-gamification-service -n ayopramuka -o yaml
kubectl get pod -n ayopramuka --show-labels | grep gamification
kubectl get pod -n ayopramuka --show-labels | grep giat
kubectl edit svc ayo-pramuka-giat-service -n ayopramuka
kubectl edit svc ayo-pramuka-gamification-service -n ayopramuka
kubectl get endpoints ayo-pramuka-gamification-service -n ayopramuka