Kubectl / Get Other Resources
Get Other Resources
Use kubectl to list various Kubernetes resources like PVCs and Secrets in your namespace.
kubectl get <persistentvolumeclaims|secret|...> kubectl get <persistentvolumeclaims|secret|...> #!/bin/bash
# Get Other Resources
kubectl get {{persistentvolumeclaims|secret|...}} import subprocess
# Get Other Resources
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"kubectl",
"get",
"<persistentvolumeclaims|secret|...>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: kubectl not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
To audit resources in a namespace during security assessments.
Terminal Output
Expected runtime feedback
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
my-pvc Bound my-pv 10Gi RWO standard 5d
NAME TYPE DATA AGE
my-secret Opaque 1 5d Power User Variants
Optimized versions
kubectl get persistentvolumeclaims List all persistent volume claims in the current namespace.
kubectl get secrets List all secrets in the current namespace.
Unix Pipeline
Shell combinations
kubectl get persistentvolumeclaims -n my-namespace List PVCs in a specific namespace.
kubectl get secrets -o wide List secrets with additional details.
Troubleshooting
Common pitfalls
Error from server (NotFound): persistentvolumeclaims "my-pvc" not found
Solution: Ensure the PVC name is correct and exists in the specified namespace.
Error from server (Forbidden): secrets is forbidden: User "system:serviceaccount:default:default" cannot list resource "secrets"
Solution: Check your permissions and ensure the user has access to list secrets.
Command Breakdown
What each part is doing
-
kubectl - Base Command
- The executable that performs this operation. Here it runs Kubectl before the shell applies any redirect operators.
-
<persistentvolumeclaims|secret|...> - persistentvolumeclaims|secret|...
- The value supplied for persistentvolumeclaims|secret|....
How To Run
Execution path
- Step 1
Run `kubectl get persistentvolumeclaims` to list PVCs.
- Step 2
Run `kubectl get secrets` to list Secrets in the namespace.
- Step 3
Use `kubectl get <resource>` for other resource types.
Alternative Approaches
Comparable commands in other tools
Alternative kubernetes tools for the same job.
helm get <chart_release_name> Minikube / Start Minikube In Background Mode minikube start --background Minikube / Start Minikube With Custom Addons minikube start --addons <metrics-server> Kubens / List Namespaces Kubens kubens Kubens / Switch Previous Namespace Kubens kubens -