Labels and Secrets in Kubernetes | DevOps | VisualPath

Labels


• Labels are key/value pair that can be attached to objects.
• Labels are like tags in AWS.
• You can label your objects, for instance, your pod, following an organizational structure.
• Key: environment – Value: dev/staging/qa/prod
• Key: department – Value: engineering/finance/marketing
Labels are not unique and multiple labels can be added to one object. Once labels are attached to an object, you can use filters to narrow down results. This is called Label Selectors.
Using Label Selectors, you can use a matching expression to match labels. For example, a particular pod can only run on a node labeled with “environment” equals “development”.
You can use labels to tag nodes. Once nodes are tagged, you can use label selectors to let pods only run on specific nodes.
• Selecting a specific node from deployment definition
 • Tag hardware: high-spec is not on any node from our cluster.
 • Create our deployment which has node selector tag looking for hardware: high-spec tag.

 Observe the pod creation status is pending.
• Deployment is looking for a node with tag high-spec, which is not found.
• If we don’t have such tag then pod creation will be pending.
 
 • Let’s Tag a node with hardware: high-spec.
 • The pod will automatically be scheduled once the label is available.

Secrets

Secrets provide a way in kubernetes to distribute Credentials, keys, and passwords to the pods. Kubernetes itself uses this secrets mechanism to provide the credentials to access the internal API.
Secrets can be used in the following ways.
• Use secrets as environment variables.
• Use secrets as a file in a pod.
• This setup uses volumes to be mounted in a container.
• In the volumes, you have files.
• Base 64 encoding, encoding username & password.
 • Creating Secret.
 • Creating deployment which mounts our secret(db-secrets) as a volume. • Describe shows the mounted volumes, highlighted is our db-secret mounted as a volume.
 • Log in to any of the pod and check mount point /etc/creds to verify our db-secrets.


For more information about Visualpath, visit www.visualpath.in and follow the company on Facebook and Twitter.
For DevOps training contact us at +91 9704455959 / info@visualpath.in

Comments