Home [kubernetes-실습] CRD (Custom Resource Definition)
Post
Cancel

[kubernetes-실습] CRD (Custom Resource Definition)

Custom Resource Definition 생성

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# CRD 생성을 위한 yaml 파일 작성
ps0107@k8smaster1:~$ vi crd.yaml 
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: crontabs.ps.example.com
spec:
  scope: Cluster
  group: ps.example.com
  version: v1
  names:
    kind: CronTab
    plural: crontabs
    singular: crontab
    shortNames:
    - ct 

# CRD 생성
ps0107@k8smaster1:~$ kubectl create -f crd.yaml                                                                                      customresourcedefinition.apiextensions.k8s.io/crontabs.ps.example.com created

# 생성 확인
ps0107@k8smaster1:~$ kubectl get crd
NAME                                          CREATED AT
bgpconfigurations.crd.projectcalico.org       2020-01-28T08:33:18Z
bgppeers.crd.projectcalico.org                2020-01-28T08:33:18Z
clusterinformations.crd.projectcalico.org     2020-01-28T08:33:18Z
crontabs.ps.example.com                       2020-02-06T06:14:19Z
felixconfigurations.crd.projectcalico.org     2020-01-28T08:33:18Z
globalnetworkpolicies.crd.projectcalico.org   2020-01-28T08:33:18Z
globalnetworksets.crd.projectcalico.org       2020-01-28T08:33:18Z
hostendpoints.crd.projectcalico.org           2020-01-28T08:33:18Z
ippools.crd.projectcalico.org                 2020-01-28T08:33:18Z
networkpolicies.crd.projectcalico.org         2020-01-28T08:33:18Z

# 생성된 객체 자세한 정보 확인
ps0107@k8smaster1:~$ kubectl describe crd crontabs.ps.example.com
Name:         crontabs.ps.example.com
Namespace:    
Labels:       <none>
Annotations:  <none>
API Version:  apiextensions.k8s.io/v1beta1
Kind:         CustomResourceDefinition
Metadata:
  Creation Timestamp:  2020-02-06T06:14:19Z
  Generation:          1
  Resource Version:    1033756
  Self Link:           /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/crontabs.ps.example.com
  UID:                 b8c8a2a4-5e76-4471-8d17-e9c36a24b4c1
Spec:
  Conversion:
    Strategy:  None
  Group:       ps.example.com
  Names:
    Kind:       CronTab
    List Kind:  CronTabList
    Plural:     crontabs
    Short Names:
      ct
    Singular:               crontab
  Preserve Unknown Fields:  true
  Scope:                    Cluster
  Version:                  v1
  Versions:
    Name:     v1
    Served:   true
    Storage:  true
Status:
  Accepted Names:
    Kind:       CronTab
    List Kind:  CronTabList
    Plural:     crontabs
    Short Names:
      ct
    Singular:  crontab
  Conditions:
    Last Transition Time:  2020-02-06T06:14:19Z
    Message:               no conflicts found
    Reason:                NoConflicts
    Status:                True
    Type:                  NamesAccepted
    Last Transition Time:  <nil>
    Message:               the initial names have been accepted
    Reason:                InitialNamesAccepted
    Status:                True
    Type:                  Established
  Stored Versions:
    v1
Events:  <none>

# CRD를 이용한 새로운 객체 생성
ps0107@k8smaster1:~$ vi new-crontab.yaml 
apiVersion: "ps.example.com/v1"
kind: CronTab
metadata:
  name: new-cron-obj
spec:
  cronSpec: "*/5 * * * *"
  image: example-cron-image

# 객체 생성
ps0107@k8smaster1:~$ kubectl create -f new-crontab.yaml 
crontab.ps.example.com/new-cron-obj created

# 생성된 객체 확인
ps0107@k8smaster1:~$ kubectl get CronTab
NAME           AGE
new-cron-obj   13s

# shortName으로도 확인
ps0107@k8smaster1:~$ kubectl get ct
NAME           AGE
new-cron-obj   22s

ps0107@k8smaster1:~$ kubectl describe ct
Name:         new-cron-obj
Namespace:    
Labels:       <none>
Annotations:  <none>
API Version:  ps.example.com/v1
Kind:         CronTab
Metadata:
  Creation Timestamp:  2020-02-06T06:15:03Z
  Generation:          1
  Resource Version:    1033816
  Self Link:           /apis/ps.example.com/v1/crontabs/new-cron-obj
  UID:                 7569c09f-8ceb-4eba-91ce-04dbf835c878
Spec:
  Cron Spec:  */5 * * * *
  Image:      example-cron-image
Events:       <none>

# CRD 삭제
ps0107@k8smaster1:~$ kubectl delete -f crd.yaml 
customresourcedefinition.apiextensions.k8s.io "crontabs.ps.example.com" deleted

# 삭제 후 shortName이 안되는걸 확인 가능하다.
ps0107@k8smaster1:~$ kubectl get ct
Error from server (NotFound): Unable to list "ps.example.com/v1, Resource=crontabs": the server could not find the requested resource (get crontabs.ps.example.com)
This post is licensed under CC BY 4.0 by the author.

[kubernetes-실습] 로깅과 트러블슈팅 : Metrics와 DashBoard

[kubernetes-실습] helm