Monday, March 27, 2023

k8 Secret

 In Kubernetes, a Secret is an object that allows you to store and manage sensitive information, such as passwords, API keys, and certificates. 

Secrets are stored in a cluster, and they can be accessed by Pods or other Kubernetes objects.


To create a Secret, you need to encode the sensitive data as base64 and store it in a YAML file. 

Here's an example YAML file that creates a Secret named "mysecret" with a username and password:


apiVersion: v1

kind: Secret

metadata:

  name: mysecret

type: Opaque

data:

  username: dXNlcm5hbWU= # base64-encoded "username"

  password: cGFzc3dvcmQ= # base64-encoded "password"




In this example, the Secret is of type "Opaque," which means that Kubernetes doesn't understand its contents. The data field contains the encoded username and password.


Once you have created a Secret, you can reference it in your Pod's YAML file using environment variables or volumes. 


For example, to use the username and password from the "mysecret" Secret as environment variables in a Pod, you could add the following to your Pod's YAML file:


env:

- name: USERNAME

  valueFrom:

    secretKeyRef:

      name: mysecret

      key: username

- name: PASSWORD

  valueFrom:

    secretKeyRef:

      name: mysecret

      key: password


This would create two environment variables in the Pod named "USERNAME" and "PASSWORD," with values equal to the decoded contents of the "username" and "password" keys in the "mysecret" Secret, respectively.

No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117