calicoctl validate
calicoctl validate 명령은 리소스 매니페스트의 문법과 스키마 오류를 클러스터에 적용하기 전에 미리 잡아 주는 오프라인 검증 도구예요. 데이터스토어 접근이 필요 없어서 매니페스트 작성 시 빠른 피드백을 받기 좋아요. 명령 사용법과 예시, 자주 나는 오류 형태를 소개해요.
출처: 문서
본문
이 섹션은 calicoctl validate 명령을 설명해요.
calicoctl 명령 전체 목록은 calicoctl 커맨드 라인 인터페이스 사용자 레퍼런스를 읽어 보세요.
참고: validate 명령은 오프라인으로 동작하며 데이터스토어 접근이 필요 없어요. 클러스터에 변경 사항을 적용하지 않고 리소스 구조, 문법, Calico 고유의 검증 규칙을 확인해요.
'calicoctl validate' 명령의 도움말 표시하기
calicoctl validate --help를 실행하면 이 명령의 도움말 메뉴가 표시돼요.
Validate one or more Calico resources from a file, directory, or stdin without
applying them. Validation runs entirely offline - checking syntax, structure,
and schema without touching the datastore - so it's useful for catching errors
before you apply resources to a cluster.
Usage:
calicoctl validate [flags]
Examples:
# Validate resources in a file.
calicoctl validate -f ./policy.yaml
Flags:
-c, --config string Path to the file containing connection configuration in YAML or JSON format. (default "/etc/calico/calicoctl.cfg")
-f, --filename string Filename to use to create/apply/replace/delete the resource. Use '-' for stdin.
-h, --help help for validate
-n, --namespace string Namespace of the resource.
-R, --recursive Process the filename specified in -f recursively.
--skip-empty Do not error if files contain no data.
Global Flags:
--allow-version-mismatch Allow client and cluster versions mismatch
--context string The name of the kubeconfig context to use
-l, --log-level string Set the log level (panic, fatal, error, warn, info, debug) (default "panic")
예시
-
단일 정책 파일을 검증해요.
calicoctl validate -f ./network-policy.yaml검증이 성공했다는 결과예요.
Successfully validated 1 'NetworkPolicy' resource(s) -
stdin에서 리소스를 검증해요.
cat resources.yaml | calicoctl validate -f -여러 리소스의 검증이 성공했다는 결과예요.
Successfully validated 3 resource(s) -
디렉터리 안의 모든 리소스 파일을 재귀적으로 검증해요.
calicoctl validate -f ./calico-resources/ --recursive검증에 실패했다는 결과예요.
Failed to validate 'NetworkPolicy' resource: [error with field Selector = 'invalid@selector' (Reason: failed to validate Field: Selector because of Tag: selector )] -
잘못된 셀렉터 예시로 검증해요.
calicoctl validate -f policy-with-invalid-selector.yamlCalico 고유의 검증 오류가 표시돼요.
Failed to validate 'NetworkPolicy' resource: [error with field Selector = 'ga@rb"ag'e' (Reason: failed to validate Field: Selector because of Tag: selector )] -
잘못된 IP 주소 예시로 검증해요.
calicoctl validate -f bgppeer-with-invalid-ip.yamlIP 검증 오류가 표시돼요.
Failed to validate 'BGPPeer' resource: [error with field PeerIP = '999.999.999.999' (Reason: failed to validate Field: PeerIP because of Tag: IP:port )]
옵션
-f, --filename string Filename to use to create/apply/replace/delete the resource. Use '-' for stdin.
-R, --recursive Process the filename specified in -f recursively.
--skip-empty Do not error if files contain no data.
함께 보기
- calicoctl 설치
- 리소스 - 파일 형식과 스키마를 포함해 모든 유효한 리소스에 대한 상세 설명
- NetworkPolicy - Calico 셀렉터 기반 정책 모델에 대한 상세 설명
더 알아보기 (Learn more)
validate는 클러스터에 아무것도 적용하지 않으니 CI에서 매니페스트 린트 용도로 쓰기 좋아요. 셀렉터나 IP 같은 Calico 고유 필드의 오류까지 잡아 준다는 점이 일반 YAML 문법 검사와의 차이예요.