# \[쿠버네티스 아키텍처] 3. API 호출

> 44BIT님의 [\[초보를 위한 쿠버네티스 안내서\] 쿠버네티스 아키텍처](https://youtu.be/IOem05grFkU) 강의를 듣고 정리한 내용입니다.

## 1. API 호출 방법

원하는 상태(desired stats)를 다양한 **오브젝트(objects)**&#xB85C; **정의(spec)**&#xD558;고 API 서버에 `yaml` 형식으로 전달한다.

## 2. 쿠버네티스의 흐름 요약

![](https://github.com/hidaehyunlee/Fork-my-brain/tree/4f7d19f4487fe8d450e22a9b6451bbed865ce125/images/37580034-108153984-8426eb00-711f-11eb-9909-7e331191419a.png)

위 그림은 지난 글에서 배운 ReplicaSet을 생성하는 흐름을 나타내고 있는데, 사실 이 과정이 쿠버네티트의 전부라고 봐도 된다. **이 과정 속에서 어떤 오브젝트가 있고, 어떤 스펙이 있는지, 그래서 띄우면 어떻게 되는지를 이해하면 쿠버네티스를 사용**할 수 있는 것이다.

## 3. 오브젝트 YAML 명세 작성법

예를 들어 **pod 오브젝트**를 띄우고 싶을 때 spec을 어떻게 `yaml` 형식으로 작성하는지 알아보자.

```yaml
apiVersion: v1
kind: Pod
metadata:
    name: example
spec:
    containers:
    - name: busybox
        image: busybox:1.25
```

`key:value` 형식으로 이렇게 명세를 작성하면, API 서버가 이 명세를 보고 ectd에 정보를 저장하고 각 컨트롤러들이 동작을 하는 것이다. 게시글 최상단의 그림은 ReplicaSet의 스펙을 작성하는 예시이다.

아래는 **ArgoCD** 라는 커스텀 리소스를 어떻게 호출하는지에 대한 예시인데, **어떤 오브젝트이던지 `apiVersion`, `kind`, `metadata` 를 작성하는 방법은 동일하다. 그리고 종류에 따라 `spec` 을 그에 맞게 작성해주면 된다.**

![](https://github.com/hidaehyunlee/Fork-my-brain/tree/4f7d19f4487fe8d450e22a9b6451bbed865ce125/images/37580034-108155054-7b371900-7121-11eb-8da3-2267df2ddf48.png)

세 종류의 API를 호출하는 방법을 알아봤는데, 보다시피 형식 자체는 동일하다. `spec` 만 각 오브젝트의 스펙으로 작성해주면 되는 것이다.

## 4. 요약 및 정리

yaml 포맷에 들어가는 내용을 정리를 해보자.

* **apiVersion** : 종류가 많을 수 있다. 배포 버전, 앱의 버전, 네트워크 버전...등등&#x20;
* **kine** : 오브젝트의 종류를 적어준다. Pod, Depolyment, Service, Ingress..
* **metadata** : name, namespace, label을 설정할 수 있다.
* **spec** : 각종 설정에 대한 정보를 담고 있는데, 어떤 오브젝트냐에 따라 달라질 수 있기 때문에 각 종류의 스펙을 보고 작성해주면 된다.
* **status** : 각종 설정의 현재 최신 상태를 read-only로 관리하는 항목이다. 컨트롤러가 현재상태를 조회할 때 이 status 를 확인한다.

이제 쿠버네티스 안내서의 [워드프레스 배포](https://subicura.com/k8s/guide/#%EA%B0%80%EC%9D%B4%EB%93%9C) 실습을 해보면 조금 더 감이 올 것 같다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hidaehyunlee.gitbook.io/fork-my-brain/kubernetes/3.-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
