what k8s-app label represent ? and how to use it?

2/23/2021

Hello I've been learning about Kubernetes but in a YAML file I found k8s-app as a label but when looking for an answer I really didn't find an accurate answer. Please if someone has what does k8s-app stands for in YAML file help.

-- nessHaf
kubernetes
yaml

2 Answers

2/23/2021

It doesn't stand for anything; it's just an older convention that has been superseded by the new app.kubernetes.io/ nomenclature

The old style was likely replaced by the new "namespaced" style to allow users to have their own k8s-app: or instance: or other "common" names without colliding with the labels that were used by the Deployment controllers for managing Pod lifecycles

tl;dr = it's not important what the text is, it's import that the text match up in the multiple places that reference it, as those labels are a contract between a few moving parts

-- mdaniel
Source: StackOverflow

2/23/2021

Basically, labels are key/value pairs that we can give to k8s objects. By using labels we can identify attributes of objects and also can select those objects by the selector. For example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx

On the other hand, you there are basically 6 fields which you can set in your label, fields are:

apiVersion: 
kind: 
metadata:
  labels:
    app.kubernetes.io/name: 
    app.kubernetes.io/instance:
    app.kubernetes.io/version: 
    app.kubernetes.io/managed-by: 
    app.kubernetes.io/component:
    app.kubernetes.io/part-of:

Every object should have a unique name which is represented by app.kubernetes.io/name, it also can have an instance label, a version, a who manages the object, a component type, and a part of what object is. These labels are used previously, but now they are not commonly used.

From k8s official doc, the following Deployment is used for WordPress:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: wordpress
    app.kubernetes.io/instance: wordpress-abcxzy
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
-- Sahadat Hossain
Source: StackOverflow