ClusterIP Service के पीछे दो या अधिक replicas, जो केवल आपके back-end से पहुँच योग्य हैं।
पूर्वापेक्षाएँ
- एक Kubernetes cluster और उस तक
kubectlएक्सेस। - Human Plugin के लिए समर्पित एक PostgreSQL डेटाबेस, जो cluster से पहुँच योग्य हो। पूर्वापेक्षाएँ और एक्सेस देखें।
- Unico से मिले registry credentials और access key।
नीचे का सब कुछ अपने अलग namespace में रखें:
kubectl create namespace human-plugin
1. Registry pull secret
kubectl -n human-plugin create secret docker-registry unico-registry \
--docker-server=pkg.unico.run \
--docker-username="<username>" \
--docker-password="<token>"
2. सेटिंग्स Secret
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 तभी जोड़ें जब आपका डेटाबेस कॉन्फ़िगरेशन के डिफ़ॉल्ट मानों से अलग हो। यदि आप secrets को किसी अन्य टूल (External Secrets, Sealed Secrets, एक vault) से प्रबंधित करते हैं, तो उसी से यही keys बनाएँ। मानों वाला Secret manifest कभी commit न करें।
3. Deployment और Service
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 }
kubectl apply -f human-plugin.yaml
kubectl -n human-plugin rollout status deployment/human-plugin
replicas: 2: replicas डेटाबेस साझा करते हैं, इसलिए आप जितने चाहें उतने चला सकते हैं। दो replicas एक के रीस्टार्ट होने के दौरान भी Human Plugin को उपलब्ध रखते हैं।terminationGracePeriodSeconds: 60: रुकते समय Human Plugin चल रहे अनुरोधों के लिए 55 सेकंड तक प्रतीक्षा करता है। Kubernetes का डिफ़ॉल्ट, 30 सेकंड, किसी create को बी च में काट सकता है।imagePullPolicy: Always:latesttag के साथ, हर नया Pod सबसे हालिया release pull करता है।- Probes: readiness किसी replica को तब तक ट्रैफ़िक से दूर रखता है जब तक उसका डेटाबेस उत्तर न दे, और
timeoutSeconds: 5डेटाबेस के उत्तर देना बंद करने पर उसे विफल कर देता है। हेल्थ और मॉनिटरिंग देखें। - Resources: ऊपर के मान प्रत्येक replica के लिए न्यूनतम हैं। हार्डवेयर आवश्यकताएँ देखें।
4. एक्सेस सीमित करें
आपका back-end Human Plugin तक http://human-plugin.human-plugin.svc:8080 पर पहुँचता है। Human Plugin में अपना कोई authentication नहीं है, इसलिए:
- Service को Ingress,
LoadBalancerयाNodePortके ज़रिए expose न करें; - NetworkPolicy से केवल अपने back-end के namespace को अनुमति दें।
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 को स्वयं Unico तक outbound HTTPS और आपके डेटाबेस तक एक्सेस चाहिए। नेटवर्किंग और सुरक्षा देखें।
5. सत्यापित करें
kubectl -n human-plugin port-forward svc/human-plugin 8080:8080
दूसरे terminal में, readiness जाँचें और http://127.0.0.1:8080 के विरुद्ध क्विकस्टार्ट का create अनुरोध चलाएँ:
curl --fail http://127.0.0.1:8080/health/ready
लॉग
kubectl -n human-plugin logs deploy/human-plugin --since=10m
अपडेट
kubectl -n human-plugin rollout restart deployment/human-plugin
नए Pods नवीनतम image pull करते हैं और तैयार होने पर पुराने Pods को एक-एक करके बदलते हैं। ऑपरेशंस देखें।