我在 Mac OS 上运行与 docker 捆绑的本地 kubernetes。
如何公开服务,以便我可以通过 Mac 上的浏览器访问该服务?
我创建了:
a) 部署包括 apache httpd。
b) 通过 yaml 服务:
apiVersion: v1
kind: Service
metadata:
name: apaches
spec:
selector:
app: web
type: NodePort
ports:
- protocol: TCP
port: 80
externalIPs:
- 192.168.1.10 # Network IP of my Mac
我的服务看起来像:
$ kubectl get service apaches
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
apaches NodePort 10.102.106.158 192.168.1.10 80:31137/TCP 14m
我可以通过
wget $CLUSTER-IP
在本地访问我的 kubernetes 集群中的服务我尝试调用http://192.168.1.10/在我的 Mac 上,但它不起作用。
这个question处理类似的问题。但是解决方案没有帮助,因为我不知道我可以使用哪个 IP。
更新
感谢 Michael Hausenblas,我使用 Ingress 制定了一个解决方案.
尽管如此,仍有一些悬而未决的问题:
最佳答案
非常简单的例子
方法1
$ kubectl create deployment nginx-dep --image=nginx --replicas=2
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-dep-5c5477cb4-76t9q 1/1 Running 0 7h5m
nginx-dep-5c5477cb4-9g84j 1/1 Running 0 7h5m
kubectl port
访问 pod $ kubectl port-forward nginx-dep-5c5477cb4-9g84j 8888:80
Forwarding from 127.0.0.1:8888 -> 80
Forwarding from [::1]:8888 -> 80
curl
到localhost:8888
$ curl -v http://localhost:8888
方法2你可以曝光
port 80
部署的(应用程序运行的地方,即 nginx 端口)通过 NodePort
$ kubectl expose deployment nginx-dep --name=nginx-dep-svc --type=NodePort --port=80
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 31d
nginx-dep-svc NodePort 10.110.80.21 <none> 80:31239/TCP 21m
$ curl http://localhost:31239
关于kubernetes - 在本地 Kubernetes 上公开服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49219171/