복원 중 리소스 수정


이 페이지에서는 변환 규칙을 사용하여 복원 프로세스 중에 Kubernetes 리소스를 수정하는 방법을 설명합니다. 변환 규칙은 대체 규칙이라고 부르는 이전 기능에 대한 개선으로 의도되었습니다. 대체 규칙과 하위 호환되지 않으므로 지원 중단된 대체 규칙 인터페이스를 계속 사용할 수 있습니다.

대체 규칙 문서를 보려면 복원 중에 리소스 수정을 참조하세요.

개요

복원 프로세스의 일환으로 Kubernetes 리소스를 수정해야 하는 이유에는 몇 가지가 있습니다.

  • 다른 스토리지 프로비저닝 도구를 사용하여 PersistentVolumeClaim(PVC)을 만들 수 있습니다. 예를 들어 Kubernetes 트리 내 드라이버에서 CSI 드라이버로 이동하려고 합니다.

  • 다른 이름으로 네임스페이스를 복원할 수 있습니다.

  • 라벨 또는 ConfigMap 키와 연결된 값을 추가, 변경, 삭제할 수 있습니다.

  • Deployment 또는 StatefulSet에서 복제본 수를 변경할 수 있습니다.

Backup for GKE는 변환 규칙이라고 하는 이러한 변경을 수행하는 메커니즘을 제공하며 이는 선택적으로 RestorePlan의 일부로 정의할 수도 있습니다.

복원 프로세스에서 변환 규칙은 다음과 같이 작동합니다.

  1. 규칙은 순서가 지정된 목록으로 구성됩니다.

  2. 변환을 사용할 수 없는 CustomResourceDefinition 리소스를 제외한 모든 리소스가 이 규칙 목록을 통해 순차적으로 복원됩니다.

  3. 각 규칙에는 간단한 설명, 일치 기준, 리소스 수정이 포함됩니다.

  4. 리소스가 규칙의 기준과 일치하지 않으면 목록을 수정하지 않고 목록의 다음 규칙으로 이동합니다.

  5. 리소스가 규칙의 기준과 일치하면 목록에 있는 다음 규칙으로 이동하기 전에 규칙의 수정사항을 리소스에 적용합니다.

  6. 여러 규칙이 정의된 경우 각 규칙의 일치 기준이 이전 규칙으로 수정된 리소스 버전에 대해 평가됩니다.

  7. 일치하는 규칙의 수정 사항이 적용된 후 리소스의 최종 버전은 클러스터에 생성된 버전입니다.

변환 규칙 매개변수

다음 정보를 제공하여 변환 규칙을 만듭니다.

  • description: 변환 규칙에 대한 간단한 설명입니다.

  • resourceFilter: 이 필터는 리소스와 일치시키는 데 사용됩니다. resourceFilter를 제공하지 않으면 모든 리소스가 이 규칙과 일치합니다.

  • fieldActions: resourceFilter와 일치하는 리소스에 대한 수정 목록입니다. 수정은 순서가 지정된 작업 목록으로 제공됩니다. 한 작업의 결과가 목록의 다음 작업에 영향을 줄 수 있으므로 여기서 순서가 중요합니다. 실패하는 작업이 있으면 전체 복원이 실패합니다.

리소스 필터(resourceFilter)

리소스 필터를 정의하려면 다음 매개변수를 제공합니다.

매개변수 필수 Description(설명)
namespaces 선택 사항 네임스페이스 목록입니다. 리소스가 이 규칙과 일치하려면 네임스페이스가 지정된 리소스이며 지정된 네임스페이스 중 하나가 있어야 합니다. 이 매개변수에 어떠한 값도 제공하지 않으면 모든 리소스가 일치합니다(모든 네임스페이스가 지정된 리소스 및 클러스터 범위 리소스).
groupKinds 선택 사항 다음은 Kubernetes 리소스 Group/Kind 튜플의 목록입니다.
  • 이 매개변수에 아무것도 제공하지 않으면 Group/Kind에 따른 제한 없이 모든 리소스가 일치합니다.
  • Group/Kind가 하나 이상 제공되는 경우 리소스가 규칙과 일치하려면 리소스 중 하나가 일치해야 합니다.
  • 핵심 리소스와 일치시키려면 빈 ('') 그룹을 사용합니다.
jsonPath 선택 사항 이것은 리소스를 일치시키는 데 사용되는 JSONPath 표현식입니다.

JSONPath(jsonPath)

JSONPath 표현식은 리소스와 일치시키는 데 사용됩니다. 표현식의 결과가 리소스에 대해 비어 있지 않으면 이 리소스는 일치하는 것으로 간주됩니다.

다음 리소스를 참조하세요.

YAML

apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-cm
  labels:
    app: mysql
    app.kubernetes.io/name: mysql
data:
  primary.cnf: |
    # Apply this config only on the primary.
    [mysqld]
    log-bin
  replica.cnf: |
    # Apply this config only on replicas.
    [mysqld]
    super-read-only

JSON

{
  "apiVersion": "v1",
  "kind": "ConfigMap",
  "metadata": {
    "name": "mysql-cm",
    "labels": {
      "app": "mysql",
      "app.kubernetes.io/name": "mysql"
    }
  },
  "data": {
    "primary.cnf": "# Apply this config only on the primary.\n[mysqld]\nlog-bin\n",
    "replica.cnf": "# Apply this config only on replicas.\n[mysqld]\nsuper-read-only\n"
  }
}

JSONPath 표현식 사용 예시:

표현식 Description(설명) Result
.metadata[?(@.name == 'mysql-cm')] metadata 객체에는 name 키가 포함되어 있고 해당 값은 'mysql-cm'입니다. [
 {
  "name": "mysql-cm",
  "labels": {
   "app": "mysql",
   "app.kubernetes.io/name": "mysql"
  }
 }
]
.metadata.labels['app\.kubernetes\.io/name'] metadata.labels 아래의 'app.kubernetes.io/name' 키의 문자열 값 [
 "mysql"
]
.data['primary\.cnf'] data 아래에 있는 키 'primary.cnf'의 객체 값 [
 "# Apply this config only on the primary.\n[mysqld]\nlog-bin\n"
]
.metadata[?(@.name =~ /^mysql-.*/i)] metadata 객체에는 name 키가 포함되어 있으며 해당 값은 정규 표현식 '/^mysql-.*/i'와 일치합니다.
슬래시 /는 정규 표현식 패턴을 구분하는 데 사용됩니다. 정규 표현식 끝에 있는 i는 대소문자를 구분하지 않는 일치를 위한 플래그입니다.
[
 {
  "name": "mysql-cm",
  "labels": {
   "app": "mysql",
   "app.kubernetes.io/name": "mysql"
  }
 }
]

JSONPath 표현식의 출력이 비어 있지 않으면 해당 리소스가 이 규칙과 일치합니다. 따라서 .metadata[?(@.name == 'mysql-cm')].metadata[?(@.name == 'mysql-cm')].name은 동일한 일치 결과를 생성하며, .metadata.name"mysql-cm"인 리소스와 일치합니다.

Google Cloud 콘솔에서 지도의 키와 일치하는 필터를 JSONPath에서 사용할 경우 .(점)을 \(백슬래시)로 이스케이프 처리해야 합니다. JSONPath가 gcloud CLI 또는 Terraform 언어를 사용하여 YAML 컨텍스트로 제공되는 경우 \\(이중 백슬래시)가 필요합니다. 예를 들어 .metadata.labels['app\.kubernetes\.io/name']는 YAML 또는 Terraform에서 .metadata.labels['app\\.kubernetes\\.io/name']와 동일합니다.

사용하기 전 표현식을 테스트하려면 정규 표현식을 지원하는 JSONPath 평가자 도구를 사용하는 것이 좋습니다. kubectl을 사용하여 JSONPath 표현식의 결과를 확인할 수도 있습니다. 더 많은 예시는 JSONPath 지원을 참조하세요.

필드 작업(fieldActions)

필드 작업은 JSON 문서에 적용할 작업을 표현하기 위한 JSON 문서 구조를 정의하는 JSON 패치를 기반으로 모델링됩니다. 필드 작업을 정의하려면 다음 매개변수가 필요합니다.

  • path: 작업이 수행되는 대상 리소스의 위치를 참조하는 JSON 포인터 값입니다. JSON 포인터는 항상 /(슬래시)로 시작하며 하위 요소 속성 이름(키)도 /(슬래시)로 구분됩니다.

  • op: 리소스에 대해 수행되는 작업 유형으로 5개 작업이 지원됩니다.

    • addpath에서 참조하는 항목에 따라 새 객체 또는 값을 지정된 path에 삽입합니다.
    • remove는 지정된 path에서 값을 삭제합니다.
    • replace는 지정된 path의 값을 새 값으로 바꿉니다.
    • move는 위치에서 값을 삭제하고 지정된 path에 추가합니다.
    • copy는 특정 위치의 값을 지정된 path에 복사합니다.

다음 포드 정의를 사용하여 각 작업의 예시를 찾을 수 있습니다.

YAML

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

JSON

{
  "apiVersion": "v1",
  "kind": "Pod",
  "metadata": {
    "name": "nginx",
    "namespace": "ns",
    "labels": {
      "app": "nginx"
    }
  },
  "spec": {
    "containers": [
      {
        "name": "nginx",
        "image": "nginx:latest",
        "ports": [
          {
            "containerPort": 80
          }
        ],
        "env": [
          {
            "name": "PROTOCOL",
            "value": "https"
          }
        ],
        "resources": {
          "limits": {
            "cpu": "250m",
            "memory": "64Mi"
          }
        }
      }
    ],
    "initContainers": [
      {
        "name": "install",
        "image": "busybox:stable",
        "command": [
          "wget",
          "-O",
          "/tmp/index.html",
          "http://info.cern.ch"
        ]
      }
    ]
  }
}

추가

valueadd 작업에 항상 필요하며 유효한 JSON 요소여야 합니다.

다음 작업은 "80" 값을 가진 새 환경 변수 "PORT"nginx 컨테이너에 추가합니다.

op: add
path: "/spec/containers/0/env/0"
value: >
  {
    "name": "PORT",
    "value": "80"
  }

원본

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

변환됨

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    - name: PORT  # newly added
      value: "80"  # newly added
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

다음 작업은 포드에 새 라벨 app.kubernetes.io/name: nginx에 값을 추가합니다.

op: add
path: "/metadata/labels/app.kubernetes.io~1name"
value: "nginx"

원본

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

변환됨

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
    app.kubernetes.io/name: nginx  # newly added
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

다음 작업은 nginx 컨테이너의 이미지를 "nginx:latest"에서 "nginx:stable"로 변경하기 위해 바꿉니다.

op: add
path: "/spec/containers/0/image"
value: nginx:stable

원본

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

변환됨

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:stable  # replaced
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

삭제

다음 작업은 nginx 컨테이너의 리소스 요구사항을 삭제합니다.

op: remove
path: "/spec/containers/0/resources"

원본

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

변환됨

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    # resource requirements are removed
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

바꾸기

replace 작업에 value가 필요하며 JSON 요소여야 합니다.

다음 작업은 nginx 컨테이너의 이미지를 nginx:latest에서 nginx:stable로 바꿉니다.

op: replace
path: "/spec/containers/0/image"
value: nginx:stable

원본

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

변환됨

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:stable  # replaced
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

이동

move 작업에는 fromPath가 필요합니다.

다음 작업은 nginx 컨테이너에서 환경 변수를 삭제하고 install 초기화 컨테이너에 추가합니다.

op: move
fromPath: "/spec/containers/0/env"
path: "/spec/initContainers/0/env"

원본

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

변환됨

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    #  "env" is moved to "install" container
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch
    env:  # moved "from" nginx container
    - name: PROTOCOL
      value: https

복사

copy 작업에는 fromPath가 필요합니다.

다음 작업은 nginx 컨테이너에서 install init 컨테이너에 환경 변수를 복사합니다.

op: copy
fromPath: "/spec/containers/0/env"
path: "/spec/initContainers/0/env"

원본

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch

변환됨

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: ns
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: PROTOCOL
      value: "https"
    resources:
      limits:
        cpu: "250m"
        memory: "64Mi"
  initContainers:
  - name: install
    image: busybox:stable
    command:
    - wget
    - "-O"
    - "/tmp/index.html"
    - http://info.cern.ch
    env:  # copy from "nginx" container
    - name: PROTOCOL
      value: https

Google Cloud 콘솔에서 변환 규칙을 정의하는 방법에 대한 자세한 내용은 복원 집합 계획을 참조하세요.

gcloud CLI를 통해 변환 규칙을 정의하려면 transformationRules YAML 배열이 포함된 파일을 만들고 gcloud beta container backup-restore restore-plans create 명령어에 --transformation-rules-file= 매개변수를 포함합니다.

변환 규칙 예시

다음 예시는 gcloud CLI 또는 Terraform 구성 언어에 사용되는 YAML 형식으로 제공됩니다.

PVC의 StorageClass 변경

이 예시에서는 복원된 모든 PersistentVolumeClaim 리소스의 StorageClass를 standard에서 premium-rwo로 변경합니다.

YAML

transformationRules:
- description: Change StorageClass in PVC from standard to premium-rwo
  resourceFilter:
    namespaces: []
    jsonPath: ".spec[?(@.storageClassName == 'standard')]"
    groupKinds:
    - resourceGroup: ""
      resourceKind: PersistentVolumeClaim
  fieldActions:
  - op: REPLACE
    path: "/spec/storageClassName"
    value: "premium-rwo"

Terraform

transformation_rules {
  description = "Change StorageClass in PVC from standard to premium-rwo"
  resource_filter {
    json_path = ".spec[?(@.storageClassName == 'standard')]"
    group_kinds {
      resource_kind = "PersistentVolumeClaim"
    }
  }
  field_actions {
    op = "REPLACE"
    path = "/spec/storageClassName"
    value = "premium-rwo"
  }
}

네임스페이스 클론

이 예시에서는 네임스페이스를 알파에서 베타로 클론하여 새 네임스페이스 "beta"를 만들고 "alpha"의 모든 리소스를 새 "beta" 네임스페이스로 복원합니다. 이 예시에서는 두 가지 변환 규칙이 필요합니다. 하나는 네임스페이스 자체에 대한 규칙이고 다른 하나는 네임스페이스 내 리소스에 대한 규칙입니다.

YAML

transformationRules:
- description: Rename namespace name from alpha to beta
  resourceFilter:
    namespaces: []
    jsonPath: ".metadata[?(@.name == 'alpha')]"
    groupKinds:
    - resourceGroup: ""
      resourceKind: Namespace
  fieldActions:
  - op: REPLACE
    path: "/metadata/name"
    value: "beta"
- description: Clone all resources from namespace alpha to beta
  resourceFilter:
    namespaces: ["alpha"]
  fieldActions:
  - op: REPLACE
    path: "/metadata/namespace"
    value: "beta"

Terraform

transformation_rules {
  description = "Rename namespace name from alpha to beta"
  resource_filter {
    json_path = ".metadata[?(@.name == 'alpha')]"
    group_kinds {
      resource_kind = "Namespace"
    }
  }
  field_actions {
    op = "REPLACE"
    path = "/metadata/name"
    value = "beta"
  }
}
transformation_rules {
  description = "Clone all resources from namespace alpha to beta"
  resource_filter {
    namespaces = ["alpha"]
  }
  field_actions {
    op = "REPLACE"
    path = "/metadata/namespace"
    value = "beta"
  }
}

클론된 네임스페이스에서 PVC 및 복제본 수의 StorageClass 변경

이 예시에서는 네임스페이스를 클론한 후 변경사항 집합을 새 네임스페이스의 리소스에 적용합니다.

  • PVC의 StorageClass를 standard에서 premium-rwo로 변경

  • nginx 배포의 복제본 수를 3으로 변경합니다.

YAML

transformationRules:
- description: Rename the namespace from alpha to beta
  resourceFilter:
    namespaces: []
    jsonPath: ".metadata[?(@.name == 'alpha')]"
    groupKinds:
    - resourceGroup: ""
      resourceKind: Namespace
  fieldActions:
  - op: REPLACE
    path: "/metadata/name"
    value: "beta"
- description: Change all resources from namespace alpha to beta
  resourceFilter:
    namespaces: ["alpha"]
  fieldActions:
  - op: REPLACE
    path: "/metadata/namespace"
    value: "beta"
- description: Change the StorageClass on PVCs from standard to premium-rwo
  resourceFilter:
    namespaces: ["beta"]
    jsonPath: ".spec[?(@.storageClassName == 'standard')]"
    groupKinds:
    - resourceGroup: ""
      resourceKind: PersistentVolumeClaim
  fieldActions:
  - op: REPLACE
    path: "/spec/storageClassName"
    value: "premium-rwo"
- description: Change the replica count of the Deployment nginx from 7 to 3
  resourceFilter:
    namespaces: ["beta"]
    jsonPath: ".metadata[?(@.name == 'nginx')]"
    groupKinds:
    - resourceGroup: apps
      resourceKind: Deployment
  fieldActions:
  - op: REPLACE
    path: "/spec/replicas"
    value: "3"

Terraform

transformation_rules {
  description = "Rename the namespace from alpha to beta"
  resource_filter {
    json_path = ".metadata[?(@.name == 'alpha')]"
    group_kinds {
      resource_kind = "Namespace"
    }
  }
  field_actions {
    op = "REPLACE"
    path = "/metadata/name"
    value = "beta"
  }
}
transformation_rules {
  description = "Change all resources from namespace alpha to beta"
  resource_filter {
    namespaces = ["alpha"]
  }
  field_actions {
    op = "REPLACE"
    path = "/metadata/namespace"
    value = "beta"
  }
}
transformation_rules {
  description = "Change the StorageClass on PVCs from standard to premium-rwo"
  resource_filter {
    namespaces = ["beta"]
    json_path = ".spec[?(@.storageClassName == 'standard')]"
    group_kinds {
      resource_kind = "PersistentVolumeClaim"
    }
  }
  field_actions {
    op = "REPLACE"
    path = "/spec/storageClassName"
    value = "premium-rwo"
  }
}
transformation_rules {
  description = "Change the replica count of the Deployment nginx from 7 to 3"
  resource_filter {
    namespaces = ["beta"]
    json_path = ".metadata[?(@.name == 'nginx')]"
    group_kinds {
      resource_group = "apps"
      resource_kind = "Deployment"
    }
  }
  field_actions {
    op = "REPLACE"
    path = "/spec/replicas"
    value = "3"
  }
}

ConfigMap 항목 변경, 삽입, 삭제

이 예시에서는 "mysql" 네임스페이스에서 라벨 키 "app.kubernetes.io/name"이 포함된 ConfigMap을 수정하여 다음을 수행합니다.

  • "endpoint" 항목 값을 "192.0.2.127"로 변경합니다.

  • 값이 "30s"인 새 "connection-timeout" 항목을 삽입합니다.

  • "read-timeout" 키가 있는 항목을 삭제합니다.

YAML

transformationRules:
- description: Change, insert, remove `ConfigMap` entres
  resourceFilter:
    namespaces: ["mysql"]
    jsonPath: ".metadata.labels['app\\.kubernetes\\.io/name']"
    groupKinds:
    - resourceGroup: ""
      resourceKind: ConfigMap
  fieldActions:
  - op: REPLACE
    path: "/data/endpoint"
    value: "192.0.2.127"
  - op: ADD
    path: "/data/connection-timeout"
    value: "30s"
  - op: REMOVE
    path: "/data/read-timeout"

Terraform

transformation_rules {
  description = "Change, insert, remove `ConfigMap` entres"
  resource_filter {
    namespaces = ["mysql"]
    json_path = ".metadata.labels['app\\.kubernetes\\.io/name']"
    group_kinds {
      resource_kind = "ConfigMap"
    }
  }
  field_actions {
    op = "REPLACE"
    path = "/data/endpoint"
    value = "192.0.2.127"
  }
  field_actions {
    op = "ADD"
    path = "/data/connection-timeout"
    value = "30s"
  }
  field_actions {
    op = "REMOVE"
    path = "/data/read-timeout"
  }
}

이름이 mysql-로 시작하는 리소스에 app.kubernetes.io/name 라벨을 추가합니다.

이 예시에서는 값이 mysqlapp.kubernetes.io/name 라벨을 이름이 mysql-로 시작하는 모든 리소스에 추가합니다.

YAML

transformationRules:
- description: Add a label to resources whose name starts with
  resourceFilter:
    namespaces: []
    jsonPath: ".metadata[?(@.name =~ /^mysql-.*/i)]"
  fieldActions:
  - op: ADD
    path: "/metadata/labels/app.kubernetes.io~1name"
    value: "mysql"

Terraform

transformation_rules {
  description = "Add a label to resources whose name starts with"
  resource_filter {
    json_path = ".metadata[?(@.name =~ /^mysql-.*/i)]"
  }
  field_actions {
    op = "ADD"
    path = "/metadata/labels/app.kubernetes.io~1name"
    value = "mysql"
  }
}

LoadBalancer 유형 서비스의 고정 IP 주소 할당

이 예시에서는 네임스페이스 "nginx"의 서비스 "nginx-svc"에 고정 IP 주소를 할당합니다.

YAML

transformationRules:
- description: Assign a static IP to Service nginx-svc
  resourceFilter:
    namespaces: ["nginx"]
    jsonPath: ".metadata[?(@.name == 'nginx-svc')]"
    groupKinds:
    - resourceGroup: ""
      resourceKind: Service
  fieldActions:
  - op: ADD
    path: "/spec/loadBalancerIP"
    value: "192.0.2.127"

Terraform

transformation_rules {
  description = "Assign a static IP to Service nginx-svc"
  resource_filter {
    namespaces = ["nginx"]
    json_path = ".metadata[?(@.name == 'nginx-svc')]"
    group_kinds {
      resource_kind = "Service"
    }
  }
  field_actions {
    op = "ADD"
    path = "/spec/loadBalancerIP"
    value = "192.0.2.127"
  }
}