Belajar Kubernetes - Episode 17 - Bekerja dengan All Resources di Kubernetes

Belajar Kubernetes - Episode 17 - Bekerja dengan All Resources di Kubernetes

Di episode ini kita akan coba bahas kubectl all keyword untuk mengelola multiple Kubernetes resource sekaligus. Kita akan mempelajari cara menggunakan kubectl get all, kubectl delete all, dan memahami resource apa saja yang included di all.

Arman Dwi Pangestu
Arman Dwi PangestuMarch 20, 2026
0 views
8 min read

Pendahuluan

Catatan

Untuk kalian yang ingin membaca episode sebelumnya, bisa click thumbnail episode 16 di bawah ini

Episode 16Episode 16

Di episode sebelumnya kita sudah belajar tentang Node Selector untuk kontrol Pod placement di specific node. Selanjutnya di episode 17 kali ini, kita akan coba bahas all keyword di kubectl, yang menyediakan cara convenient untuk bekerja dengan multiple Kubernetes resource sekaligus.

Catatan: Disini saya akan menggunakan Kubernetes Cluster yang di install melalui K3s.

Saat mengelola Kubernetes cluster, kalian sering perlu view atau manage multiple resource type simultaneously. Daripada running separate command untuk Pod, Service, Deployment, dll, kubectl menyediakan all keyword sebagai shortcut untuk bekerja dengan common resource together.

Apa Itu All Keyword?

all keyword di kubectl adalah special resource type yang represent collection dari commonly used Kubernetes resource. Saat kalian gunakan kubectl get all, dia retrieve multiple resource type dalam single command, memberikan comprehensive view dari application component kalian.

Bayangkan all seperti preset filter yang include most frequently accessed resource - bukan literally "all resource" di cluster kalian, tapi rather curated list dari common workload-related resource.

Karakteristik kunci all keyword:

  • Multiple resource type - Retrieve beberapa resource type sekaligus
  • Convenience shortcut - Save time dibanding individual command
  • Namespace-scoped - Bekerja dalam specific namespace
  • Predefined list - Include specific resource type, bukan everything
  • Read dan delete operation - Bekerja dengan get, delete, dan describe command
  • Label filtering - Bisa dikombinasikan dengan label selector

Resource yang Included di All

all keyword include resource type ini:

  • pods (po) - Running container
  • services (svc) - Network service
  • deployments (deploy) - Deployment controller
  • replicasets (rs) - ReplicaSet controller
  • statefulsets (sts) - StatefulSet controller
  • daemonsets (ds) - DaemonSet controller
  • jobs - One-time task
  • cronjobs (cj) - Scheduled task
  • replicationcontrollers (rc) - Legacy ReplicationController

Important

Penting: all keyword TIDAK include semua resource type. Dia exclude ConfigMap, Secret, PersistentVolume, PersistentVolumeClaim, Namespace, Node, dan banyak resource lain.

Menggunakan kubectl get all

Penggunaan paling umum dari all adalah dengan get command.

Basic Usage

Get all resource di current namespace:

Kubernetesbash
sudo kubectl get all

Contoh output:

Kubernetesbash
NAME                              READY   STATUS    RESTARTS   AGE
pod/nginx-deployment-abc123-xyz   1/1     Running   0          5m
pod/nginx-deployment-abc123-def   1/1     Running   0          5m
pod/nginx-deployment-abc123-ghi   1/1     Running   0          5m
 
NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.43.0.1       <none>        443/TCP   30d
service/nginx        ClusterIP   10.43.100.50    <none>        80/TCP    5m
 
NAME                               READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-deployment   3/3     3            3           5m
 
NAME                                          DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-deployment-abc123       3         3         3       5m

Get All di Specific Namespace

View resource di specific namespace:

Kubernetesbash
sudo kubectl get all --namespace production

Atau gunakan shorthand:

Kubernetesbash
sudo kubectl get all -n production

Get All Across All Namespace

View resource across all namespace:

Kubernetesbash
sudo kubectl get all --all-namespaces

Atau gunakan shorthand:

Kubernetesbash
sudo kubectl get all -A

Output include namespace column:

Kubernetesbash
NAMESPACE     NAME                              READY   STATUS    RESTARTS   AGE
default       pod/nginx-abc123                  1/1     Running   0          5m
production    pod/api-xyz789                    1/1     Running   0          10m
development   pod/test-def456                   1/1     Running   0          2m
 
NAMESPACE     NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)
default       service/kubernetes   ClusterIP   10.43.0.1       <none>        443/TCP
production    service/api          ClusterIP   10.43.100.50    <none>        8080/TCP

Get All dengan Wide Output

Show additional detail seperti node placement dan IP address:

Kubernetesbash
sudo kubectl get all -o wide

Get All dengan Label Selector

Filter resource by label:

Kubernetesbash
sudo kubectl get all -l app=nginx

Get resource dengan specific label value:

Kubernetesbash
sudo kubectl get all -l environment=production

Get resource dengan multiple label:

Kubernetesbash
sudo kubectl get all -l app=nginx,environment=production

Get All dengan Field Selector

Filter by field value:

Kubernetesbash
sudo kubectl get all --field-selector status.phase=Running

Watch All Resource

Monitor resource secara real-time:

Kubernetesbash
sudo kubectl get all --watch

Atau gunakan shorthand:

Kubernetesbash
sudo kubectl get all -w

Menggunakan kubectl delete all

all keyword juga bekerja dengan delete command untuk remove multiple resource sekaligus.

Warning

Warning: Hati-hati dengan kubectl delete all karena dia remove multiple resource simultaneously. Selalu verify namespace dan gunakan label selector untuk avoid accidental deletion.

Delete All di Current Namespace

Delete all resource di current namespace:

Kubernetesbash
sudo kubectl delete all --all

Ini delete semua Pod, Service, Deployment, ReplicaSet, dll di current namespace.

Delete All di Specific Namespace

Delete all resource di specific namespace:

Kubernetesbash
sudo kubectl delete all --all --namespace development

Atau:

Kubernetesbash
sudo kubectl delete all --all -n development

Delete All dengan Label Selector

Delete hanya resource yang matching specific label:

Kubernetesbash
sudo kubectl delete all -l app=nginx

Delete resource dengan multiple label criteria:

Kubernetesbash
sudo kubectl delete all -l app=nginx,environment=development

Dry Run Sebelum Delete

Preview apa yang akan di-delete tanpa actually delete:

Kubernetesbash
sudo kubectl delete all --all --dry-run=client

Atau dengan server-side dry run:

Kubernetesbash
sudo kubectl delete all --all --dry-run=server

Delete dengan Confirmation

Get list resource sebelum deletion:

Kubernetesbash
# Pertama, lihat apa yang akan di-delete
sudo kubectl get all -l app=nginx
 
# Kemudian delete
sudo kubectl delete all -l app=nginx

Menggunakan kubectl describe all

Kalian juga bisa gunakan describe dengan all:

Kubernetesbash
sudo kubectl describe all

Ini show detailed information untuk all resource di current namespace.

Describe all resource dengan specific label:

Kubernetesbash
sudo kubectl describe all -l app=nginx

Contoh Praktis

Contoh 1: View Application Resource

Check all resource untuk specific application:

Kubernetesbash
sudo kubectl get all -l app=web-app

Output:

Kubernetesbash
NAME                           READY   STATUS    RESTARTS   AGE
pod/web-app-abc123-xyz         1/1     Running   0          10m
pod/web-app-abc123-def         1/1     Running   0          10m
 
NAME              TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
service/web-app   ClusterIP   10.43.50.100   <none>        80/TCP    10m
 
NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/web-app   2/2     2            2           10m
 
NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/web-app-abc123       2         2         2       10m

Contoh 2: Clean Up Development Environment

Remove all development resource:

Kubernetesbash
# Pertama, verify apa yang akan di-delete
sudo kubectl get all -n development
 
# Kemudian delete
sudo kubectl delete all --all -n development

Contoh 3: Monitor Application Deployment

Watch resource during deployment:

Kubernetesbash
sudo kubectl get all -l app=api -w

Contoh 4: Check Resource by Environment

View production resource:

Kubernetesbash
sudo kubectl get all -l environment=production -n production

View staging resource:

Kubernetesbash
sudo kubectl get all -l environment=staging -n staging

Contoh 5: Clean Up Failed Job

Delete all failed job dan pod nya:

Kubernetesbash
# View failed job
sudo kubectl get jobs --field-selector status.successful=0
 
# Delete all resource untuk failed job
sudo kubectl delete all -l job-name=<job-name>

Contoh 6: Application Lifecycle Management

Deploy dan verify application:

Kubernetesbash
# Deploy application
sudo kubectl apply -f app-deployment.yml
 
# Check all resource
sudo kubectl get all -l app=myapp
 
# Jika ada issue, delete dan redeploy
sudo kubectl delete all -l app=myapp
sudo kubectl apply -f app-deployment.yml

Apa yang TIDAK Included di All

Resource penting yang TIDAK included di all:

ConfigMap dan Secret

Kubernetesbash
# Tidak included di 'all'
sudo kubectl get configmaps
sudo kubectl get secrets

Persistent Volume dan Claim

Kubernetesbash
# Tidak included di 'all'
sudo kubectl get persistentvolumes
sudo kubectl get persistentvolumeclaims

Namespace

Kubernetesbash
# Tidak included di 'all'
sudo kubectl get namespaces

Node

Kubernetesbash
# Tidak included di 'all'
sudo kubectl get nodes

Service Account

Kubernetesbash
# Tidak included di 'all'
sudo kubectl get serviceaccounts

Ingress

Kubernetesbash
# Tidak included di 'all'
sudo kubectl get ingress

Custom Resource

Kubernetesbash
# Tidak included di 'all'
sudo kubectl get customresourcedefinitions

Getting Truly All Resource

Untuk get ALL resource type (including yang tidak di all):

Kubernetesbash
sudo kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n <namespace>

Atau untuk all namespace:

Kubernetesbash
sudo kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -A

Use Case Umum

Use Case 1: Quick Application Overview

Get quick overview dari application kalian:

Kubernetesbash
sudo kubectl get all -l app=myapp -o wide

Use Case 2: Namespace Cleanup

Clean up entire namespace:

Kubernetesbash
# Preview
sudo kubectl get all -n temp-namespace
 
# Delete
sudo kubectl delete all --all -n temp-namespace

Use Case 3: Troubleshooting

Check all resource saat troubleshooting:

Kubernetesbash
# Check current state
sudo kubectl get all
 
# Watch untuk change
sudo kubectl get all -w
 
# Get detailed info
sudo kubectl describe all

Use Case 4: Environment Comparison

Compare resource across environment:

Kubernetesbash
# Production
sudo kubectl get all -n production -l app=api
 
# Staging
sudo kubectl get all -n staging -l app=api

Use Case 5: Release Management

Manage application release:

Kubernetesbash
# Check current release
sudo kubectl get all -l release=v1.0
 
# Delete old release
sudo kubectl delete all -l release=v0.9
 
# Deploy new release
sudo kubectl apply -f release-v1.1.yml

Kesalahan Umum dan Pitfall

Kesalahan 1: Assume All Means Everything

Problem: Expect all include ConfigMap, Secret, PVC, dll.

Solusi: Remember all hanya include workload resource. Check resource lain separately:

Kubernetesbash
sudo kubectl get all
sudo kubectl get configmaps
sudo kubectl get secrets
sudo kubectl get pvc

Kesalahan 2: Delete Tanpa Verification

Problem: Running kubectl delete all --all tanpa check dulu.

Solusi: Selalu verify sebelum delete:

Kubernetesbash
# Pertama, lihat apa yang akan di-delete
sudo kubectl get all
 
# Kemudian delete jika yakin
sudo kubectl delete all --all

Kesalahan 3: Wrong Namespace

Problem: Delete resource di wrong namespace.

Solusi: Selalu specify namespace explicitly:

Kubernetesbash
# Check current namespace
sudo kubectl config view --minify | grep namespace
 
# Specify namespace explicitly
sudo kubectl delete all --all -n development

Kesalahan 4: Tidak Gunakan Label Selector

Problem: Delete lebih dari intended.

Solusi: Gunakan label selector untuk precision:

Kubernetesbash
# Daripada delete everything
# sudo kubectl delete all --all
 
# Delete specific app
sudo kubectl delete all -l app=myapp

Kesalahan 5: Lupa Dependent Resource

Problem: Delete all tapi leave ConfigMap, Secret, PVC.

Solusi: Delete dependent resource separately:

Kubernetesbash
sudo kubectl delete all -l app=myapp
sudo kubectl delete configmap -l app=myapp
sudo kubectl delete secret -l app=myapp
sudo kubectl delete pvc -l app=myapp

Kesalahan 6: Tidak Gunakan Dry Run

Problem: Accidentally delete production resource.

Solusi: Gunakan dry run dulu:

Kubernetesbash
# Dry run untuk lihat apa yang akan di-delete
sudo kubectl delete all --all --dry-run=client
 
# Jika correct, run actual delete
sudo kubectl delete all --all

Best Practice

Selalu Specify Namespace

Be explicit tentang namespace:

Kubernetesbash
# Bagus
sudo kubectl get all -n development
 
# Risky (gunakan default namespace)
sudo kubectl get all

Gunakan Label Selector

Filter resource dengan label:

Kubernetesbash
# Bagus - specific
sudo kubectl get all -l app=myapp,version=v2
 
# Less specific
sudo kubectl get all

Verify Sebelum Delete

Selalu check sebelum deletion:

Kubernetesbash
# Step 1: View
sudo kubectl get all -l app=myapp
 
# Step 2: Verify it's correct
# Step 3: Delete
sudo kubectl delete all -l app=myapp

Gunakan Dry Run untuk Destructive Operation

Test deletion dulu:

Kubernetesbash
sudo kubectl delete all --all -n temp --dry-run=client

Combine dengan Resource Type Lain

Jangan lupa non-all resource:

Kubernetesbash
# Delete application completely
sudo kubectl delete all -l app=myapp
sudo kubectl delete configmap -l app=myapp
sudo kubectl delete secret -l app=myapp
sudo kubectl delete pvc -l app=myapp
sudo kubectl delete ingress -l app=myapp

Gunakan Output Formatting

Get better visibility:

Kubernetesbash
# Wide output
sudo kubectl get all -o wide
 
# Custom column
sudo kubectl get all -o custom-columns=NAME:.metadata.name,KIND:.kind,STATUS:.status.phase
 
# JSON untuk scripting
sudo kubectl get all -o json

Document Cleanup Script Kalian

Buat documented cleanup script:

Kubernetescleanup-dev.sh
#!/bin/bash
# Cleanup development environment
 
echo "Cleaning up development namespace..."
 
# Show apa yang akan di-delete
echo "Resources to be deleted:"
kubectl get all -n development
 
# Confirm
read -p "Continue with deletion? (yes/no): " confirm
 
if [ "$confirm" = "yes" ]; then
    kubectl delete all --all -n development
    kubectl delete configmap --all -n development
    kubectl delete secret --all -n development
    echo "Cleanup complete"
else
    echo "Cleanup cancelled"
fi

Monitor During Operation

Watch resource during operation:

Kubernetesbash
# Terminal 1: Watch resource
sudo kubectl get all -w
 
# Terminal 2: Perform operation
sudo kubectl apply -f deployment.yml

Alternative Command

Get Specific Resource Type

Daripada all, specify exact type:

Kubernetesbash
sudo kubectl get pods,services,deployments

Get Resource by API Group

Get resource dari specific API group:

Kubernetesbash
sudo kubectl get deployments.apps,statefulsets.apps

Gunakan Custom Alias

Buat shell alias untuk common operation:

bash
alias kga='kubectl get all'
alias kgaa='kubectl get all --all-namespaces'
alias kdaa='kubectl delete all --all'

Penutup

Pada episode 17 ini, kita telah membahas bekerja dengan all keyword di Kubernetes. Kita sudah belajar apa yang included di all, cara menggunakannya dengan get dan delete command, dan important consideration saat bekerja dengan multiple resource.

Key takeaway:

  • all adalah shortcut untuk common workload resource
  • Include Pod, Service, Deployment, ReplicaSet, StatefulSet, DaemonSet, Job, CronJob
  • TIDAK include ConfigMap, Secret, PVC, Namespace, Node, dan banyak lainnya
  • Bekerja dengan get, delete, dan describe command
  • Bisa dikombinasikan dengan label selector dan namespace filter
  • Selalu verify sebelum delete dengan all
  • Gunakan dry run untuk destructive operation
  • Specify namespace explicitly untuk avoid mistake
  • Remember untuk handle non-all resource separately
  • Gunakan label selector untuk precise resource management

all keyword adalah convenient tool untuk manage Kubernetes resource, tapi require careful use, especially dengan delete operation. Dengan memahami apa yang included dan follow best practice, kalian bisa efficiently manage cluster resource sambil avoid common pitfall.

Bagaimana, makin jelas kan tentang bekerja dengan all resource di Kubernetes? Di episode 18 berikutnya, kita akan membahas Service, salah satu konsep paling fundamental di Kubernetes networking untuk expose dan access application. Jadi, pastikan tetap semangat belajar dan nantikan episode selanjutnya!

Catatan

Untuk kalian yang ingin lanjut ke episode berikutnya, bisa click thumbnail episode 18 di bawah ini

Episode 18Episode 18

Related Posts