How to delete completed kubernetes pod?

You can do this a bit easier, now.

You can list all completed pods by:

kubectl get pod --field-selector=status.phase==Succeeded

delete all completed pods by:

kubectl delete pod --field-selector=status.phase==Succeeded

and delete all errored pods by:

kubectl delete pod --field-selector=status.phase==Failed

If this pods created by CronJob, you can use spec.failedJobsHistoryLimit and spec.successfulJobsHistoryLimit

Example:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: my-cron-job
spec:
  schedule: "*/10 * * * *"
  failedJobsHistoryLimit: 1
  successfulJobsHistoryLimit: 3
  jobTemplate:
    spec:
      template:
         ...