[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/