0Pricing
Docker & Kubernetes for Developers · 강의

사용자 지정 리소스 정의(CRD)

사용자 지정 리소스를 정의하여 도메인별 객체를 관리하고 Kubernetes 기능을 확장합니다.

사용자 지정 리소스 정의(CRD)은(는) CoddyKit의 무료 Docker & Kubernetes for Developers 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Docker & Kubernetes for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Extend Kubernetes API

Welcome! In this lesson, we'll explore Custom Resource Definitions (CRDs). CRDs allow you to extend Kubernetes by defining your own custom resource types.

Think of it as teaching Kubernetes new words and concepts, so it can manage application-specific objects just like it manages built-in ones like Pods or Deployments.

Why Custom Resources?

Kubernetes provides powerful primitives like Pods, Deployments, and Services. But what if your application needs to manage a unique kind of object, like a database cluster, a serverless function, or a custom build pipeline?

  • Domain-Specific Objects: Define resources tailored to your application's unique needs.
  • Abstraction: Simplify complex application deployments into a single, manageable resource.
  • Kubernetes Native: Leverage Kubernetes's declarative API, tooling (kubectl), and watch mechanisms for your custom objects.

Core vs. Custom Resources

Kubernetes comes with many built-in or 'core' resources you already know:

  • Core Resources: Pod, Deployment, Service, ConfigMap. These are part of the standard Kubernetes API.
  • Custom Resources: These are resources you define using CRDs. They behave just like core resources but represent your own application-specific concepts.

Once a CRD is created, you can create and manage instances of your custom resource using kubectl, just like any other Kubernetes object.

Anatomy of a CRD: Basics

A CRD is itself a Kubernetes resource defined in YAML. Here's what some key fields mean:

  • apiVersion: apiextensions.k8s.io/v1: Specifies the API version for the CRD itself.
  • kind: CustomResourceDefinition: Identifies this YAML as a CRD definition.
  • metadata.name: The unique name for your CRD, typically in the format <plural>.<group>.

Let's look at defining the core specification next.

CRD Anatomy: Group & Versions

The spec section of a CRD defines the custom resource's properties:

  • spec.group: The API group for your custom resource (e.g., example.com). This helps organize your custom resources.
  • spec.versions: A list of supported versions for your custom resource (e.g., v1alpha1, v1). Each version can have its own schema.
  • spec.scope: Defines if your custom resource is Namespaced (like Pods) or Cluster (like Nodes).

CRD Anatomy: Names & Schema

More important fields in the spec:

  • spec.names: Defines how your custom resource will be referred to:
    • plural: The plural name used in kubectl get (e.g., webservers).
    • singular: The singular name (e.g., webserver).
    • kind: The CamelCase name for the resource object (e.g., WebServer).
    • shortNames: Optional, short aliases (e.g., ws).
  • spec.versions[].schema.openAPIV3Schema: This is crucial! It defines the structure and validation rules for your custom resource's data.

Defining a Simple WebServer CRD

Here's a basic CRD for a WebServer resource. Notice how it defines the group, versions, names, and a simple schema for its properties (like image and replicas).

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: webservers.example.com
spec:
  group: example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                image:
                  type: string
                replicas:
                  type: integer
              required:
                - image
  scope: Namespaced
  names:
    plural: webservers
    singular: webserver
    kind: WebServer
    shortNames:
      - ws

Applying Your CRD

Once you have your CRD YAML file (e.g., webserver-crd.yaml), you can apply it to your Kubernetes cluster using kubectl. This registers your new resource type with Kubernetes.

It might take a few seconds for the API server to fully acknowledge the new type.

kubectl apply -f webserver-crd.yaml

Creating a Custom Resource

After the CRD is applied, you can create instances of your WebServer custom resource. This YAML defines a specific WebServer object with its own image and replicas values, conforming to the schema you defined.

You can manage this object just like any other Kubernetes resource.

apiVersion: example.com/v1
kind: WebServer
metadata:
  name: my-first-webserver
spec:
  image: nginx:latest
  replicas: 3

Interacting with Custom Resources

Now that you've defined a CRD and created an instance, you can use standard kubectl commands to interact with your custom resources:

  • kubectl get webservers: List all WebServer objects.
  • kubectl get ws: Use the short name.
  • kubectl describe webserver my-first-webserver: Get detailed information about a specific WebServer instance.

This seamless integration is a key benefit of CRDs!

Check Your CRD Knowledge

Which of the following are benefits of using Custom Resource Definitions (CRDs) in Kubernetes?

Recap: Extending Kubernetes

Great job! You've learned about Custom Resource Definitions!

  • CRDs allow you to extend the Kubernetes API with your own custom resource types.
  • They enable Kubernetes to manage domain-specific objects using its native API and tooling.
  • A CRD defines the schema and properties of your custom resource.
  • Once defined, you can create and interact with instances of your custom resource using kubectl.

Next, we'll see how Operators leverage CRDs to automate complex application management!

자주 묻는 질문

“사용자 지정 리소스 정의(CRD)” 강의는 무료인가요?

네 — “사용자 지정 리소스 정의(CRD)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Docker & Kubernetes for Developers 강의 전체를 잠금 해제할 수 있습니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

“사용자 지정 리소스 정의(CRD)”에서 뭘 배우나요?

사용자 지정 리소스를 정의하여 도메인별 객체를 관리하고 Kubernetes 기능을 확장합니다. 브라우저에서 직접 실행하는 실습 코드로 Docker & Kubernetes for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Docker & Kubernetes for Developers을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Docker & Kubernetes for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“사용자 지정 리소스 정의(CRD)” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Docker & Kubernetes for Developers 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Docker & Kubernetes for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 사용자 지정 리소스 정의(CRD)
  2. Kubernetes의 오퍼레이터 패턴
  3. Kubernetes를 활용한 서버리스(Knative)
  4. Admission 웹훅으로 API 서버 확장하기
← Docker & Kubernetes for Developers(으)로 돌아가기