Skip to content

Handling Container Images⚓︎

Adding a new imagePullSecret to the default service account⚓︎

You can add a new imagePullSecret to the default service account by running the following command (For Kubeflow users, default-editor is usually the right service account.):

# Assuming the new secret is called "newregistrykey"
NAMESPACE=my-namespace
NEW_SECRET=newregistrykey
SERVICE_ACCOUNT=default-editor

SERVICE_ACCOUNT_JSON=$(kubectl get serviceaccount $SERVICE_ACCOUNT -n $NAMESPACE -o json)
PATCHED_JSON=$(echo $SERVICE_ACCOUNT_JSON | jq --arg new_key $NEW_SECRET '.imagePullSecrets += [{"name":$new_key}]')
kubectl patch serviceaccount $SERVICE_ACCOUNT -n $NAMESPACE -p "$(echo $PATCHED_JSON)"

Removing old and unused container images⚓︎

Only valid for microk8s: You can use the following command to remove all container images that are not running with crictl

crictl -r unix:///var/snap/microk8s/common/run/containerd.sock rmi --prune