kustomize 설치 및 사용

문학적인유사성·2023년 8월 12일
0

뎁옵깃옵쿠베

목록 보기
35/46
post-thumbnail

flux는 kustomize를 이용해서 편하게 gitops를 할수있다. ArgoCD에 비해서 kustomize에 최적화되어있는 툴이라고 생각하면 편함
그러면 kustomize가 어떤 것이고, 어떤 내용을 포함하고있는지 먼저 알아야함..!!


kustomize란? => "Differenet varitions Of YAML"

kustomize 공식문서
kustomize ppt 메루카리엔지니어
쿠버네티스 리소스(yaml파일)을 변경하지 않고 필드를 재정의하여 새로운 쿠버네티스 리소스를 생성하는 도구
yaml + kustomize ==> 필드가 재정의된 yaml > "Differenet varitions Of YAML"

curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"  | bash
  • 참고 : helm vs kustomize
    여러팀이 helm을 다르게 원한다는것...! 그것을 피하기 위해서 helm을 안쓴다구 하네영...
    그냥 선택하는것 나름인듯.. 팀에 맞는 툴을 사용하는 것이 목적이라고 함.
    팀마다 선택하는게 다르니까... 유튜브에서 본 팀은 쿠스터마이즈로 적용하는게 더 편해서 그렇게 쓰는거같음... ㅋㅋㅋ
  • kustomize 장점
    Cross-cutting 지원 : kustomize가 동작할 대 연관관계가 있는 다른 필드를 자동으로 수정해줌

kustomize설명 공식문서
네개의 리스트 가있는데,
리소스(input) -> 제너레이터(필드생성)-> 트랜스포머(필드변경) -> 벨리데이터(검증)
resources 필드: kustomize를 적용할 쿠버네티스 리소스(yaml파일)
generators 필드: 새로 생성할 필드를 설정
transformers 필드: 기존 필드 변경을 설정
validators 필드: 검증


실제로 쿠스터마이즈 예시

git clone https://github.com/vfarcic/argocd-production
cd argocd-production
ls -1 argo-workflows
cd argo-workflows (<- recently installed define here )
cd base


# Kustomization
# Argo Project의 내용과 내 설정을 섞어서 쓰겠다!!! 
# this is a combination of the manifest defined in argo worklofws project plus my own those that imsuing customize to behiave my own desirement.
base % cat kustomization.yaml 
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- namespace.yaml
- github.com/argoproj/argo-workflows/manifests/base # I dont want to copy and paste all the definitions of a thrird-part application in this case argo workflows
- github.com/argoproj/argo-workflows/manifests/cluster-install/workflow-controller-rbac 
- github.com/argoproj/argo-workflows/manifests/cluster-install/argo-server-rbac
- ingress.yaml
patchesStrategicMerge:
- config.yaml
namespace: argo

깃허브 링크 참고

base % cat config.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: workflow-controller-configmap
data:
  config: |
    containerRuntimeExecutor: k8sapi
# config에 밑에 data밑에 아래 내용을 추가하는거 

아래의 명령어를 실행하면 yaml파일이 떨어지게되는데, 하나씩 보면 내용이 바뀌어서 추가된것을 볼수있음!
kustomize build ${base디렉토리}
==> All the manifests with their patches applied and combined and all the stuff prepared for use and output on the screen!!!!
==> it's just jobs to output combined patched version of all the manifest referenced in all the customization files

새로 만들어진 yaml들이 apply 됨!
kustomize build base | kubectl apply --filename -

production % ls
ingress_patch.json      kustomization.yaml

production % cat ingress_patch.json  # 이 오버레이를 통해서 ingress를 보게되면 내용의 values가 바뀌는 것을 볼수있음.
[
  {
    "op": "replace",
    "path": "/spec/rules/0/host",
    "value": "argo-workflows.192.168.64.2.nip.io"
  }
]

production % cat kustomization.yaml 
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base 
- ../workflows
patches:
- path: ingress_patch.json # json에 있는것을 patch해라 
  target: # ptach하려고하는 타켓 리소스
    group: networking.k8s.io
    version: v1
    kind: Ingress
    name: argo-server
    
아래와 같이 yaml에서 image 하나만 바꾸고싶을때 저렇게 쓸수있음 
kustomize edit set image argoproj/cli=argoproj/cli:v2.12.4

production % cat kustomization.yaml 
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
- ../workflows
patches:
- path: ingress_patch.json
  target:
    group: networking.k8s.io
    kind: Ingress
    name: argo-server
    version: v1
images: # 새롭게 추가된 부분!!! 
- name: argoproj/cli
  newName: argoproj/cli
  newTag: v2.12.4

kustomize yaml

yusa@YUSAui-MacBookAir kustomize % tree
.
├── base
│   ├── deployment.yaml
│   └── kustomization.yaml
└── overlay
    └── dev
        └── kustomization.yaml

BASE의 내용이 Overlay의 input으로 들어감.

  • deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
  • kustomization.yaml under the base
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yaml
#  - service.yaml

-kustomization.yaml under the dev

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base/

replicas:
- name: nginx-deployment
  count: 1

dev폴더에서 kubectl apply -k . 하면 kustomize가 적용된 yaml이 apply됨 -k ( kustomize )

DevOps ToolKit 유튜브
Michael Levan
악분 일상 유튜브

0개의 댓글