🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsHeader and Footer not showing in Excel(14.09.2026 um 22:43 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsHeader and Footer not showing in Excel(14.09.2026 um 22:43 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 4 Min Lesezeit
0

Managing Kubernetes Resources: A Comprehensive Guide to Create, Update, Delete, and Watch Operations

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Managing Kubernetes Resources (Create, Update, Delete, Watch)



Kubernetes provides a rich API that allows developers and administrators to interact with and manage cluster resources such as Pods, Services, Deployments, ConfigMaps, and more. Managing Kubernetes resources involves actions like creating, updating, deleting, and monitoring these resources.



This article explores the core operations for managing Kubernetes resources using the kubectl CLI and the Kubernetes API.









Core Kubernetes Resource Management Actions





  1. Create: Add new resources to the cluster.


  2. Update: Modify existing resources in the cluster.


  3. Delete: Remove resources from the cluster.


  4. Watch: Monitor changes to resources in real-time.









1. Creating Kubernetes Resources



Resources in Kubernetes can be created either declaratively (using YAML/JSON files) or imperatively (direct commands).






Declarative Creation



Declarative resource management involves defining the desired state of a resource in a YAML/JSON file and applying it to the cluster using the kubectl apply command.



Example: Create a Deployment




CODE
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80






Apply the file:




CODE
kubectl apply -f deployment.yaml









Imperative Creation



Imperative resource management allows you to create resources directly from the command line.



Example: Create a Pod Imperatively




CODE
kubectl run my-pod --image=nginx:1.21 --port=80












2. Updating Kubernetes Resources



You can update resources using both imperative and declarative approaches.






Imperative Updates



Imperative updates modify resource fields using commands.



Example: Scale a Deployment




CODE
kubectl scale deployment my-deployment --replicas=5









Declarative Updates



Declarative updates involve modifying the YAML/JSON definition and reapplying it.



Steps:




  1. Edit the deployment.yaml file:




CODE
   spec:
replicas: 5







  1. Apply the updated file:




CODE
   kubectl apply -f deployment.yaml









Direct Editing



You can also edit resources directly in the cluster:




CODE
kubectl edit deployment my-deployment






This command opens the resource definition in your default text editor, where you can make changes.









3. Deleting Kubernetes Resources



Kubernetes allows you to delete resources both declaratively and imperatively.






Delete Using YAML File



To delete resources managed by a YAML file:




CODE
kubectl delete -f deployment.yaml









Delete Resources by Name



You can delete specific resources by name using kubectl delete.



Example: Delete a Deployment




CODE
kubectl delete deployment my-deployment









Delete All Resources of a Type



You can delete all resources of a specific type in a namespace:




CODE
kubectl delete pods --all









Force Delete Stuck Resources



If a resource is stuck in a terminating state, you can force delete it:




CODE
kubectl delete pod my-pod --grace-period=0 --force












4. Watching Kubernetes Resources



Kubernetes supports watching resources to monitor real-time changes. This is useful for debugging or understanding how resources behave.






Watch Using kubectl



The --watch flag allows you to monitor changes to a resource.



Example: Watch Pods in Real-Time




CODE
kubectl get pods --watch









Watch Resource Events



Kubernetes events provide details about what’s happening in the cluster.



Example: View Events




CODE
kubectl get events --watch









Describe Resources for Details



The kubectl describe command gives detailed information about a resource.



Example: Describe a Pod




CODE
kubectl describe pod my-pod












Namespace Management



Namespaces are used to organize resources in a cluster. Most kubectl commands allow specifying a namespace using the -n flag.






Examples:





  • List all resources in a namespace:




CODE
  kubectl get all -n my-namespace








  • Create resources in a specific namespace:




CODE
  kubectl apply -f deployment.yaml -n my-namespace












Advanced Management Techniques






Dry-Run Mode



The --dry-run flag simulates the creation, update, or deletion of a resource without making actual changes.



Example: Test Resource Creation




CODE
kubectl apply -f deployment.yaml --dry-run=client









Export Resource YAML



You can export the definition of an existing resource for backup or modification.



Example: Export Deployment YAML




CODE
kubectl get deployment my-deployment -o yaml > deployment-export.yaml









Patch Resources



Patching modifies specific fields in a resource without replacing the entire object.



Example: Add an Annotation




CODE
kubectl patch deployment my-deployment -p '{"metadata": {"annotations": {"key": "value"}}}'












Best Practices for Resource Management





  1. Use Declarative Configuration: Store all resource definitions in version-controlled YAML files for consistency and traceability.


  2. Leverage Namespaces: Use namespaces to isolate environments (e.g., dev, staging, production).


  3. Monitor Resources: Regularly use kubectl get, kubectl describe, and kubectl logs to monitor the health of resources.


  4. Automate Resource Management: Use CI/CD pipelines to automate the deployment and update of Kubernetes resources.









Conclusion



Managing Kubernetes resources efficiently requires understanding the key operations: create, update, delete, and watch. Kubernetes provides powerful tools like kubectl and declarative configuration to simplify these tasks. By mastering these core operations, you can ensure your applications and infrastructure run smoothly in a Kubernetes environment.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Mastering Claude and ChatGPT: Developers Guide to Advanced Prompting
1 Quelle
Build vs Buy: When to Outsource Machine Learning Development
1 Quelle
SchemaCrawler LLM Context: Extract and Prune Relational DB Schemas
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Managing Kubernetes Resources: A Comprehensive Guide to Create, Update, Delete, and Watch Operations

Thematisch verwandte Begriffe: Managing, Kubernetes, Resources, Comprehensive · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...