🔠 쿠버네티스 클러스터의 오브젝트나 컨트롤러가 어떤 상태여야 하는지를 적용할 때는 YAML형식의 템플릿을 사용합니다.
# 템플릿 기본 형식
apiVersion: v1
kind: Pod
metadata:
spec:
- apiVersion
- 사용하려는 쿠버네티스 API 버전을 명시합니다.
- 쿠버네티스는 버전 변경이 빠른 편이므로 여러가지 API 버전이 있으므로 API 버전을 정확하게 지정하는것이 중요합니다.
kubectl api-versions
명령으로 현재 클러스터에서 사용 가능한 API 버전을 확인
- Kind
- 어떤 종류의 오브젝트 및 컨트롤러에 작업인지 명시
- e.g : Pod, Deployment, Ingress, Service
- metadata
- spec
- pod가 어떤 컨테이너를 갖고 실행하며, 실행할 때 어떻게 동작해야 할지 명시
템플릿에서 하위 필드로 무엇이 있는지
kubectl explain pods
명령으로 확인이 가능하다
추가 하위 필드 :kubectl explain pods.spec
설명 없이 모든 하위 필드 출력 :kubectl explain pods
–recursive
# example
$ kubectl explain pods
KIND: Pod
VERSION: v1
DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts.
FIELDS:
apiVersion <string>
APIVersion defines the versioned schema of this representation of an
object. Servers should convert recognized schemas to the latest internal
value, and may reject unrecognized values. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
kind <string>
Kind is a string value representing the REST resource this object
represents. Servers may infer this from the endpoint the client submits
requests to. Cannot be updated. In CamelCase. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
metadata <Object>
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
spec <Object>
Specification of the desired behavior of the pod. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
status <Object>
Most recently observed status of the pod. This data may not be up to date.
Populated by the system. Read-only. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
# 하위 필드까지의 정보를 확인하고 싶으면 아래와 같이 .입력후 필드를 입력해주면 된다.
$ kubectl explain pods.spec
# 필드 설명 없이 특정 필드와 그 아래에 속한 모든 하위 필드를 한꺼번에 보려면 --recursive 옵션을 사용
$ kubectl explain pods --recursive