---
title: Kubernetes
description: Ejecuta Human Plugin en Kubernetes con un Deployment, un Service ClusterIP, un Secret para la configuración y un pull secret para el registry de Unico.
canonical: https://developer.unico.io/es/human-plugin/self-hosting/kubernetes
locale: es
generated_by: markdown-export
---

# Kubernetes

Dos o más réplicas detrás de un Service ClusterIP, accesibles solo desde tu back-end.

## Requisitos previos

- Un clúster de Kubernetes y acceso a él con `kubectl`.
- Una base de datos PostgreSQL dedicada a Human Plugin, accesible desde el clúster. Consulta [Requisitos previos y acceso](/es/human-plugin/get-started/prerequisites).
- Las credenciales del registry y la clave de acceso que entrega Unico.

Todo lo que sigue va en un namespace propio:

```bash
kubectl create namespace human-plugin
```

## 1. Pull secret del registry

```bash
kubectl -n human-plugin create secret docker-registry unico-registry \
  --docker-server=pkg.unico.run \
  --docker-username="<username>" \
  --docker-password="<token>"
```

## 2. Secret de configuración

```bash
kubectl -n human-plugin create secret generic human-plugin \
  --from-literal=HUMAN_API_ACCESS_KEY='<your access key>' \
  --from-literal=POSTGRES_ADDRESS_HOST='<database host>' \
  --from-literal=POSTGRES_USER='human_plugin' \
  --from-literal=POSTGRES_PASSWORD='<database password>'
```

Agrega `POSTGRES_ADDRESS_PORT`, `POSTGRES_DATABASE` o `POSTGRES_SSL_MODE` solo si tu base de datos difiere de los valores predeterminados de [Configuración](/es/human-plugin/self-hosting/configuration). Si gestionas los secretos con otra herramienta (External Secrets, Sealed Secrets, un vault), crea las mismas claves con ella. Nunca hagas commit de un manifiesto de Secret con valores.

## 3. Deployment y Service

```yaml title="human-plugin.yaml"
apiVersion: apps/v1
kind: Deployment
metadata:
  name: human-plugin
  namespace: human-plugin
spec:
  replicas: 2
  selector:
    matchLabels: { app: human-plugin }
  template:
    metadata:
      labels: { app: human-plugin }
    spec:
      terminationGracePeriodSeconds: 60
      imagePullSecrets:
        - name: unico-registry
      containers:
        - name: human-plugin
          image: pkg.unico.run/human-plugin-api:latest
          imagePullPolicy: Always
          ports:
            - { name: http, containerPort: 8080 }
          envFrom:
            - secretRef: { name: human-plugin }
          resources:
            requests: { cpu: "1", memory: 1Gi }
            limits: { cpu: "1", memory: 1Gi }
          readinessProbe:
            httpGet: { path: /health/ready, port: http }
            timeoutSeconds: 5
          livenessProbe:
            httpGet: { path: /health/live, port: http }
            periodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
  name: human-plugin
  namespace: human-plugin
spec:
  selector: { app: human-plugin }
  ports:
    - { name: http, port: 8080, targetPort: http }
```

```bash
kubectl apply -f human-plugin.yaml
```

```bash
kubectl -n human-plugin rollout status deployment/human-plugin
```

- **`replicas: 2`:** las réplicas comparten la base de datos, por lo que puedes ejecutar tantas como necesites. Dos mantienen Human Plugin disponible mientras una se reinicia.
- **`terminationGracePeriodSeconds: 60`:** al detenerse, Human Plugin espera hasta 55 segundos a que terminen las solicitudes en curso. El valor predeterminado de Kubernetes, 30 segundos, puede interrumpir una creación.
- **`imagePullPolicy: Always`:** con la etiqueta `latest`, cada Pod nuevo descarga la versión más reciente.
- **Sondas:** la readiness mantiene el tráfico alejado de una réplica hasta que su base de datos responde, y `timeoutSeconds: 5` hace que falle cuando la base de datos deja de responder. Consulta [Salud y monitoreo](/es/human-plugin/self-hosting/health-and-monitoring).
- **Recursos:** los valores de arriba son el mínimo para cada réplica. Consulta [Requisitos de hardware](/es/human-plugin/self-hosting/overview#hardware-requirements).

## 4. Restringe el acceso

Tu back-end accede a Human Plugin en `http://human-plugin.human-plugin.svc:8080`. Human Plugin no tiene autenticación propia, por lo tanto:

- no expongas el Service mediante un Ingress, un `LoadBalancer` ni un `NodePort`;
- permite únicamente el namespace de tu back-end con una NetworkPolicy.

```yaml title="network-policy.yaml"
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: human-plugin-allow-backend
  namespace: human-plugin
spec:
  podSelector:
    matchLabels: { app: human-plugin }
  policyTypes: [Ingress]
  ingress:
    - from:
        - namespaceSelector:
            matchLabels: { kubernetes.io/metadata.name: <your back-end namespace> }
      ports:
        - { port: 8080 }
```

Human Plugin necesita salida HTTPS hacia Unico y acceso a tu base de datos. Consulta [Redes y seguridad](/es/human-plugin/self-hosting/networking-and-security).

## 5. Valida

```bash
kubectl -n human-plugin port-forward svc/human-plugin 8080:8080
```

En otra terminal, verifica la readiness y ejecuta la solicitud de creación del [Quickstart](/es/human-plugin/get-started/quickstart#3-create-a-process) contra `http://127.0.0.1:8080`:

```bash
curl --fail http://127.0.0.1:8080/health/ready
```

## Logs

```bash
kubectl -n human-plugin logs deploy/human-plugin --since=10m
```

## Actualizar

```bash
kubectl -n human-plugin rollout restart deployment/human-plugin
```

Los Pods nuevos descargan la imagen más reciente y reemplazan a los anteriores de uno en uno, una vez que están listos. Consulta [Operaciones](/es/human-plugin/self-hosting/operations).