下午好,我遇到了无法在 kybernetike 中启动 Django 项目的问题。我有一个针对该项目的部署。

apiVersion: v1
kind: Service
metadata:
  name: django-cloud-todo-list-svc
  labels:
    app: django-cloud-todo-list
spec:
  ports:
    - port: 8000
      targetPort: 8000
  type: LoadBalancer

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: django-cloud-todo-list
spec:
  selector:
    matchLabels:
      app: django-cloud-todo-list
      tier: app
  replicas: 1
  template:
    metadata:
      labels:
        app: django-cloud-todo-list
        tier: app
    spec:
      containers:
        - name: django-cloud-todo-list
          image: trickstermaster/cloud-todo-list-django_web:18.0
          ports:
            - containerPort: 8000

一切顺利开始

root@main-serv:/home/main-serv/k3s/deployment/cloud-todo-list-django_web# kubectl get pod
NAME                                      READY   STATUS    RESTARTS   AGE
django-cloud-todo-list-7fb9bbfcc6-r5zm6   1/1     Running   0          38m

root@main-serv:/home/main-serv/k3s/deployment/cloud-todo-list-django_web# kubectl get svc
NAME                         TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
django-cloud-todo-list-svc   LoadBalancer   10.43.186.41   192.168.0.176   8000:31806/TCP   38m

但是当你尝试打开页面时,什么都不起作用,pod 里面一切都很好

Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  41m   default-scheduler  Successfully assigned default/django-cloud-todo-list-7fb9bbfcc6-r5zm6 to k3s-master-1
  Normal  Pulled     41m   kubelet            Container image "trickstermaster/cloud-todo-list-django_web:18.0" already present on machine
  Normal  Created    41m   kubelet            Created container django-cloud-todo-list
  Normal  Started    41m   kubelet            Started container django-cloud-todo-list

LoadBalancer 运行正常,因为其他所有项目都运行正常。Image 也运行正常,如果在 docker-compose 中使用它,一切都会顺利运行。

version: '3.5'
services:
  web-server:
    image: trickstermaster/cloud-todo-list-django_web:18.0
    container_name: test
    ports:
      - '9000:8000'

2

  • 您查看过日志吗?是否有任何迹象表明应用程序已完全启动或流量已成功通过负载均衡器并被应用程序接收?


    – 

  • 问题出在部署文件中


    – 


最佳答案
1

我重新做了部署文件,一切开始

apiVersion: v1
kind: Service
metadata:
  name: django-cloud-todo-list-svc
spec:
  selector:
    app: django-cloud-todo-list
  type: LoadBalancer
  ports:
    - port: 8000
      targetPort: 8000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: django-cloud-todo-list
spec:
  replicas: 1
  selector:
    matchLabels:
      app: django-cloud-todo-list
  template:
    metadata:
      labels:
        app: django-cloud-todo-list
    spec:
      containers:
      - name: django-cloud-todo-list
        image: trickstermaster/cloud-todo-list-django_web:18.0
        ports:
          - containerPort: 8000
        imagePullPolicy: Always

1

  • 请详细说明解决问题的更改


    –