I am trying to connect a k8s deployment to a (Oracle DB) deployment/service. Here is my DB deployment and service:
apiVersion: v1
kind: Service
metadata:
name: oracle-db
labels:
app: oracle-db
spec:
ports:
- name: oracle-db
port: 1521
protocol: TCP
targetPort: 1521
selector:
app: oracle-db
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: oracle-db-depl
labels:
app: oracle-db
spec:
selector:
matchLabels:
app: oracle-db
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: oracle-db
spec:
containers:
- name: oracle-db
image: oracledb:latest
imagePullPolicy: Always
ports:
- containerPort: 1521
env:
...
I'm wondering in the labels sections, what exactly is the difference between specifying 'run' vs 'app' (both of which I have seen used). I have scoured the k8s documentation and cannot find an answer.
Actually the only difference between run
and app
is the name, labels are used to identify the object in Kubernetes and you can give the name that you like, not necessarily app or run.
You probably can find a lot of run
online because if you create an object via imperative command the tag run
will be placed automatically for you.
Of course you can change this to a key/value pair that makes more sense to you.
According to k8s documentation:
Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system.
Labels can be used to organize and to select subsets of objects.
Labels can be attached to objects at creation time and subsequently added and modified at any time. Each object can have a set of key/value labels defined.
Each Key must be unique for a given object
Labels are arbitrary key value pairs. There is no special meaning of app
or run
. You can choose any key and value for your labels. One thing to remember though is that the service's selector needs to have a label which matches with what has been specified as label on the deployment otherwise it will not work.
So if you have app: oracle-db
label in your deployment then have app: oracle-db
in service's selector and if you have run: oracle-db
label in your deployment then have run: oracle-db
in service's selector.