Thursday, September 1, 2022

Kubernetes: Update Service Account with Registry Secrets

Background

 Recently, I faced some issues in my Kubernetes test environment where I had deleted the secret that contained my private registry (harbor) credentials. So, the deployments could not pull the images from harbor. Even after adding the secret containing harbor credentials, the deployments could not pull the images. 

After some troubleshooting I figured out the deployments did not include the registry credential secret in the YAML manifests. So instead of editing each deployment in the namespace, I edited the service account and added the secret so all the deployments in that namespace would use the registry secret by default.

The Secret



The YAML file:


Updating Service Account

Since we only have default service account we will be updating the default service account in the namespace "testbed".  


There are several ways to update the service account: 

  1. Patch the service account
  2. Replace the service account
  3. Edit the service account

Patch Service Account


Replace Service Account


First we export the default service account in YAML format.



After exporting the service account in YAML format we edit the YAML file and add the following



The final default service account after editing the serviceaccount.yaml file and adding imagePullSecrets.



Now we replace the serviceaccount with the serviceaccount.yaml file.


Edit Service Account


We directly edit the service account and add the imagePullSecrets and save.


The final service account:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.