K8s 의 오브젝트는 namespace 에서 존재하며 name 으로 식별됩니다. 반면 labes 는 중복을 허용하며 검색, 그루핑 등에서 사용됩니다.
apiVersion: v1
kind: Pod
metadata:
name: popod
spec:
containers:
- name: nginx
image: nginx:latest
특정 오브젝트 조회
kubectl get Pod popod
굳이 오브젝트 타입을 적어줘야할까요?
오브젝트 타입으로 조회하는 명령어에 확장된 기능이라 그런건가 잘 모르겠습니다.
-n, --namespace 명령어로 조회 namespace 를 지정할 수 있습니다.
기본값은defaultnamespace 입니다.
apiVersion: v1
kind: Pod
metadata:
name: popod
labels:
app: web-server
env: production
spec:
containers:
- name: nginx
image: nginx:latest
label selector 를 응용한 조회
kubectl get pods -l app=web-server
kubectl delete pod -l app=web-server
name labels