---
title: Kubernetes
description: شغّل Human Plugin على Kubernetes باستخدام Deployment وService من نوع ClusterIP وSecret للإعدادات وسر سحب (pull secret) لسجل Unico.
canonical: https://developer.unico.io/ar/human-plugin/self-hosting/kubernetes
locale: ar
generated_by: markdown-export
---

# Kubernetes

نسختان أو أكثر خلف Service من نوع ClusterIP، لا يمكن الوصول إليها إلا من الواجهة الخلفية لديك.

## المتطلبات المسبقة

- عنقود Kubernetes وصلاحية `kubectl` للوصول إليه.
- قاعدة بيانات PostgreSQL مخصصة لـ Human Plugin ويمكن الوصول إليها من العنقود. راجع [المتطلبات المسبقة والوصول](/ar/human-plugin/get-started/prerequisites).
- بيانات اعتماد السجل (registry) ومفتاح الوصول من Unico.

كل ما يلي يوضع في namespace خاص به:

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

## 1. سر سحب الصور من السجل

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

## 2. Secret الإعدادات

```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>'
```

أضف `POSTGRES_ADDRESS_PORT` أو `POSTGRES_DATABASE` أو `POSTGRES_SSL_MODE` فقط إذا كانت قاعدة بياناتك تختلف عن القيم الافتراضية في [الإعداد](/ar/human-plugin/self-hosting/configuration). إذا كنت تدير الأسرار بأداة أخرى (External Secrets أو Sealed Secrets أو خزنة أسرار)، فأنشئ المفاتيح نفسها بها. لا تضع أبدًا ملف Secret يحتوي على القيم في نظام التحكم بالإصدارات.

## 3. Deployment و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`:** تتشارك النسخ قاعدة البيانات نفسها، لذا يمكنك تشغيل العدد الذي تحتاجه. تُبقي نسختان Human Plugin متاحًا أثناء إعادة تشغيل إحداهما.
- **`terminationGracePeriodSeconds: 60`:** ينتظر Human Plugin حتى 55 ثانية لإنهاء الطلبات الجارية عند إيقافه. قد تقطع القيمة الافتراضية في Kubernetes، وهي 30 ثانية، عملية إنشاء قبل اكتمالها.
- **`imagePullPolicy: Always`:** مع الوسم `latest`، يسحب كل Pod جديد أحدث إصدار.
- **الفحوصات (Probes):** يبعد فحص الجاهزية الطلبات عن النسخة حتى تردّ قاعدة بياناتها، وتجعله `timeoutSeconds: 5` يفشل عندما تتوقف قاعدة البيانات عن الرد. راجع [الصحة والمراقبة](/ar/human-plugin/self-hosting/health-and-monitoring).
- **الموارد:** القيم أعلاه هي الحد الأدنى لكل نسخة. راجع [متطلبات الأجهزة](/ar/human-plugin/self-hosting/overview#hardware-requirements).

## 4. تقييد الوصول

تصل الواجهة الخلفية لديك إلى Human Plugin عبر `http://human-plugin.human-plugin.svc:8080`. لا يملك Human Plugin مصادقة خاصة به، لذلك:

- لا تعرض الـ Service عبر Ingress أو `LoadBalancer` أو `NodePort`؛
- اسمح فقط بالوصول من namespace الواجهة الخلفية لديك باستخدام 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 نفسه إلى اتصال HTTPS صادر إلى Unico وإلى الوصول إلى قاعدة بياناتك. راجع [الشبكات والأمان](/ar/human-plugin/self-hosting/networking-and-security).

## 5. التحقق

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

في نافذة طرفية أخرى، افحص الجاهزية ونفّذ طلب الإنشاء الوارد في [البدء السريع](/ar/human-plugin/get-started/quickstart#3-create-a-process) على `http://127.0.0.1:8080`:

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

## السجلات

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

## التحديث

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

تسحب الـ Pods الجديدة أحدث صورة وتحلّ محل القديمة واحدًا تلو الآخر، بمجرد أن تصبح جاهزة. راجع [العمليات](/ar/human-plugin/self-hosting/operations).