这可能是一个愚蠢的问题,但是我如何让我的https://localhost:5000通过我的flask kuberenetes应用程序工作,以确保其返回正确的信息?
这是我到目前为止的工作流程:
$ eval $(minikube docker-env)
$ docker build ...
$ kubectl apply -f deploy.yaml (contains deployment & service)
$ kubectl set image...
kubectl logs...
会在下面返回此信息:另外,我的pod已启动并正在运行,因此一切正常
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on https://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 443-461-677
唯一的事情是,当我在浏览器中转到该地址时,它说无法访问该网站。当我curl https://localhost:5000
或curl https://0.0.0.0:5000/
时,出现连接失败错误。我觉得我的环境/设置不正确。有什么提示/建议吗?
谢谢!
也继承了我的deploy.yaml文件:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: myapp
namespace: test-space
spec:
selector:
matchLabels:
app: myapp
replicas: 3
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp
imagePullPolicy: IfNotPresent
volumeMounts:
- name: secret-volume
mountPath: /etc/secret-volume
ports:
- containerPort: 80
env:
- name: "SECRET_KEY"
value: /etc/secret-volume/secret-key
- name: "SECRET_CRT"
value: /etc/secret-volume/secret-crt
volumes:
- name: secret-volume
secret:
secretName: my-secret3
---
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: test-space
spec:
type: NodePort
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 5000
nodePort: 30000
Dockerfile:
FROM python:2
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
EXPOSE 5000
CMD ["python", "app.py"]
答案 0 :(得分:0)
在Dockerfile中公开Port 5000
后,您需要在Deployment中的容器中公开同一端口。之后,您需要配置服务以使用此端口。
它应该像这样:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: myapp
namespace: test-space
spec:
selector:
matchLabels:
app: myapp
replicas: 3
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp
imagePullPolicy: IfNotPresent
volumeMounts:
- name: secret-volume
mountPath: /etc/secret-volume
ports:
- containerPort: 5000 #<<<PORT FIXED
env:
- name: "SECRET_KEY"
value: /etc/secret-volume/secret-key
- name: "SECRET_CRT"
value: /etc/secret-volume/secret-crt
volumes:
- name: secret-volume
secret:
secretName: my-secret3
---
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: test-space
spec:
type: NodePort
selector:
app: myapp
ports:
- protocol: TCP
port: 5000 #<<<PORT FIXED
targetPort: 5000
nodePort: 30000
之后,您可以在<any-kubernetes-node-IP>:30000
上找到您的应用程序
答案 1 :(得分:0)
您需要使用标签选择器myapp创建服务。 但是还有另一种卷曲的方法 通过登录正在运行的吊舱并从吊舱内部执行卷曲。
就做
kubectl exec -it podname / bin / bash这将打开bash shell 然后您可以卷曲localhost:5000