일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- kotlin querydsl
- 오블완
- 정보처리기사 실기
- kotlin
- PETERICA
- CloudWatch
- CKA
- AWS EKS
- APM
- Elasticsearch
- MySQL
- Pinpoint
- CKA 기출문제
- IntelliJ
- kotlin coroutine
- 코틀린 코루틴의 정석
- kotlin spring
- 티스토리챌린지
- Java
- Linux
- minikube
- mysql 튜닝
- 정보처리기사 실기 기출문제
- aws
- 기록으로 실력을 쌓자
- 공부
- Kubernetes
- AI
- 정보처리기사실기 기출문제
- Spring
- Today
- Total
피터의 개발이야기
[kubernetes] kubectl convert 설치 및 사용법 본문
[kubernetes] 개발환경 목차
ㅁ kubectl convert란
kubectl convert은 쿠버네티스 커맨드 라인 도구인 kubectl의 플러그인으로서, 특정 버전의 쿠버네티스 API로 작성된 매니페스트를 다른 버전으로 변환할 수 있도록 한다. 이것은 매니페스트를 최신 쿠버네티스 릴리스의 사용 중단되지 않은 API로 마이그레이션하는 데 특히 유용하다.
ㅁ kubectl convert 플러그인 설치
# for linux
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert"
# for mac silicon
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert"
# for mac intel
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert"
ㅇ 최신 릴리즈를 다운받는다.
chmod +x ./kubectl-convert
ㅇ 실행권한을 설정한다.
mv ./kubectl-convert /usr/local/bin/kubectl-convert
ㅇ kubectl-convert 바이너리를 시스템의 PATH 위치로 이동한다.
kubectl convert --help
ㅇ 설치가 잘 되었는지 확인한다.
ㅇ OS 별 설치 안내 페이지
- linux : https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-kubectl-convert-plugin
- mac : https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/#install-kubectl-convert-plugin
- window : https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/#install-kubectl-convert-plugin
ㅁ 사용법
ㅇ 다른 API 버전 간에 구성 파일을 변환합니다. YAML 및 JSON 형식이 모두 허용한다.
ㅇ 이 명령은 파일 이름, 디렉토리 또는 URL을 입력으로 받아 –output-version 플래그에 지정된 버전 형식으로 변환한다.
ㅇ 대상 버전이 지정되지 않았거나 지원되지 않는 경우 최신 버전으로 변환한다.
ㅇ 기본 출력은 YAML 형식의 stdout에 인쇄된다. -o 옵션을 사용하여 출력 대상으로 변경할 수 있다.
kubectl convert -f FILENAME
ㅁ 옵션
-f, --filename=[]: Filename, directory, or URL to file to need to get converted.
--local[=true]: If true, convert will NOT try to contact api-server but run locally.
--no-headers[=false]: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/release-1.2/docs/user-guide/jsonpath.md].
--output-version="": Output the formatted object with the given group version (for ex: 'extensions/v1beta1').
--schema-cache-dir="~/.kube/schema": If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
-a, --show-all[=false]: When printing, show all resources (default hide terminated pods.)
--show-labels[=false]: When printing, show all labels as the last column (default hide labels column)
--sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
--template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
--validate[=true]: If true, use a schema to validate the input before sending it
ㅁ 사용예제
# Convert 'pod.yaml' to latest version
kubectl convert -f pod.yaml
# Convert the live state of the resource specified by 'pod.yaml' to the latest version
# and print to stdout in json format.
kubectl convert -f pod.yaml --local -o json
# Convert all files under current directory to latest version and create them all.
kubectl convert -f . | kubectl create -f -
ㅁ extensions/v1beta1 API version to networking.k8s.io/v1
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: beta-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internal
alb.ingress.kubernetes.io/target-type: ip
spec:
rules:
- http:
paths:
- backend:
serviceName: example
servicePort: 8080
path: /*
ㅇ 사용법 테스트를 위해 v1beta_ingress.yaml를 생성하였다.
$ kubectl apply -f v1beta_ingress.yaml --dry-run=server
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.extensions/beta-ingress created (server dry run)
ㅇ 배타버젼의 메니피스트 검증을 위해 dry-run을 실행하였다.
ㅇ extensions/v1beta1을 networking.k8s.io/v1으로 변경해야함을 알려준다.
$ datree test v1beta_ingress.yaml
>> File: v1beta_ingress.yaml
[V] YAML validation
[V] Kubernetes schema validation
[X] Policy check
❌ Prevent deprecated APIs in Kubernetes v1.16 [1 occurrence]
- metadata.name: beta-ingress (kind: Ingress)
💡 Incorrect value for key `apiVersion` - the version you are trying to use is not supported by the Kubernetes cluster version (>=1.16)
(Summary)
- Passing YAML validation: 1/1
- Passing Kubernetes (1.21.0) schema validation: 1/1
- Passing policy check: 0/1
+-----------------------------------+-----------------------+
| Enabled rules in policy "Default" | 21 |
| Configs tested against policy | 1 |
| Total rules evaluated | 21 |
| Total rules skipped | 0 |
| Total rules failed | 1 |
| Total rules passed | 20 |
| See all rules in policy | https://app.datree.io |
+-----------------------------------+-----------------------+
ㅇ 동일하게 datree로 테스트 하였다.
ㅇ schema validation을 통과하지 못하였고, 1.16버젼에서 deprecated 상태임을 알려준다.
$ kubectl convert -f v1beta_ingress.yaml --output-version networking.k8s.io/v1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/scheme: internal
alb.ingress.kubernetes.io/target-type: ip
kubernetes.io/ingress.class: alb
creationTimestamp: null
name: beta-ingress
spec:
rules:
- http:
paths:
- backend:
service:
name: example
port:
number: 8080
path: /*
pathType: ImplementationSpecific
status:
loadBalancer: {}
ㅇ kubectl convert로 변환을 하였다.
$ kubectl convert -f v1beta_ingress.yaml --output-version networking.k8s.io/v1 | kubectl create -f - --dry-run=server
ingress.networking.k8s.io/beta-ingress created (server dry run)
ㅇ 테스트 시에도 적용가능하였다.
ㅁ 함께 보면 좋은 사이트
Deprecated API Migration Guide
As the Kubernetes API evolves, APIs are periodically reorganized or upgraded. When APIs evolve, the old API is deprecated and eventually removed. This page contains information you need to know when migrating from deprecated API versions to newer and more
kubernetes.io
ㅇ Deprecated API Migration Guide
https://kubernetes.io/blog/2020/09/03/warnings/#deprecation-warnings
Warning: Helpful Warnings Ahead
Author: Jordan Liggitt (Google) As Kubernetes maintainers, we're always looking for ways to improve usability while preserving compatibility. As we develop features, triage bugs, and answer support questions, we accumulate information that would be helpful
kubernetes.io
ㅇ Deprecation Warnings
Kubernetes - kubectl convert
Edit This Page kubectl convert Convert config files between different API versions Synopsis Convert config files between different API versions. Both YAML and JSON formats are accepted. The command takes filename, directory, or URL as input, and convert it
jamesdefabia.github.io
ㅇ kubectl convert 사용설명
ㅇ 코드 레벨에서 보는 쿠버네티스 이야기
'Kubernetes > kube 개발환경' 카테고리의 다른 글
[kubernetes] kubectl 다중 클러스터 접근하기, context 변경 (0) | 2022.10.09 |
---|---|
[kubernetes] kubecolor 사용법, kubectl 색상화 (0) | 2022.10.08 |
[kubernetes] skaffold 로컬 환경 세팅 트러블슈팅 (0) | 2022.09.25 |
[kubernets] Kubernetes 로컬 개발환경 skaffold, Intellij (0) | 2022.09.24 |
[kubernets] skaffold란, Kubernetes 로컬 개발환경 (0) | 2022.09.21 |