
# pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels: // 레이블
app: myapp
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 8080
# replicaSet-definition.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: simple-webapp
labels: // 이 부분은 replicaSet의 labels임 다른 replicaSet과 구분하기 위함
app: App1
tier: frontend
spec:
replicas: 3
selector:
matchLabels: // 이 구문으로 식별할 labels을 필터링
app: App1
template:
metadata:
labels: // template 아래 이 부분이 실제 replicas를 만들기 위해 식별되는 labels
app: App1
tier: frontend
spec:
containers:
name: simple-webapp
image: simple-webapp
labels은 key: value 로 생성한다.metadata 필드 아래 labels 필드를 작성하고 자식 필드에 작성한다.labels는 원하는 만큼 붙일 수 있다.replicaSet의 metadata 필드의 labels은 replicaSet 자체에 달려있는 labels이다.💡 이 부분이 초보자들이 많이 실수하는 부분
labels와 selector를 이용해 다른 오브젝트들을 연결한다matchLabels로 필터링을 하고template 필드 아래에 labels로 복제본을 만들 pod들을 식별한다!$ kubectl get pods --selector app=App1
$ kubectl get pods --show-labels
$ kubectl get pod -l <key>=<value>
--selector 옵션으로 키와 값을 입력하면 해당 labels을 보유하고 있는 pod들을 필터링하여 출력한다.replicaSet에서는 selector 필드의 자식 요소로 matchLabels 필드에 키, 값을 명시하여 필터링 할 수 있다.labels을 입력하여 ReplicaSet이 올바르게 식별하도록 도울 수 있다.apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: App1
ports:
- protocol: TCP
port: 80
targetPort: 9376
service 같은 다른 개체(오브젝트)에도 동일하게 작동selector를 사용apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: simple-webapp
labels:
app: App1
function: Front-end
annotations:
buildversion: 1.34
name: YuSangmin
phone: 010-1234-1234
email: email@email.com
spec:
replicas: 3
selector:
matchLabels:
app: App1
template:
metadata:
labels:
app: App1
function: Front-end
spec:
containers:
name: simple-webapp
image: simple-webapp
annotations는 말 그대로 주석