# 4. YAML Configuration File

### Introduction

* Config File is written in YAML Format
* Config File should be stored with the code inside SCM

***

### 3 Parts of K8 Config File

1. Metadata
2. Specification
3. Status (Auto Generated & Added by K8)
   * K8 Gets Status from etcd

***

### Template

* The specified **kind** has its own *metadata* and *spec*
* Pod has also a section of its own which contains its own configuration&#x20;

<figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FD468YvIcUQZ9kmhrITzT%2Fimage.png?alt=media&#x26;token=750decbb-27b2-4361-869c-157a2fc8286e" alt=""><figcaption></figcaption></figure>

#### Labels & Connectors

* *Metadata* section contain the labels
* *Spec* section contains the selectors

**Connecting Deployment to Pods**

* Deployment looks which pods belong to it using labels (key value pairs)
* The label is matched by the selector&#x20;

<figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FqgVbuLHaairhLWVX9z1c%2Fimage.png?alt=media&#x26;token=1aa765ae-097f-4d21-b10b-856d50a974d0" alt=""><figcaption></figcaption></figure>

**Connecting Services to Deployments**

* Similar concept as connecting deployment to pods&#x20;

<figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2FZO7uGOiaI9WRFM2er6gV%2Fimage.png?alt=media&#x26;token=222824e8-5190-4b08-86c7-e7cb88c5a2f9" alt=""><figcaption></figcaption></figure>

#### Ports in Service & Pods

* Service listens on port and forwards the request to target port which must be of a pod&#x20;

<figure><img src="https://1920086362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDfv51K0WXLZdwTryHQZc%2Fuploads%2F3y62YqbvooIo1IQoIt9d%2Fimage.png?alt=media&#x26;token=7b79bb30-d342-4281-9404-50ed515bd086" alt=""><figcaption></figcaption></figure>

### Minimal Deployment File

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.16
        ports:
        - containerPort: 8080
```

***

### Minimal Service File

```yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
```

***


---

# 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://notes.nomanaziz.me/devops/orchestration/kubernetes/4.-yaml-configuration-file.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.
