我无法使用clusterip从webbrowser连接到kubernetes pod

tjjdgumg  于 5个月前  发布在  Kubernetes
关注(0)|答案(3)|浏览(79)

我创建了一个简单的部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: hello-world
          image: michalwolnicki/myapp:testlatests4
          ports:
            - containerPort: 8080
              protocol: TCP

字符串
michalwolnicki/myapp:testlatests 4 image是我的应用程序,暴露/test1 URL unter 8080端口
接下来我创建了一个Nodeport:kubectl expose deployment hello-world --type=NodePort --name=example-service
当我登录到pod并运行此URL时:

curl localhost:8080/test1

成功连接到:hello-world-c54 bb 6 f45-npgxx# <--这是我的应用程序的响应
现在我想打开浏览器并在集群外访问这个/test1 URL:
要做到这一点,我必须遵循:
<port_from_Nodeport>/test1或<32193>/test 2
获取端口:
PS C:\Windows\system32> k get svc example-service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)AGE example-service NodePort 10.105.206.191 8080:31113/TCP 26 m
获取clusterIp:
PS C:\Windows\system32> k cluster-info Kubernetes控制平面正在https://127.0.0.1:36898上运行
所以我必须使用的URL将是:
127.0.0.1:31113/test1
但是当我粘贴它时,我无法连接:/
当我做这个练习的时候,它起作用了,但是当我搬到我的公寓的时候,我不能这样做:
我做错了什么?
我使用minikube

mepcadol

mepcadol1#

您可以通过两种可能的方式公开您的服务,通过端口转发或使用负载均衡器
本地端口转发

kubectl port-forward svc/<service_name> <local_port>:<service_port> -n <namespace>

kubectl port-forward svc/example-service 8081:8080

curl localhost:8081/test1

字符串
使用负载均衡器公开

kubectl expose deployment hello-world --type=LoadBalancer --name=example-service -n <namespace>

## Run this command to get the LoadBalancer IP
kubectl get svc -A

ivqmmu1c

ivqmmu1c2#

如果你尝试使用minikube运行,我建议将服务暴露为NodePort,并使用minikube隧道访问服务。

minikube service <service-name> --url

字符串
您可以在这里阅读更多

oalqel3c

oalqel3c3#

我还没有找到解决方案,为什么我不能到达我的网址,但我找到了一种方法来绕过这个问题。我已经下载了最新版本的minikube(以前的版本,我已经删除了minikube停止和删除.kube .minikube从c:/users/<my_user>)
突然一切都正常了,这次我发现kube controlplane ip和核心dns看起来不同了:以前我有127.0.0.1,现在172.26.245.231

相关问题