# Deploying Apidog on Kubernetes using Helm

## Overview
This guide details the deployment of **Apidog Enterprise On-Premises** on Kubernetes using the official Helm chart. This is the recommended deployment method as it simplifies configuration management, upgrades, and rollback processes.

:::tip[]
If you are looking for Docker deployment instructions, please refer to the [Docker Deployment Guide](https://self-hosting.apidog.com/standalone-docker-deployment-1804764m0.md)
:::
## Requirements & Prerequisites

### System Requirements

    - **[Kubernetes](https://kubernetes.io/docs/setup/)** Version 1.19+ (Verify with `kubectl version`)

    - **[Helm](https://helm.sh/docs/intro/install/)**: Version 3.0.0+ (Verify with `helm version`)

    - **Hardware & Software:** For hardware and software requirement, please refer to the [System Requirements](https://self-hosting.apidog.com/system-requirements-1048815m0.md) documentation.

### External Dependencies
    - **Database:** A PostgreSQL or MySQL instance. See [Database Configuration](https://self-hosting.apidog.com/database-configuration-405309m0.md).
    - **Storage**: An S3-compatible object storage service. See [Storage Services Configuration](https://self-hosting.apidog.com/storage-services-configuration-405310m0.md)
    - **Docker Registry Access:** Ensure you have the Access Token (received via email) to pull the private image.
    
    
## Preparation: Image Pull

Kubernetes requires authentication to pull images from the private Docker Hub repository.

 1.  **Log in to Docker Hub manually to verify credentials**
 
 ```bash
 docker login --username=apidog docker.io
 ```
 2. **Pull the Image**
 ```bash
 docker pull docker.io/apidog/apidog-ee:<image_tag>
 ```
## Database Initialization

:::info[]
**This guide utilizes a MySQL database. If you are using PostgreSQL, please refer to the [PostgreSQL Guidelines](https://self-hosting.apidog.com/database-configuration-405309m0.md##postgresql)**
:::

Apidog does not automatically create the database. You must manually connect to your database instance to initialize the database. Once connected, execute:

```sql
CREATE DATABASE IF NOT EXISTS apidog CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
exit;
```

## Installation Steps

### Download the Chart

1. **Download the Helm chart:**
Download and extract the latest Helm chart package.

```bash
# Download the latest Helm chart
wget https://file-assets.apidog.com/download/ee/templates/helm/apidog-chart-202602140225.zip

# Extract the chart
unzip apidog-chart-202602140225.zip

# Navigate to the chart directory
cd apidog-chart
```

2. **Configure the chart:**

- Edit the values.yaml file to match your environment. You must update:
    - **Database Connections**: Host, Port, Username, Password.
    - **Redis Settings**: Host, Port, Auth.
    - **Base URL**: The domain where Apidog will be accessible.
    - **License**
    
    and other environment specific values.
    
    :::caution[Important]
    For more information on the environment variables and how to configure them, please refer to the [Configuration Guide](doc-405300)
    :::

### Install via Helm
Deploy the application using the upgrade command, which works for both fresh installs and updates.

```bash
# Install with default values
helm upgrade --install apidog . --namespace apidog --create-namespace

# Or install with a custom values.
# Base: The default values.yaml file inside the chart directory (.) is always loaded first.
# Override: The values file(s) you specify with the -f flag are loaded next.
helm upgrade --install apidog . -f custom-values.yaml --namespace apidog --create-namespace
```

### Upgrading the Deployment

```bash
cd apidog-chart
# Upgrade the deployment
helm upgrade --install apidog . --namespace apidog

# Upgrade with new values
helm upgrade --install apidog . -f custom-values.yaml --namespace apidog
```

## Post-Deployment Management

After deploying with Helm, you can use kubectl commands to view pods, manage and troubleshoot your Apidog deployment:

### Viewing Pods and Logs

```bash
# List pods in the apidog
kubectl get pods -n apidog

# Get pod logs
kubectl logs <pod-name> -n apidog

# Follow pod logs in real-time
kubectl logs -f <pod-name> -n apidog
```

### Debugging with Interactive Shell

```bash
# Get an interactive shell in the pod
kubectl exec -it <pod-name> -n apidog -- /bin/sh
```

## Advanced Configuration: HashiCorp Vault

If you utilize HashiCorp Vault for secret management, you must modify the deployment entrypoint to decrypt secrets before the application starts.

Update your `values.yaml` or deployment configuration with the following command arguments:

```yaml
command: ["sh", "-c"]
args:
  [
    "echo 'Execute the decryption program if needed, or wait for the sidecar agent to decrypt the variables' && sleep 10 && echo 'Load the decrypted variables if needed. e.g., `. /vault/secrets/config`' && . /vault/secrets/config && export -p > /usr/src/app/startup.conf && /init",
  ]
```

## Verify System Health Check

Execute the following command to check the internal health status using the built-in doctor script.

```bash
kubectl exec -it <pod-name> -n apidog -- /bin/sh -c "cd /usr/src/app && ./doctor"
```

The application has started successfully if the output includes lines similar to the following:

```
[WARN] This Redis server's `default` user does not require a password, but a password was supplied
connect succeeded! value is  null
Executing (default): SELECT 1+1 AS result
...
Connecting to 127.0.0.1:3000 (127.0.0.1:3000)
remote file exists
Connecting to 127.0.0.1 (127.0.0.1:80)
remote file exists
Connecting to 127.0.0.1 (127.0.0.1:80)
remote file exists
Checking BASE_URL: https://your-base-url.com
API base URL matches expected BASE_URL
```

:::info[]
If the output differs from the above, the application has either not started successfully or is still in the process of starting. A typical graceful startup time is around 30 seconds, though this may vary depending on hardware performance.
:::

## Run the application


To run the application, refer to the documentations:

[Accessing Apidog Web Interface](https://self-hosting.apidog.com/accessing-apidog-web-interface-405307m0.md)
[Accessing Apidog Admin Panel](https://self-hosting.apidog.com/accessing-apidog-admin-panel-700382m0.md)
[Installing Apidog On-Premises Client](https://self-hosting.apidog.com/installing-apidog-on-premises-client-700348m0.md)
 

## Other Resources

[Using LDAP for Authentication](https://self-hosting.apidog.com/using-ldap-for-authentication-405303m0.md)
[Using OKTA for Authentication](https://self-hosting.apidog.com/using-okta-for-authentication-405304m0.md)
[Using OAuth2.0 for Authentication](https://self-hosting.apidog.com/using-oauth2-0-for-authentication-481407m0.md)
[Troubleshooting Guide](doc-405314)
[Configuration Guide](doc-405300)
[Updating Apidog](https://self-hosting.apidog.com/updating-apidog-405312m0.md)
[Backing up Apidog](https://self-hosting.apidog.com/backing-up-apidog-405313m0.md)
[License Renewal](https://self-hosting.apidog.com/license-renewal-703533m0.md)
