Reputation: 4969
I'm running a K8s cluster on rasberry pi(Ubuntu 20.04) . When I try to deploy the following K8s deployment, the labels 'rel' and 'env' weren't created on pods.
K8s Versions:
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.7", GitCommit:"8fca2ec50a6133511b771a11559e24191b1aa2b4", GitTreeState:"clean", BuildDate:"2019-09-18T14:47:22Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"windows/a
md64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.6", GitCommit:"dff82dc0de47299ab66c83c626e08b245ab19037", GitTreeState:"clean", BuildDate:"2020-07-15T16:51:04Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/arm"}
-- Deployment yaml (kubectl apply -f .)
apiVersion: apps/v1
kind: Deployment
metadata:
name: product-catalog-deployment
namespace: default
labels:
app: product-catalog
rel: beta
env: prod
spec:
selector:
matchLabels:
app: product-catalog
replicas: 3
template:
metadata:
labels:
app: product-catalog
spec:
containers:
- name: product-catalog
image: marveltracker/netcore_fun:netcore_3_1
ports:
- containerPort: 80
name: http
- containerPort: 443
name: https
---get prods (kubectl get po --show-labels)
NAME READY STATUS RESTARTS AGE LABELS
product-catalog-deployment-65c7bcbf48-8nxbw 1/1 Running 0 16s app=product-catalog,pod-template-hash=65c7bcbf48
product-catalog-deployment-65c7bcbf48-f764h 1/1 Running 0 16s app=product-catalog,pod-template-hash=65c7bcbf48
product-catalog-deployment-65c7bcbf48-pcz4q 1/1 Running 0 16s app=product-catalog,pod-template-hash=65c7bcbf48
What was the issue here ?
Upvotes: 0
Views: 434
Reputation: 9174
Your Yaml file should be like this
apiVersion: apps/v1
kind: Deployment
metadata:
name: product-catalog-deployment
namespace: default
labels:
app: product-catalog
rel: beta
env: prod
spec:
replicas: 3
selector:
matchLabels:
app: product-catalog
rel: beta #----These all should same
env: prod
template:
metadata:
labels:
app: product-catalog
rel: beta #----Same like above
env: prod
spec:
containers:
- name: product-catalog
image: marveltracker/netcore_fun:netcore_3_1
ports:
- containerPort: 80
name: http
- containerPort: 443
name: https
This is because deployment manages replicasets in the background and you apply the label on replica sets pods. and replicaset add label to pods and manages those pod (means the number of pod availability)
Upvotes: 2