[k8s] CustomResourceDefinitions

CustomResourceDefinitions๋Š” ์ƒˆ๋กœ์šด ์ข…๋ฅ˜์˜ kubernetes ๋ฆฌ์†Œ์Šค๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๋ถ€๊ฐ€๊ธฐ๋Šฅ์ด๋‹ค.
deployment๋‚˜ cronjob ๊ฐ™์€ ๋ฆฌ์†Œ์Šค ๋‹จ์œ„๋ฅผ ์ง์ ‘ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๋‚˜๋Š” ์—ฌ๊ธฐ์„œ crontab์ด๋ผ๋Š” ๋ฆฌ์†Œ์Šค ๋‹จ์œ„๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด๋ ค ํ•œ๋‹ค.

cronjob์€ ์žˆ์ง€๋งŒ crontab์ด๋ผ๋Š” ๋ฆฌ์†Œ์Šค๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค.




CustomResourceDefinitions ์ •์˜

๋‹ค์Œ๊ณผ ๊ฐ™์ด yaml ๊ตฌ์„ฑ์„ ์ •์˜ํ•œ๋‹ค.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

์Šคํ‚ค๋งˆ ๋ถ€๋ถ„์—์„œ ์ถ”ํ›„ crontab ๋ฆฌ์†Œ์Šค๋ฅผ yaml๋กœ ์ •์˜ํ• ๋•Œ ์–ด๋–ค ๊ฐ’์„ ๋ฐ›์„ ๊ฒƒ์ธ์ง€๋ฅผ ์ •์˜ํ•˜๊ณ 

์•„๋ž˜์—์„œ๋Š” ๋ฆฌ์†Œ์Šค ์ด๋ฆ„์„ ์–ด๋–ป๊ฒŒ ์ง€์„์ง€๋ฅผ ์ •ํ•œ๋‹ค.

์ด๋ฆ„์ด crontab์ด๋‹ˆ kubect get crontab์œผ๋กœ ๋ฆฌ์†Œ์Šค๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๊ณ ,
shortName์ด ct๋‹ˆ๊นŒ kubectl get ct๋กœ๋„ crontab ๋ฆฌ์†Œ์Šค๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๋œป์ด ๋œ๋‹ค.

์ €๋ ‡๊ฒŒ ํ•ด์„œ apply๋กœ ๋„์šฐ๋ฉด

์ด๋ ‡๊ฒŒ ์ถ”๊ฐ€๊ฐ€ ๋œ๋‹ค.

๋ฐฉ๊ธˆ ๋‚ด๊ฐ€ ๋งŒ๋“ ๊ฒƒ ๋ง๊ณ ๋„ ๋ญ๊ฐ€ ๋งŽ์€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.




๋ฆฌ์†Œ์Šค ์ƒ์„ฑํ•˜๊ธฐ

์ด๋ฒˆ์—๋Š” ๋ฐฉ๊ธˆ ์ •์˜ํ•œ crontab์œผ๋กœ ๋ฆฌ์†Œ์Šค๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.
์•„๊นŒ ์Šคํ‚ค๋งˆ์— ์ •์˜ํ–ˆ๋˜๋Œ€๋กœ yaml์„ ์งœ๋„ฃ๊ณ 

apply๋ฅผ ๋จน์—ฌ์ฃผ๋ฉด ๋œ๋‹ค.

๋ณ„๋กœ ๋‹ค๋ฅผ ๊ฒƒ์€ ์—†๋‹ค.

ํ•˜์ง€๋งŒ ์ง€๊ธˆ ์—ฌ๊ธฐ์—๋Š” Pod์— ๋Œ€ํ•œ ์ƒ์„ฑ์ด๋‚˜ ์ œ์–ด๊ฐ™์€๊ฑด ์„ค์ •๋˜์–ด์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—, ๋ญ”๊ฐ€๋ฅผ ๋” ํ• ์ˆ˜๋Š” ์—†๋‹ค.
์ง€๊ธˆ์œผ๋กœ์„œ๋Š” ๊ทธ๋ƒฅ ๊ป๋ฐ๊ธฐ์ผ ๋ฟ์ด๋‹ค.

์—ฌ๊ธฐ์„œ ์ด ๋ฆฌ์†Œ์Šค์— ์ƒ๋ช…์„ ๋ถˆ์–ด๋„ฃ์–ด์ฃผ๋Š” ๊ฒƒ์ด operator๋‹ค. operator๋Š” ์ด custom resource์— ๋Œ€ํ•œ ์ƒ์„ฑ์ด๋‚˜ ์ˆ˜์ • ๋“ฑ์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๋ฉด์„œ ์‹ค์งˆ์ ์ธ ๋™์ž‘์„ ์ฑ…์ž„์ง„๋‹ค.

์‹ค์งˆ์ ์ธ ๊ตฌํ˜„์€ ๋ณ„๋„ ํฌ์ŠคํŠธ์—์„œ ์ด์–ด์„œ ํ•ด๋ณธ๋‹ค.
https://blog.naver.com/sssang97/223461756266



์ฐธ์กฐ
https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/