Labels
POD A-frt
Key | Value |
---|
app | frontend |
color | red |
shape | triangle |
POD B-fyt
Key | Value |
---|
app | frontend |
color | yellow |
shape | triangle |
POD C-fgt
Key | Value |
---|
app | frontend |
color | green |
shape | triangle |
POD D-brt
Key | Value |
---|
app | backend |
color | red |
shape | triangle |
POD E-byt
Key | Value |
---|
app | backend |
color | yellow |
shape | triangle |
POD F-bgt
Key | Value |
---|
app | backend |
color | green |
shape | triangle |
POD G-frr
Key | Value |
---|
app | frontend |
color | red |
shape | rectangle |
POD H-byr
Key | Value |
---|
app | backend |
color | yellow |
shape | rectangle |
POD I-bgr
Key | Value |
---|
app | backend |
color | green |
shape | rectangle |
Selector
Selector 1
1
| kubectl get pods --selector app=backend,shape=rectangle
|
Key | Value |
---|
app | backend |
shape | rectangle |
Selected PODs by Selector 1
Selector 2
1
| kubectl get pods --selector app=frontend,color=red
|
Key | Value |
---|
app | frontend |
color | red |
Selected PODs by Selector 2
Selector 3
1
| kubectl get pods --selector color=green,shape=rectangle
|
Key | Value |
---|
color | green |
shape | rectangle |
Selected PODs by Selector 2
YAML
replicaset-definition.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: simple-webapp
labels:
app: App1
function: Front-end
spec:
replicas: 3
selector: # -> This selector is matching below labels in template.
matchLabels:
app: App1
template:
metadata:
labels:
app: App1
function: Front-end
spec:
containers:
- name: simple-webapp
image: simple-webapp
|
service-definition.yml
1
2
3
4
5
6
7
8
9
10
11
| apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector: # -> This selector is find ReplicaSet and PODs.
app: App1
ports:
- protocol: TCP
port: 80
targetPort: 9376
|
Annotations Example
replicaset-annotation-definition.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: simple-webapp
labels:
app: App1
function: Front-end
annotations:
buildVersion: 1.34
spec:
replicas: 3
selector: # -> This selector is matching below labels in template.
matchLabels:
app: App1
template:
metadata:
labels:
app: App1
function: Front-end
spec:
containers:
- name: simple-webapp
image: simple-webapp
|