※ Label vs Selector 핵심 비교
| 구분 | Label (이름표) | Selector (검색기) |
| 정의 | 리소스를 식별하기 위한 Key-Value 쌍 | 특정 Label을 가진 리소스를 선택하는 필터 |
| 위치 | metadata.labels 항목에 작성 | spec.selector 항목에 작성 |
| 사용 주체 | Pod, Node 등 (관리 대상) | Service, Deployment, HPA (관리 주체) |
| 비유 | 상품에 붙어 있는 바코드/태그 | 바코드를 찍어 물건을 분류하는 스캐너 |
| 역할 | "나는 'A'라는 그룹 소속이다"라고 표시 | "나는 'A' 그룹인 애들만 관리하겠다"라고 연결 |
1. k8s 환경 세팅
# k8s 에서 directory 생성
[root@k8s-master ~]# mkdir -p /root/k8s-local-volume/1231
# k8s 대시보드에서 objec들 생성
▶ dashboard 접속 > Namespace [모든 네임스페이스] > [+] 버튼 > [입력을 통해 생성] > yaml 파일 붙여넣기 > 업로드
- 아래는 yml.
apiVersion: v1
kind: Namespace
metadata:
name: anotherclass-123
labels:
part-of: k8s-anotherclass
managed-by: dashboard
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
version: 1.0.0
managed-by: dashboard
spec:
capacity:
storage: 2G
volumeMode: Filesystem
accessModes:
- ReadWriteMany
local:
path: "/root/k8s-local-volume/1231"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [k8s-master]}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: anotherclass-123
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: kubectl
spec:
resources:
requests:
storage: 2G
accessModes:
- ReadWriteMany
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: anotherclass-123
name: api-tester-1231-properties
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
data:
spring_profiles_active: "dev"
application_role: "ALL"
postgresql_filepath: "/usr/src/myapp/datasource/postgresql-info.yaml"
---
apiVersion: v1
kind: Secret
metadata:
namespace: anotherclass-123
name: api-tester-1231-postgresql
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
stringData:
postgresql-info.yaml: |
driver-class-name: "org.postgresql.Driver"
url: "jdbc:postgresql://postgresql:5431"
username: "dev"
password: "dev123"
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
replicas: 2
strategy:
type: RollingUpdate
template:
metadata:
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
spec:
nodeSelector:
kubernetes.io/hostname: k8s-master
containers:
- name: api-tester-1231
image: 1pro/api-tester:v1.0.0
ports:
- name: http
containerPort: 8080
envFrom:
- configMapRef:
name: api-tester-1231-properties
startupProbe:
httpGet:
path: "/startup"
port: 8080
periodSeconds: 5
failureThreshold: 36
readinessProbe:
httpGet:
path: "/readiness"
port: 8080
periodSeconds: 10
failureThreshold: 3
livenessProbe:
httpGet:
path: "/liveness"
port: 8080
periodSeconds: 10
failureThreshold: 3
resources:
requests:
memory: "100Mi"
cpu: "100m"
limits:
memory: "200Mi"
cpu: "200m"
volumeMounts:
- name: files
mountPath: /usr/src/myapp/files/dev
- name: secret-datasource
mountPath: /usr/src/myapp/datasource
volumes:
- name: files
persistentVolumeClaim:
claimName: api-tester-1231-files
- name: secret-datasource
secret:
secretName: api-tester-1231-postgresql
---
apiVersion: v1
kind: Service
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
ports:
- port: 80
targetPort: http
nodePort: 31231
type: NodePort
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
namespace: anotherclass-123
name: api-tester-1231-default
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-tester-1231
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
behavior:
scaleUp:
stabilizationWindowSeconds: 120
※ object 삭제 script
[root@k8s-master ~]# kubectl delete ns anotherclass-123
[root@k8s-master ~]# kubectl delete pv api-tester-1231-files
2. Obejct

3. Label / Selector / Naming (1)

3. Label / Selector / Naming (2)

'Cloud & Infra > K8S' 카테고리의 다른 글
| [K8S] App 배포 및 주요기능(Routing, AutoScaling 등) Test (0) | 2026.03.16 |
|---|---|
| [K8S] K8S에서 Prometheus, Loki, Grafana 설치하기 (0) | 2026.03.11 |
| [K8S] K8S 구성요소(컴포넌트)와 인터페이스 규격 (0) | 2026.03.10 |
| [K8S] 로컬에 K8S 환경 구축하기 (0) | 2026.03.10 |



























