Closed blueseller closed 3 months ago
package main
import (
"context"
"fmt"
"os"
"time"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/wait"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func main() {
// Load Kubernetes configuration from the default location or a kubeconfig file
config, err := rest.InClusterConfig()
if err != nil {
fmt.Println("Error loading in-cluster configuration:", err)
os.Exit(1)
}
// Create a Kubernetes clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
fmt.Println("Error creating clientset:", err)
os.Exit(1)
}
// Specify the namespace and pod name you want to delete
namespace := "your-namespace"
podName := "your-pod-name"
// Define a grace period (in seconds) for the pod deletion
gracePeriodSeconds := int64(0) // 0 for immediate deletion
// Create a context with a timeout for the deletion operation
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Delete the pod with immediate deletion
err = clientset.CoreV1().Pods(namespace).Delete(ctx, podName, metav1.DeleteOptions{
GracePeriodSeconds: &gracePeriodSeconds,
})
if err != nil {
fmt.Printf("Error deleting pod %s in namespace %s: %v\n", podName, namespace, err)
os.Exit(1)
}
fmt.Printf("Pod %s in namespace %s deleted successfully\n", podName, namespace)
}
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle stale
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle rotten
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/reopen
/remove-lifecycle rotten
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
Sometimes, the status of the job will always be terminal. So I expect to detect that if a job is in the terminal state for a long time, it will be directly and forcibly deleted. But I found that there is no such option on client go.
code example: return clientset.BatchV1(). Jobs(namespace). Delete( context.Background(), job.ObjectMeta.Name, metav1.DeleteOptions{ GracePeriodSeconds: &gracePeriodSeconds, }, )