K8s 部署Django项目
K8s作为目前主流互联网使用技术栈,本次介绍如何将Django项目部署到Kubernetes中。
项目代码使用前面几章节定义的Django文件上传代码,使用上一章打包好的镜像,接下来就是部署到K8s中,请往下看:
Deployment yaml
apiVersion: apps/v1 kind: Deployment metadata: annotations: analysis.crane.io/resource-recommendation: | containers: - containerName: upload-service target: cpu: 125m memory: 375Mi deployment.kubernetes.io/revision: "4" myname: xiaowangtech labels: app.kubernetes.io/instance: upload-service name: upload-service namespace: devops spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: upload-service strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: annotations: myname: xiaowangtech labels: app: upload-service spec: containers: - env: image: devops-test.pkg.coding.net/django-upload-service:v2 imagePullPolicy: IfNotPresent name: upload-service ports: - containerPort: 8000 protocol: TCP resources: limits: cpu: "1" memory: 1Gi requests: cpu: 200m memory: 1Gi terminationMessagePath: /app/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst imagePullSecrets: - name: docker-registry restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30
Service yaml
apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/instance: upload-service name: upload-service-svc namespace: devops spec: internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - port: 8000 protocol: TCP targetPort: 8000 selector: app: upload-service sessionAffinity: None type: ClusterIP
Ingress yaml
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: kubernetes.io/ingress.class: test-ingress-internet myname: xiaowangtech labels: app.kubernetes.io/instance: upload-service name: upload-service-ingress namespace: devops spec: rules: - host: unit-upload.xxx.com http: paths: - backend: service: name: upload-service-svc port: number: 8000 path: / pathType: ImplementationSpecific tls: - hosts: - unit-upload.xxx.com secretName: xxx-com
部署查看
$ kubectl apply -f upload-service.yaml $ kubectl get ing,svc,pod -n devops
访问验证
亲测上述配置有效!!!
标签:name,service,部署,app,upload,Django,io,K8s From: https://www.cnblogs.com/weiweirui/p/17640315.html