我有一个简单的 HelloWorld ReactJs 应用程序 Docker 映像,我将部署创建为:
kind: Deployment
apiVersion: apps/v1
metadata:
name: minikube-react-app
spec:
replicas: 2
selector:
matchLabels:
app: minikube-react-app
template:
metadata:
labels:
app: minikube-react-app
spec:
containers:
- name: minikube-react-app
image: hello-react:1.0.1
imagePullPolicy: Never
ports:
- containerPort: 80
resources:
requests:
memory: "100Mi"
cpu: "300m"
limits:
memory: "200Mi"
cpu: "600m"
restartPolicy: Always
---
kind: Service
apiVersion: v1
metadata:
name: minikube-react-app
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
nodePort: 31000
selector:
app: minikube-react-app
我跑了,kubectl apply -f deployent.yaml
但是当我访问 http://localhost:31000 时它不起作用(无法访问此站点)。
有人可以帮我吗?
答案 0 :(得分:1)
应该使用'node ip'而不是'localhost'来访问节点端口。
运行 shell minikube ip
获取 minikube 节点的 ip。
检查服务类型:https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
答案 1 :(得分:0)
运行以下命令以从主机获取与您的应用程序连接的实际地址。
minikube service --url <service-name>