The Complete Guide to the `kubectl delete secret` Command

When a live application goes down, deployments fail, and pods enter a CreateContainerConfigError loop, a common root cause is an in-use secret being deleted. In Kubernetes, kubectl delete secret is irreversible; without a recovery plan, the blast radius can be immediate and severe. This guide targets practitioners who want to avoid this failure mode—or remediate it under pressure—by outlining safe deletion practices, how to diagnose deletion-related failures, and how to restore service quickly after an accidental secret removal.

Unified Cloud Orchestration for Kubernetes

Manage Kubernetes at scale through a single, enterprise-ready platform.

GitOps Deployment
Secure Dashboards
Infrastructure-as-Code
Book a demo

Key takeaways:

  • Always confirm a secret has no active dependencies: Before running a delete command, check for any references in running pods, service accounts, and deployment manifests to prevent application failures and unexpected outages.
  • Use command flags for safer operations: Incorporate flags like --dry-run=client to preview changes before execution and --namespace to ensure you are targeting the correct resource in the correct environment.
  • Adopt a GitOps workflow for lifecycle management: Transition from manual kubectl commands to managing secrets as code. This declarative approach provides version control, peer review, and a clear audit trail, turning a high-risk task into a safe, automated process.

What Are Kubernetes Secrets?

Kubernetes Secrets are API objects used to store and manage sensitive data such as passwords, OAuth tokens, SSH keys, and TLS material. They decouple confidential values from application code, container images, and manifests by letting Pods reference secrets at runtime instead of hardcoding credentials in YAML. This enables applications and services within a cluster to authenticate and access protected resources without leaking secrets into version control or build artifacts.

By default, Secrets are stored in etcd as base64-encoded values, not encrypted data. Anyone with sufficient API access can read or mutate a Secret, and direct access to etcd exposes the data in clear text. Base64 prevents accidental disclosure only; it is not a security control. Production clusters must enable encryption at rest for etcd and enforce least-privilege access with RBAC. At scale, teams typically adopt a centralized management layer—such as Plural—to standardize policies, audit access, and prevent configuration drift across clusters. Kubernetes here refers to Kubernetes.

Key Types of Kubernetes Secrets

Kubernetes supports multiple built-in Secret types that enable validation and tighter integrations. While Opaque works for arbitrary key-value data, using a specific type simplifies workflows and reduces errors.

  • Opaque: Default type for arbitrary user-defined data.
  • kubernetes.io/service-account-token: Managed by Kubernetes; stores ServiceAccount tokens that are auto-created and mounted into Pods.
  • kubernetes.io/dockerconfigjson: Registry credentials for pulling private images.
  • kubernetes.io/tls: TLS certificate and private key, commonly consumed by Ingress.
  • kubernetes.io/ssh-auth: SSH authentication credentials.

Why Secure Secret Management Is Critical

Secrets prevent credentials from being embedded in code or configuration, reducing exposure in repositories and making rotation feasible without rebuilding images. As environments grow, however, secrets tend to proliferate. This “secret sprawl” leaves behind unused or orphaned secrets that still contain valid credentials and often lack monitoring or ownership.

Orphaned secrets expand the attack surface and can become long-lived backdoors if compromised. Effective lifecycle management—creation, rotation, access control, and secure deletion—is therefore a core security requirement, not an operational afterthought. Platforms like Plural help enforce consistent secret policies, visibility, and safe cleanup across large Kubernetes estates.

How to Create and Manage Secrets with kubectl

Before deleting a Secret, you need to understand how it is created and consumed. kubectl is the primary CLI for interacting with Secrets in Kubernetes. It is well suited for ad-hoc operations and debugging, but it does not scale cleanly across multiple clusters or environments. At scale, a GitOps workflow—often managed through a platform like Plural—is required to ensure consistency, auditability, and controlled change propagation. That said, fluency with the core kubectl operations is essential.

Create a Secret

You can create Secrets imperatively in a few common ways.

Using literals is convenient for simple key-value data but risky because values can end up in shell history:

kubectl create secret generic my-secret \
  --from-literal=username=admin \
  --from-literal=password=s3cr3t

A safer and more flexible approach is file-based creation. This keeps raw values out of the command line and works well for multi-line data such as certificates or private keys:

kubectl create secret generic my-secret \
  --from-file=./username.txt \
  --from-file=./password.txt

Each file becomes a key in the Secret, with the file contents as the value.

View Existing Secrets

To get a high-level view of Secrets in a namespace:

kubectl get secrets

For metadata and structure, use:

kubectl describe secret my-secret

This shows labels, annotations, type, and key names, but not the values. To inspect a value for debugging, you must explicitly decode it:

kubectl get secret my-secret \
  -o jsonpath='{.data.password}' | base64 --decode

This is often necessary when validating application configuration or diagnosing startup failures.

Update a Secret

Secrets are mutable by default. The most direct update path is:

kubectl edit secret my-secret

This opens the Secret manifest in your editor. Any values you modify must remain Base64-encoded. Once saved, Kubernetes applies the update immediately.

Be aware of consumption semantics:

  • Pods that read Secrets via environment variables will not see updates until they are restarted.
  • Pods that mount Secrets as volumes will eventually see updated files, subject to kubelet refresh timing.

In production environments, imperative edits should be treated as exceptions. GitOps-driven updates, enforced through Plural, provide controlled rollouts, audit trails, and safer recovery when something goes wrong.

How to Use the kubectl delete secret Command

The kubectl delete secret command is a core lifecycle operation for Secrets in Kubernetes. The syntax is simple, but the impact is not: deletion is irreversible and can immediately break Pods that reference the Secret for configuration, credentials, or certificates. Before deleting anything, you should identify all dependent workloads and confirm the Secret is no longer required. This section covers safe, intentional deletion patterns—from single resources to label-driven bulk operations.

Basic Deletion

To delete a single Secret in the current namespace, specify its name:

kubectl delete secret db-auth-old

This permanently removes the Secret. If a Pod references it, new Pods will fail to start and existing Pods may break on restart.

Always be explicit about namespaces when working outside your default context:

kubectl delete secret db-auth-old -n production

This avoids deleting a similarly named Secret in the wrong environment, which is a common and costly mistake.

Delete Multiple Secrets at Once

You can delete multiple Secrets in a single command by listing their names. This is useful when retiring an application or cleaning up rotated credentials:

kubectl delete secret api-key-v1 tls-cert-v1 -n web-app

This approach is efficient and script-friendly, reducing the risk of partial cleanup or forgotten resources.

Target Secrets with Labels and Selectors

For large-scale or structured cleanups, label-based deletion is the safest and most scalable option. Labels let you group Secrets by application, environment, or ownership and act on them as a set.

Delete all Secrets matching a label selector:

kubectl delete secret -l project=phoenix -n staging

This removes every Secret labeled project=phoenix in the staging namespace. Compared to manually enumerating names, selectors are less error-prone and essential for maintaining hygiene in long-lived clusters.

In mature environments, imperative deletions should be the exception. GitOps workflows—enforced through platforms like Plural—provide reviewability, auditing, and safer rollbacks when secret lifecycle changes are required.

Key Flags for kubectl delete secret

The kubectl delete secret command is straightforward, but its behavior can be fine-tuned using several flags. Understanding these options is essential for executing precise and safe operations, especially in automated scripts or complex environments. These key command flags give you greater control over the deletion process, helping you prevent errors, manage graceful shutdowns, and verify your actions before they become permanent. Let's look at the most important flags you should know.

--ignore-not-found

When running automated cleanup scripts, you might try to delete a secret that has already been removed. By default, this action would return an error and potentially halt your script. Using the --ignore-not-found flag prevents this by telling kubectl to exit with a status code of 0 if the secret doesn't exist. This makes your automation more resilient and idempotent, ensuring that scripts can run to completion without failing on resources that are already gone. It’s a simple but effective way to build more robust operational workflows.

--grace-period

Kubernetes resources, particularly pods, are designed to shut down gracefully. The --grace-period flag specifies the duration (in seconds) that Kubernetes should wait before forcefully terminating a resource. For a pod using a secret, this period allows its containers to finish active processes, close connections, and unmount volumes cleanly. The default is 30 seconds. While you can set --grace-period=0 to delete it immediately, this is functionally similar to using the --force flag and carries the same risks of abrupt termination and potential data inconsistency.

--force

The --force flag enables immediate, forceful deletion of a resource, bypassing the graceful termination period entirely. This is a powerful but risky option that should be used with extreme caution. It’s typically reserved for situations where a resource is stuck in a Terminating state and unresponsive to a standard delete command. Forcibly deleting a pod does not guarantee that the processes running inside it have stopped cleanly, which can lead to data corruption or leave applications in an inconsistent state. Think of it as a last resort, not a standard operational tool.

--dry-run

Before executing any destructive command, it’s wise to verify what it will actually do. The --dry-run=client flag lets you preview the outcome of a delete command without making any changes to your cluster. It prints the object that would be deleted to your terminal, allowing you to confirm you’ve targeted the correct secret, especially when using labels or deleting multiple resources at once. Incorporating --dry-run into your workflow is a critical safety measure that helps prevent accidental deletion of essential secrets and minimizes the risk of production incidents.

What Happens When You Delete a Secret in Use?

Deleting a Secret in Kubernetes is immediate and irreversible. The object is removed from etcd without a grace period or finalizers, and any workload that depends on it is now in an invalid state. The most dangerous aspect is delayed failure: running Pods may appear healthy because they already loaded the Secret, but the next restart, rollout, or scale event will surface the problem and can take the application offline.

This creates a latent outage condition. Everything looks stable until Kubernetes attempts to create a new Pod that references the missing Secret, at which point failures cascade. Preventing this requires understanding dependency paths before deletion and having visibility into which workloads consume which Secrets—something that becomes significantly harder without a centralized view, such as the one Plural provides.

How Pods Behave with Missing Secrets

Pod behavior depends on how the Secret is consumed:

  • Secret mounted as a volume:
    Running containers continue to read the existing files. On restart, the kubelet cannot mount the volume because the Secret no longer exists, and the Pod fails with CreateContainerConfigError.
  • Secret injected as environment variables:
    Running containers keep the original values because env vars are set only at startup. Any new Pod creation fails immediately because the referenced Secret cannot be resolved.

In both cases, failure is deferred until Kubernetes needs to create or restart a Pod.

Common Application Failure Scenarios

Deleting an in-use Secret commonly breaks systems in the following ways:

  • Failed deployments or rollouts: New replicas cannot start, causing rolling updates to stall and leaving applications partially updated.
  • Image pull failures: If the Secret was an imagePullSecret, new Pods fail with ImagePullBackOff when accessing a private registry.
  • Unexpected outages after restarts: A previously healthy Pod crashes for an unrelated reason, but cannot restart because its Secret is missing, turning a transient issue into a sustained outage.

These failures are often misdiagnosed because the deletion event may have happened earlier.

Recovery Strategies

Recovery starts by recreating the Secret with the same name and valid data. If the contents are not backed up, credentials must be regenerated or recovered from a secure source. This is where declarative management matters: in a GitOps workflow, restoring a Secret is as simple as reapplying the manifest from version control.

After restoring the Secret, you must recycle affected Pods:

kubectl rollout restart deployment/<deployment-name>

This forces controllers to recreate Pods so they can successfully mount or read the restored Secret. Platforms like Plural reduce recovery time by ensuring Secrets are tracked, auditable, and reproducible, turning a high-severity incident into a controlled remediation instead of a scramble.

How to Safely Verify Secret Dependencies

Deleting a secret that is actively used by an application is one of the fastest ways to cause an outage. Before you run kubectl delete secret, you must verify that no pods, service accounts, or other resources depend on it. This verification process protects your applications from unexpected failures and ensures that the deletion is safe and intentional. A few minutes of due diligence can save you hours of troubleshooting downtime.

The following steps outline a systematic approach to identifying and resolving these dependencies directly within your Kubernetes environment. For teams managing dozens or hundreds of clusters, this process can be time-consuming. Plural’s single-pane-of-glass console provides a centralized view of all your resources, allowing you to quickly search for dependencies across your entire fleet without switching contexts or running repetitive commands. This visibility is key to managing configurations at scale and preventing accidental disruptions.

Check Pod Configurations

First, you need to determine if any running pods are mounting the secret as a volume or using it to populate environment variables. A pod’s configuration, or spec, defines its relationship with other Kubernetes objects, including secrets. If a pod references a secret that you delete, it may fail to start or crash during runtime when it can no longer access the required data.

You can search for pods referencing a specific secret by inspecting their YAML definitions across all namespaces. Use a command that filters the output to find relevant configurations: kubectl get pods --all-namespaces -o yaml | grep -C 5 "secretName: <your-secret-name>"

If this command returns any results, you must update each pod’s configuration to remove the reference. This typically involves modifying the parent resource, such as a Deployment or StatefulSet, and applying the changes to trigger a rolling update. Only after all pods have been updated and are running successfully without the secret should you proceed with deletion.

Identify Which Service Accounts Use the Secret

Secrets are frequently used to store tokens for service accounts or credentials for pulling images from private container registries. Deleting a secret tied to a service account can break authentication flows, preventing pods from accessing the Kubernetes API or failing to pull necessary container images. This is a common cause of ImagePullBackOff errors.

To check for these dependencies, inspect the service accounts in the relevant namespace. You can retrieve the YAML definition of a service account to see which secrets it references: kubectl get serviceaccount <service-account-name> -n <namespace> -o yaml

Look for the secrets and imagePullSecrets fields in the output. If the secret you intend to delete is listed, you must first update the service account to remove the reference. Ensuring that RBAC policies and service account configurations are correct across a large environment is a significant challenge, but it's critical for security and stability.

Scan Your Deployment Manifests

While inspecting the live cluster is essential, your infrastructure's source of truth is likely a Git repository, especially if you follow a GitOps workflow. If a secret is defined in your Kubernetes manifests (like Helm charts or Kustomize overlays), deleting it directly from the cluster is only a temporary fix. The next time your GitOps controller syncs, it may re-create the secret or, worse, your application deployment will fail because it references a secret that no longer exists.

Before deleting a secret, always search your codebase for its name. This ensures you remove all references from your deployment manifests first. With a platform like Plural, this process is built into your workflow. You would first create a pull request to remove the secret from your manifests. Once merged, Plural CD automatically syncs this change to your clusters, safely decoupling the dependencies before you permanently delete the secret object. This Git-driven approach provides a clear audit trail and prevents configuration drift.

Common Mistakes to Avoid When Deleting Secrets

Using kubectl delete secret seems straightforward, but a single mistake can disrupt applications and compromise your environment. These errors often stem from a lack of visibility into dependencies or a misunderstanding of how kubectl operates across different scopes. For example, deleting a secret that a critical application relies on for database credentials will immediately break its connection, potentially causing an outage. Similarly, running the command in the wrong cluster context can have catastrophic consequences, wiping out production configurations instead of test data.

Avoiding these common pitfalls is essential for maintaining stable and secure Kubernetes clusters. It requires a methodical approach where you verify dependencies, understand the full impact of command flags, and confirm your operational context before execution. By being deliberate and aware of your environment, you can prevent accidental outages caused by improper secret deletion and ensure your cluster operations remain smooth and predictable.

Deleting Without Checking Dependencies

One of the most critical errors is deleting a secret without verifying which applications depend on it. Secrets are often shared across multiple Pods, Deployments, and Services. Removing a secret that is still in use will cause any application relying on it to fail, likely during its next restart or deployment cycle. Before running the delete command, you must confirm that the secret is no longer mounted as a volume or consumed as an environment variable by any active workload. This requires a thorough audit of your deployment manifests and running pods to trace all references to the secret in question.

Using --force Without Understanding the Impact

The --force flag is a powerful but dangerous tool. It bypasses the standard graceful termination period, immediately removing the secret from the API server. While this might seem useful for stuck resources, it can have severe consequences. Forcibly deleting a secret doesn't give the kubelet on the node time to unmount it cleanly from running pods, which can lead to inconsistent states and application crashes. According to the official Kubernetes documentation, force deletion does not wait for confirmation that the resource has been terminated. You should reserve this option for situations where a graceful deletion has failed and you fully understand the potential fallout.

Forgetting the Namespace

Kubernetes secrets are namespaced objects, meaning they exist only within a specific namespace. A common mistake is to run kubectl delete secret <secret-name> without specifying a namespace with the -n or --namespace flag. When you omit the namespace, kubectl defaults to the default namespace, which is likely not where your intended secret resides. This can lead to two outcomes: either the command fails because the secret doesn't exist in the default namespace, or worse, you accidentally delete a secret with the same name from the wrong place. Always be explicit with your commands, such as kubectl delete secret <secret-name> --namespace <namespace-name>, to ensure you are targeting the correct resource.

Working in the Wrong Context or Namespace

Similar to forgetting a namespace, executing commands in the wrong Kubernetes context can have disastrous consequences. A context determines which cluster your kubectl client is communicating with. Without careful verification, it's easy to accidentally delete a production secret when you intended to work in a staging or development environment. This type of human error can cause significant outages. Using a centralized platform like Plural provides a single-pane-of-glass console that gives you clear, consistent visibility across your entire fleet. This helps ensure you are always aware of which cluster and namespace you are targeting, dramatically reducing the risk of executing destructive commands in the wrong environment.

Best Practices for Deleting Secrets Safely

Deleting a Kubernetes secret is an irreversible action that can have immediate and severe consequences if not handled carefully. A single mistake can lead to application downtime, data corruption, or security vulnerabilities. To prevent these issues, it’s essential to adopt a systematic approach that prioritizes safety and verification. Following a set of best practices ensures that you remove secrets cleanly without disrupting services or compromising your cluster's integrity. These procedures aren't just about running the right command; they're about building a reliable operational workflow around the entire secret lifecycle.

This means treating secret management with the same discipline as code deployment. A pre-deletion checklist confirms that a secret is no longer in use, while a backup plan provides a safety net against human error. Scheduling deletions during maintenance windows contains the potential blast radius of a mistake, and enforcing strict access controls reduces the likelihood of unauthorized changes. By integrating these steps into your routine, you can confidently manage secrets at scale, knowing you have safeguards in place to catch potential problems before they escalate. This structured approach transforms a high-risk task into a predictable and safe operational procedure.

Follow a Pre-Deletion Checklist

Before you run kubectl delete secret, you must confirm that nothing in your cluster still depends on it. Deleting a secret that’s actively used by a pod, deployment, or service will cause that application to fail on its next restart or configuration reload. Your first step should always be to verify its dependencies. Check your deployment manifests, pod specifications, and service account configurations to see where the secret is referenced. A thorough audit ensures you only remove secrets that are truly obsolete, preventing self-inflicted outages. This process is critical for maintaining application stability and operational continuity.

Implement a Backup and Recovery Plan

Even with a careful process, mistakes can happen. A robust backup and recovery plan is your safety net. Before deleting any secret, create a backup of its YAML definition. You can easily export the secret to a file using the command: kubectl get secret [secret-name] -o yaml > backup-secret.yaml. Store this file in a secure, version-controlled location. If you manage your infrastructure with a GitOps workflow, this process is even simpler. By defining secrets as code in a Git repository, your entire commit history serves as a backup. With a platform like Plural CD, recovering from an accidental deletion is as straightforward as reverting a commit and letting the agent sync the correct state back to the cluster.

Consider Timing and Maintenance Windows

The timing of a secret deletion matters. If you remove a secret that an application is still using, the application might continue to function temporarily by holding the old value in memory. However, the moment that application restarts—due to a new deployment, node failure, or autoscaling event—it will fail because it can no longer access the required secret. To minimize the potential impact of an unforeseen dependency, schedule secret deletions during planned maintenance windows. This approach contains the blast radius of any potential issues, allowing your team to respond and recover without affecting users during peak traffic periods.

Enforce RBAC and Access Controls

Not everyone on your team should have the permission to delete secrets. Limiting access is a fundamental security principle that reduces the risk of accidental or malicious deletions. Use Kubernetes Role-Based Access Control (RBAC) to enforce the principle of least privilege, granting delete permissions for secrets only to specific roles or service accounts that absolutely require it. With Plural, you can streamline access management across your entire fleet. The platform’s embedded dashboard uses Kubernetes impersonation, tying permissions directly to your OIDC identity provider. This allows you to configure RBAC policies that apply consistently to users and groups, ensuring only authorized personnel can perform sensitive operations like deleting secrets.

Automate Secret Lifecycle Management with Plural

While kubectl delete secret is a fundamental command, relying on manual operations for secret management is risky, especially across a large fleet of Kubernetes clusters. A single typo or a command run in the wrong context can lead to application downtime and security vulnerabilities. The solution is to move away from imperative commands and adopt an automated, declarative approach to the entire secret lifecycle. Automation minimizes human error, enforces consistency, and provides a clear audit trail for every change.

Plural provides a unified platform to automate and streamline secret management at scale. By leveraging a GitOps workflow, integrating with your CI/CD pipeline, and offering centralized monitoring, Plural helps engineering teams handle secrets securely and efficiently. Instead of running manual commands, you can manage secrets as code, subject to the same review and validation processes as your application source code. This approach transforms secret management from a high-risk manual task into a reliable, automated process that scales with your infrastructure. With Plural, you gain control and visibility over your secrets, ensuring that deletions are intentional, audited, and safe.

Manage Secrets with a GitOps Workflow

Adopting a GitOps workflow is one of the most effective ways to secure and manage your Kubernetes secrets. This practice establishes your Git repository as the single source of truth, meaning every change—from creation to deletion—is versioned and auditable. Instead of running kubectl commands directly against a cluster, changes are proposed through pull requests. This process enforces peer review and automated checks before anything is applied, significantly reducing the risk of accidental deletion. A strong GitOps security checklist should always include strict controls around how secrets are stored and managed in your repositories.

Plural CD is built on a GitOps-based, agent-driven architecture that makes this workflow seamless across your entire fleet. You can define your secrets declaratively alongside your application manifests in Git. The Plural agent in each cluster pulls these configurations and applies them, ensuring the state of your secrets always matches what's defined in your repository. Deleting a secret becomes a deliberate, reviewed action within a pull request, not a hasty command-line operation.

Integrate Secret Management into Your CI/CD Pipeline

Integrating secret management directly into your CI/CD pipeline is essential for maintaining security throughout the software delivery lifecycle. This allows you to automate security with GitOps, embedding checks and validations directly into your build and deployment processes. By doing so, you can scan for hardcoded secrets, validate configurations, and ensure that applications are deployed with the correct permissions before they ever reach production. This proactive approach catches potential issues early, preventing vulnerabilities from being introduced into your live environments.

Plural’s API-driven platform integrates smoothly with your existing CI tools, creating a secure and automated path from code to cluster. You can use Plural to manage the deployment of both your applications and their associated secrets as part of a unified pipeline. This ensures that when a new version of an application is deployed, its required secrets are present and correctly configured. This tight integration reduces the chances of deployment failures due to missing secrets and strengthens your overall security posture.

Monitor Secret Usage Across Your Fleet

Effective secret management doesn't end at deployment; you need continuous visibility into how secrets are being used across all your clusters. Monitoring secret usage helps you identify unauthorized access, detect anomalies, and ensure compliance with security policies. Without a centralized view, tracking which pods, service accounts, or users are accessing specific secrets becomes an impossible task, especially in a large-scale environment. This visibility is critical for responding quickly to potential security incidents and for safely decommissioning secrets that are no longer in use.

Plural provides a single pane of glass for your entire Kubernetes fleet, including an embedded Kubernetes dashboard. This centralized console gives you a unified view of all resources, including secrets, across every managed cluster. You can easily inspect secret configurations and, combined with other observability tools, track their usage without having to juggle multiple kubeconfigs or access different cloud provider consoles. Plural’s RBAC integration also ensures that access to this information is controlled by your organization's identity provider, giving you a secure and auditable way to monitor your secrets at scale.

Unified Cloud Orchestration for Kubernetes

Manage Kubernetes at scale through a single, enterprise-ready platform.

GitOps Deployment
Secure Dashboards
Infrastructure-as-Code
Book a demo

Frequently Asked Questions

What is the real difference between base64 encoding and encryption for secrets? Base64 encoding is not a security measure; it is a method for representing binary data in an ASCII string format. This prevents special characters from breaking YAML or JSON manifests. Anyone with access to the Kubernetes API can retrieve a secret and easily decode its base64 value. True security comes from enabling encryption at rest for your etcd database and implementing strict Role-Based Access Control (RBAC) policies to limit who can read secret objects in the first place.

A pod is stuck in CreateContainerConfigError after I deleted a secret. How do I fix it? This error typically means the kubelet is trying to start a pod but cannot find a secret that is referenced in its configuration, either for an environment variable or a volume mount. To resolve this, you must first recreate the secret with the exact same name and data from a backup or your Git repository. Once the secret is restored, you will need to trigger a restart of the pods managed by the deployment or statefulset so they can be recreated and successfully access the newly available secret.

Is it safe to store secrets in a Git repository for a GitOps workflow? Storing plain-text secrets in Git, even in a private repository, is not a secure practice. Instead, you should use a dedicated secrets management tool that integrates with your GitOps workflow. Solutions like Sealed Secrets encrypt your secrets before they are committed to Git, ensuring they can only be decrypted by the controller running in your cluster. This approach allows you to benefit from version control and a declarative workflow without exposing sensitive credentials in your codebase.

How can I find all the unused or "orphaned" secrets in my cluster? There is no single kubectl command to identify unused secrets automatically. The process requires scripting to list all secrets and then cross-referencing them against the configurations of all pods, deployments, statefulsets, and service accounts in the cluster to see if they are referenced. This can be complex and time-consuming, which is why a centralized management platform is so valuable. Plural's single-pane-of-glass console provides the visibility needed to track resource dependencies across your fleet, simplifying the process of identifying and safely removing orphaned secrets.

Can I recover a secret after running kubectl delete secret? No, the kubectl delete secret command is irreversible. Once a secret is deleted from the Kubernetes API, it is permanently removed from the etcd database and cannot be recovered through native Kubernetes tools. This is why having a robust backup and recovery strategy is critical. The most reliable approach is to manage your secrets declaratively in a version-controlled Git repository, which serves as your source of truth and allows you to quickly restore any deleted resource by simply reapplying its manifest.