> ## Documentation Index
> Fetch the complete documentation index at: https://orphelix.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Deployments API

> API endpoints for managing Kubernetes Deployments

## Overview

The Deployments API provides endpoints for listing, viewing, and managing Kubernetes Deployments.

## Endpoints

### List Deployments

```http theme={null}
GET /api/deployments
```

**Query Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `namespace` | string | Yes | Kubernetes namespace |
| `context` | string | No | Kubeconfig context |

**Example Request:**

```bash theme={null}
curl "http://localhost:3000/api/deployments?namespace=default"
```

**Example Response:**

```json theme={null}
{
  "deployments": [
    {
      "name": "nginx",
      "namespace": "default",
      "replicas": {
        "desired": 3,
        "ready": 3,
        "available": 3,
        "unavailable": 0
      },
      "status": "Available",
      "age": "5d",
      "images": ["nginx:1.21"],
      "labels": {
        "app": "nginx",
        "tier": "frontend"
      },
      "createdAt": "2025-01-23T10:00:00Z"
    }
  ]
}
```

### Get Deployment Details

```http theme={null}
GET /api/deployments/[name]
```

**Path Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `name` | string | Yes | Deployment name |

**Query Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `namespace` | string | Yes | Kubernetes namespace |
| `context` | string | No | Kubeconfig context |

**Example Request:**

```bash theme={null}
curl "http://localhost:3000/api/deployments/nginx?namespace=default"
```

**Example Response:**

```json theme={null}
{
  "name": "nginx",
  "namespace": "default",
  "uid": "abc123...",
  "replicas": {
    "desired": 3,
    "ready": 3,
    "available": 3,
    "unavailable": 0,
    "updated": 3
  },
  "status": "Available",
  "conditions": [
    {
      "type": "Available",
      "status": "True",
      "lastUpdateTime": "2025-01-23T10:05:00Z",
      "lastTransitionTime": "2025-01-23T10:05:00Z",
      "reason": "MinimumReplicasAvailable",
      "message": "Deployment has minimum availability."
    },
    {
      "type": "Progressing",
      "status": "True",
      "lastUpdateTime": "2025-01-23T10:05:00Z",
      "lastTransitionTime": "2025-01-23T10:00:00Z",
      "reason": "NewReplicaSetAvailable",
      "message": "ReplicaSet \"nginx-abc123\" has successfully progressed."
    }
  ],
  "strategy": {
    "type": "RollingUpdate",
    "rollingUpdate": {
      "maxSurge": 1,
      "maxUnavailable": 0
    }
  },
  "selector": {
    "matchLabels": {
      "app": "nginx"
    }
  },
  "template": {
    "metadata": {
      "labels": {
        "app": "nginx"
      }
    },
    "spec": {
      "containers": [
        {
          "name": "nginx",
          "image": "nginx:1.21",
          "ports": [
            {
              "containerPort": 80,
              "protocol": "TCP"
            }
          ],
          "resources": {
            "requests": {
              "cpu": "100m",
              "memory": "128Mi"
            },
            "limits": {
              "cpu": "500m",
              "memory": "512Mi"
            }
          }
        }
      ]
    }
  },
  "createdAt": "2025-01-23T10:00:00Z",
  "labels": {
    "app": "nginx",
    "tier": "frontend"
  },
  "annotations": {
    "deployment.kubernetes.io/revision": "1"
  }
}
```

### Restart Deployment

```http theme={null}
POST /api/deployments/[name]/restart
```

**Path Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `name` | string | Yes | Deployment name |

**Request Body:**

```json theme={null}
{
  "namespace": "default"
}
```

**Example Request:**

```bash theme={null}
curl -X POST "http://localhost:3000/api/deployments/nginx/restart" \
  -H "Content-Type: application/json" \
  -d '{"namespace":"default"}'
```

**Example Response:**

```json theme={null}
{
  "success": true,
  "message": "Deployment restarted successfully",
  "deployment": "nginx",
  "namespace": "default",
  "timestamp": "2025-01-28T10:00:00Z"
}
```

**How it works:**
Adds `kubectl.kubernetes.io/restartedAt` annotation to pod template, triggering rolling restart.

### Get Deployment Pods

```http theme={null}
GET /api/deployments/[name]/pods
```

**Path Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `name` | string | Yes | Deployment name |

**Query Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `namespace` | string | Yes | Kubernetes namespace |
| `context` | string | No | Kubeconfig context |

**Example Request:**

```bash theme={null}
curl "http://localhost:3000/api/deployments/nginx/pods?namespace=default"
```

**Example Response:**

```json theme={null}
{
  "pods": [
    {
      "name": "nginx-abc123-xyz",
      "namespace": "default",
      "status": "Running",
      "phase": "Running",
      "nodeName": "node-1",
      "podIP": "10.244.1.5",
      "containers": [
        {
          "name": "nginx",
          "image": "nginx:1.21",
          "ready": true,
          "restartCount": 0,
          "state": {
            "running": {
              "startedAt": "2025-01-23T10:00:00Z"
            }
          }
        }
      ],
      "createdAt": "2025-01-23T10:00:00Z"
    }
  ]
}
```

### Get Deployment Events

```http theme={null}
GET /api/deployments/[name]/events
```

**Path Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `name` | string | Yes | Deployment name |

**Query Parameters:**

| Parameter | Type | Required | Description |
| - | - | - | - |
| `namespace` | string | Yes | Kubernetes namespace |
| `context` | string | No | Kubeconfig context |

**Example Request:**

```bash theme={null}
curl "http://localhost:3000/api/deployments/nginx/events?namespace=default"
```

**Example Response:**

```json theme={null}
{
  "events": [
    {
      "type": "Normal",
      "reason": "ScalingReplicaSet",
      "message": "Scaled up replica set nginx-abc123 to 3",
      "count": 1,
      "firstTimestamp": "2025-01-23T10:00:00Z",
      "lastTimestamp": "2025-01-23T10:00:00Z",
      "involvedObject": {
        "kind": "Deployment",
        "name": "nginx",
        "namespace": "default"
      }
    }
  ]
}
```

## Error Responses

### 400 Bad Request

```json theme={null}
{
  "error": "Namespace parameter is required",
  "code": "BAD_REQUEST"
}
```

### 403 Forbidden

```json theme={null}
{
  "error": "Forbidden: User cannot get resource \"deployments\" in API group \"apps\" in namespace \"default\"",
  "code": "FORBIDDEN",
  "statusCode": 403
}
```

### 404 Not Found

```json theme={null}
{
  "error": "Deployment not found",
  "code": "NOT_FOUND",
  "deployment": "nginx",
  "namespace": "default"
}
```

### 500 Internal Server Error

```json theme={null}
{
  "error": "Failed to fetch deployments",
  "code": "INTERNAL_ERROR",
  "details": "Connection timeout"
}
```

## Usage Examples

### JavaScript/TypeScript

```typescript theme={null}
// List deployments
async function listDeployments(namespace: string) {
  const res = await fetch(`/api/deployments?namespace=${namespace}`)
  if (!res.ok) throw new Error('Failed to fetch deployments')
  return res.json()
}

// Get deployment
async function getDeployment(name: string, namespace: string) {
  const res = await fetch(`/api/deployments/${name}?namespace=${namespace}`)
  if (!res.ok) throw new Error('Failed to fetch deployment')
  return res.json()
}

// Restart deployment
async function restartDeployment(name: string, namespace: string) {
  const res = await fetch(`/api/deployments/${name}/restart`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ namespace })
  })
  if (!res.ok) throw new Error('Failed to restart deployment')
  return res.json()
}
```

### React Query Hook

```typescript theme={null}
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'

export function useDeployments(namespace: string) {
  return useQuery({
    queryKey: ['deployments', namespace],
    queryFn: () => listDeployments(namespace),
    enabled: !!namespace,
    refetchInterval: 30000,
  })
}

export function useRestartDeployment() {
  const queryClient = useQueryClient()
  
  return useMutation({
    mutationFn: ({ name, namespace }: { name: string; namespace: string }) =>
      restartDeployment(name, namespace),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['deployments'] })
    },
  })
}
```

## Next Steps

> [card] [Pods API](https://orphelix.mintlify.site/developer/api/pods.md)
>
> Pod management endpoints

> [card] [Nodes API](https://orphelix.mintlify.site/developer/api/nodes.md)
>
> Node monitoring endpoints

> [card] [Events API](https://orphelix.mintlify.site/developer/api/events.md)
>
> Event tracking endpoints

> [card] [Real-time API](https://orphelix.mintlify.site/developer/api/realtime.md)
>
> Live updates with SSE


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.