无法按照 Django 教程连接到 DevSpace 中的 Pod
Can't connect to Pod in DevSpace following Django tutorial
有问题的 DevSpace-Django 教程如下:
https://devspace.cloud/blog/2019/10/18/deploy-django-to-kubernetes
尝试一些完全准系统的东西来了解 devspace
是如何工作的,以决定我是否要从 skaffold
进行切换。上述教程中有许多内容似乎不再准确或在 devpsace
.
的较新版本中发生了变化
无论如何,当我导航到 localhost:8000
时,我无法连接到 Django tutorial app。它只是说“无法连接到服务器。”
这是我在 devspace dev
:
时得到的输出
devspace dev
[warn] There is a newer version of DevSpace: v5.15.0. Run `devspace upgrade` to upgrade to the newest version.
[info] Using namespace 'mysite'
[info] Using kube context 'mysite'
[info] Execute 'helm upgrade mysite component-chart --namespace mysite --values /var/folders/tl/wqf19mws155_7bkqyw401z_w0000gn/T/325113665 --install --repo https://charts.devspace.sh --repository-config='' --version 0.8.0 --kube-context mysite'
[info] Execute 'helm list --namespace mysite --output json --kube-context mysite'
[done] √ Deployed helm chart (Release revision: 5)
[done] √ Successfully deployed mysite with helm
[done] √ Port forwarding started on 8000:8000 (mysite/mysite-7b856bb78b-2ztpf-devspace)
#########################################################
[info] DevSpace UI available at: http://localhost:8090
#########################################################
[0:sync] Waiting for pods...
[0:sync] Starting sync...
[0:sync] Sync started on /Users/cjones/Projects/Apps/Test/mysite <-> . (Pod: mysite/mysite-7b856bb78b-2ztpf-devspace)
[0:sync] Waiting for initial sync to complete
[info] Opening 'http://localhost:8000' as soon as application will be started (timeout: 4m0s)
[info] Opening shell to pod:container mysite-7b856bb78b-2ztpf-devspace:container-0
Installing Python Dependencies
Requirement already satisfied: asgiref==3.4.1 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 1)) (3.4.1)
Requirement already satisfied: Django==3.2.7 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 2)) (3.2.7)
Requirement already satisfied: pytz==2021.1 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 3)) (2021.1)
Requirement already satisfied: sqlparse==0.4.1 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 4)) (0.4.1)
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.1.2; however, version 21.2.4 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
____ ____
| _ \ _____ __/ ___| _ __ __ _ ___ ___
| | | |/ _ \ \ / /\___ \| '_ \ / _` |/ __/ _ \
| |_| | __/\ V / ___) | |_) | (_| | (_| __/
|____/ \___| \_/ |____/| .__/ \__,_|\___\___|
|_|
Welcome to your development container!
This is how you can work with it:
- Run `python main.py` to build the application
- Files will be synchronized between your local machine and this container
- Some ports will be forwarded, so you can access this container on your local machine via localhost:
Image ImageSelector LabelSelector Ports (Local:Remote)
username/app 8000:8000
root@mysite-7b856bb78b-2ztpf-devspace:/app#
这是 DevSpace.yaml
:
version: v1beta10
# `vars` specifies variables which may be used as ${VAR_NAME} in devspace.yaml
vars:
- name: IMAGE
value: username/app
# `deployments` tells DevSpace how to deploy this project
deployments:
- name: mysite
# This deployment uses `helm` but you can also define `kubectl` deployments or kustomizations
helm:
# We are deploying the so-called Component Chart: https://devspace.sh/component-chart/docs
componentChart: true
# Under `values` we can define the values for this Helm chart used during `helm install/upgrade`
# You may also use `valuesFiles` to load values from files, e.g. valuesFiles: ["values.yaml"]
values:
containers:
- image: ${IMAGE} # Use the value of our `${IMAGE}` variable here (see vars above)
service:
ports:
- port: 8000
# `dev` only applies when you run `devspace dev`
dev:
# `dev.ports` specifies all ports that should be forwarded while `devspace dev` is running
# Port-forwarding lets you access your application via localhost on your local machine
ports:
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
forward:
- port: 8000
# `dev.open` tells DevSpace to open certain URLs as soon as they return HTTP status 200
# Since we configured port-forwarding, we can use a localhost address here to access our application
open:
- url: http://localhost:8000
# `dev.sync` configures a file sync between our Pods in k8s and your local project files
sync:
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
excludePaths:
- .git/
uploadExcludePaths:
- Dockerfile
# `dev.terminal` tells DevSpace to open a terminal as a last step during `devspace dev`
terminal:
imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
# With this optional `command` we can tell DevSpace to run a script when opening the terminal
# This is often useful to display help info for new users or perform initial tasks (e.g. installing dependencies)
# DevSpace has generated an example ./devspace_start.sh file in your local project - Feel free to customize it!
command:
- ./devspace_start.sh
# Since our Helm charts and manifests deployments are often optimized for production,
# DevSpace let's you swap out Pods dynamically to get a better dev environment
replacePods:
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
# Since the `${IMAGE}` used to start our main application pod may be distroless or not have any dev tooling, let's replace it with a dev-optimized image
# DevSpace provides a sample image here but you can use any image for your specific needs
replaceImage: loftsh/python:latest
# Besides replacing the container image, let's also apply some patches to the `spec` of our Pod
# We are overwriting `command` + `args` for the first container in our selected Pod, so it starts with `sleep 9999999`
# Using `sleep 9999999` as PID 1 (instead of the regular ENTRYPOINT), allows you to start the application manually
patches:
- op: replace
path: spec.containers[0].command
value:
- sleep
- op: replace
path: spec.containers[0].args
value:
- "9999999"
- op: remove
path: spec.containers[0].securityContext
# `profiles` lets you modify the config above for different environments (e.g. dev vs production)
profiles:
# This profile is called `production` and you can use it for example using: devspace deploy -p production
# We generally recommend to use the base config without any profiles as optimized for development (e.g. image build+push is disabled)
- name: production
# This profile adds our image to the config so that DevSpace will build, tag and push our image before the deployment
merge:
images:
app:
image: ${IMAGE} # Use the value of our `${IMAGE}` variable here (see vars above)
dockerfile: ./Dockerfile
这是 Dockerfile
:
FROM python:3.8-slim-buster
# Create project directory (workdir)
WORKDIR /app
# Add requirements.txt to WORKDIR and install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
# Add source code files to WORKDIR
ADD . .
# Application port (optional)
EXPOSE 8000
# Container start command
# It is also possible to override this in devspace.yaml via images.*.cmd
CMD ["manage.py", "runserver", "8000"]
DevSpace UI 和 kubectl get pods
都显示 Pod 是 运行ning。
这是使用 Docker 驱动程序部署到 minikube
。
运行 端口 8000
上没有其他任何东西,我还尝试 8080
将每次出现的 8000
更改为 8080
。
Django 项目只有当您 运行: django-admin startproject mysite
时才能得到。没什么特别的。
我不清楚我在这里做错了什么。建议?
编辑:
此外,意在指出 M1 Mac。不确定是否相关但值得指出。
尝试使用 docker-desktop
集群,minikube
认为这可能是 minikube
的潜在问题。同样的问题。
此外,使用 DevSpace 提供的项目尝试了此处的快速入门指南,结果相同:
Django tutorial 遗漏了某种重要的步骤。在 运行ning devspace dev
之后,您需要在出现的 devspace
CLI 中 运行:
./manage.py runserver
这将在浏览器中启动应用程序。
有问题的 DevSpace-Django 教程如下:
https://devspace.cloud/blog/2019/10/18/deploy-django-to-kubernetes
尝试一些完全准系统的东西来了解 devspace
是如何工作的,以决定我是否要从 skaffold
进行切换。上述教程中有许多内容似乎不再准确或在 devpsace
.
无论如何,当我导航到 localhost:8000
时,我无法连接到 Django tutorial app。它只是说“无法连接到服务器。”
这是我在 devspace dev
:
devspace dev
[warn] There is a newer version of DevSpace: v5.15.0. Run `devspace upgrade` to upgrade to the newest version.
[info] Using namespace 'mysite'
[info] Using kube context 'mysite'
[info] Execute 'helm upgrade mysite component-chart --namespace mysite --values /var/folders/tl/wqf19mws155_7bkqyw401z_w0000gn/T/325113665 --install --repo https://charts.devspace.sh --repository-config='' --version 0.8.0 --kube-context mysite'
[info] Execute 'helm list --namespace mysite --output json --kube-context mysite'
[done] √ Deployed helm chart (Release revision: 5)
[done] √ Successfully deployed mysite with helm
[done] √ Port forwarding started on 8000:8000 (mysite/mysite-7b856bb78b-2ztpf-devspace)
#########################################################
[info] DevSpace UI available at: http://localhost:8090
#########################################################
[0:sync] Waiting for pods...
[0:sync] Starting sync...
[0:sync] Sync started on /Users/cjones/Projects/Apps/Test/mysite <-> . (Pod: mysite/mysite-7b856bb78b-2ztpf-devspace)
[0:sync] Waiting for initial sync to complete
[info] Opening 'http://localhost:8000' as soon as application will be started (timeout: 4m0s)
[info] Opening shell to pod:container mysite-7b856bb78b-2ztpf-devspace:container-0
Installing Python Dependencies
Requirement already satisfied: asgiref==3.4.1 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 1)) (3.4.1)
Requirement already satisfied: Django==3.2.7 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 2)) (3.2.7)
Requirement already satisfied: pytz==2021.1 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 3)) (2021.1)
Requirement already satisfied: sqlparse==0.4.1 in /usr/local/lib/python3.9/site-packages (from -r requirements.txt (line 4)) (0.4.1)
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.1.2; however, version 21.2.4 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
____ ____
| _ \ _____ __/ ___| _ __ __ _ ___ ___
| | | |/ _ \ \ / /\___ \| '_ \ / _` |/ __/ _ \
| |_| | __/\ V / ___) | |_) | (_| | (_| __/
|____/ \___| \_/ |____/| .__/ \__,_|\___\___|
|_|
Welcome to your development container!
This is how you can work with it:
- Run `python main.py` to build the application
- Files will be synchronized between your local machine and this container
- Some ports will be forwarded, so you can access this container on your local machine via localhost:
Image ImageSelector LabelSelector Ports (Local:Remote)
username/app 8000:8000
root@mysite-7b856bb78b-2ztpf-devspace:/app#
这是 DevSpace.yaml
:
version: v1beta10
# `vars` specifies variables which may be used as ${VAR_NAME} in devspace.yaml
vars:
- name: IMAGE
value: username/app
# `deployments` tells DevSpace how to deploy this project
deployments:
- name: mysite
# This deployment uses `helm` but you can also define `kubectl` deployments or kustomizations
helm:
# We are deploying the so-called Component Chart: https://devspace.sh/component-chart/docs
componentChart: true
# Under `values` we can define the values for this Helm chart used during `helm install/upgrade`
# You may also use `valuesFiles` to load values from files, e.g. valuesFiles: ["values.yaml"]
values:
containers:
- image: ${IMAGE} # Use the value of our `${IMAGE}` variable here (see vars above)
service:
ports:
- port: 8000
# `dev` only applies when you run `devspace dev`
dev:
# `dev.ports` specifies all ports that should be forwarded while `devspace dev` is running
# Port-forwarding lets you access your application via localhost on your local machine
ports:
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
forward:
- port: 8000
# `dev.open` tells DevSpace to open certain URLs as soon as they return HTTP status 200
# Since we configured port-forwarding, we can use a localhost address here to access our application
open:
- url: http://localhost:8000
# `dev.sync` configures a file sync between our Pods in k8s and your local project files
sync:
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
excludePaths:
- .git/
uploadExcludePaths:
- Dockerfile
# `dev.terminal` tells DevSpace to open a terminal as a last step during `devspace dev`
terminal:
imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
# With this optional `command` we can tell DevSpace to run a script when opening the terminal
# This is often useful to display help info for new users or perform initial tasks (e.g. installing dependencies)
# DevSpace has generated an example ./devspace_start.sh file in your local project - Feel free to customize it!
command:
- ./devspace_start.sh
# Since our Helm charts and manifests deployments are often optimized for production,
# DevSpace let's you swap out Pods dynamically to get a better dev environment
replacePods:
- imageSelector: ${IMAGE} # Select the Pod that runs our `${IMAGE}`
# Since the `${IMAGE}` used to start our main application pod may be distroless or not have any dev tooling, let's replace it with a dev-optimized image
# DevSpace provides a sample image here but you can use any image for your specific needs
replaceImage: loftsh/python:latest
# Besides replacing the container image, let's also apply some patches to the `spec` of our Pod
# We are overwriting `command` + `args` for the first container in our selected Pod, so it starts with `sleep 9999999`
# Using `sleep 9999999` as PID 1 (instead of the regular ENTRYPOINT), allows you to start the application manually
patches:
- op: replace
path: spec.containers[0].command
value:
- sleep
- op: replace
path: spec.containers[0].args
value:
- "9999999"
- op: remove
path: spec.containers[0].securityContext
# `profiles` lets you modify the config above for different environments (e.g. dev vs production)
profiles:
# This profile is called `production` and you can use it for example using: devspace deploy -p production
# We generally recommend to use the base config without any profiles as optimized for development (e.g. image build+push is disabled)
- name: production
# This profile adds our image to the config so that DevSpace will build, tag and push our image before the deployment
merge:
images:
app:
image: ${IMAGE} # Use the value of our `${IMAGE}` variable here (see vars above)
dockerfile: ./Dockerfile
这是 Dockerfile
:
FROM python:3.8-slim-buster
# Create project directory (workdir)
WORKDIR /app
# Add requirements.txt to WORKDIR and install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
# Add source code files to WORKDIR
ADD . .
# Application port (optional)
EXPOSE 8000
# Container start command
# It is also possible to override this in devspace.yaml via images.*.cmd
CMD ["manage.py", "runserver", "8000"]
DevSpace UI 和 kubectl get pods
都显示 Pod 是 运行ning。
这是使用 Docker 驱动程序部署到 minikube
。
运行 端口 8000
上没有其他任何东西,我还尝试 8080
将每次出现的 8000
更改为 8080
。
Django 项目只有当您 运行: django-admin startproject mysite
时才能得到。没什么特别的。
我不清楚我在这里做错了什么。建议?
编辑:
此外,意在指出 M1 Mac。不确定是否相关但值得指出。
尝试使用 docker-desktop
集群,minikube
认为这可能是 minikube
的潜在问题。同样的问题。
此外,使用 DevSpace 提供的项目尝试了此处的快速入门指南,结果相同:
Django tutorial 遗漏了某种重要的步骤。在 运行ning devspace dev
之后,您需要在出现的 devspace
CLI 中 运行:
./manage.py runserver
这将在浏览器中启动应用程序。