[英]How would I set up kubernetes Services and pods' IP addresses and ports to send some information into a pod?
The issue of ClusterIP, pod IP, nodePort, and targetPort are still a little confusing to me. ClusterIP、pod IP、nodePort、targetPort 的问题还是让我有点摸不着头脑。
I want to set up a small test case to better evaluate use cases, but I am having a bit of trouble.我想建立一个小测试用例来更好地评估用例,但我遇到了一些麻烦。 At the moment, I am working with kubernetes for docker on mac.
目前,我正在使用 kubernetes 在 mac 上为 docker 工作。
What I'd like:我想要什么:
I am pretty sure I need something like a Service to act as the middleware between the pod and me, but I am not sure how to set something like this up.我很确定我需要像 Service 这样的东西来充当 Pod 和我之间的中间件,但我不确定如何设置这样的东西。
Something like the kubernetes-dashboard api, where I can access the pod with:类似于 kubernetes-dashboard api 之类的东西,我可以通过以下方式访问 pod:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/pod?namespace=default
Here, know kubernetes-dashboard
is replaced by the namespace for my pods, and https
is replaced with whatever port name I have configured in a Service, but I am not sure about the rest.在这里,知道
kubernetes-dashboard
被我的 Pod 的命名空间替换,并且https
被替换为我在服务中配置的任何端口名称,但我不确定 rest。
You should define a Service with NodePort
type to access the service from the host machine.您应该定义一个具有
NodePort
类型的服务以从主机访问该服务。
Follow the reference --> https://kubernetes.io/docs/tasks/access-application-cluster/service-access-application-cluster/按照参考-> https://kubernetes.io/docs/tasks/access-application-cluster/service-access-application-cluster/
The kubernetes dashboard example that you are referring you are actually using kubectl proxy
or kubectl port forward
to access it.您所指的 kubernetes 仪表板示例实际上是在使用
kubectl proxy
或kubectl port forward
来访问它。 In this case Kubernetes API Server works as proxy and forwards the request to pod.在这种情况下 Kubernetes API 服务器充当代理并将请求转发到 pod。
You can just create a clusterIP type service and use the kubectl proxy
or kubectl port forward
mechanism to access it.您可以只创建一个 clusterIP 类型的服务并使用
kubectl proxy
或kubectl port forward
机制来访问它。 Here is a guide on this. 这是一个指南。
The service would look like below as an example该服务将如下所示作为示例
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 8080
targetPort: 8080
You could also use NodePort type service to expose the pod.您还可以使用 NodePort 类型的服务来公开 pod。 In this case you don't need to use
kubectl proxy
or kubectl port forward
在这种情况下,您不需要使用
kubectl proxy
或kubectl port forward
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
selector:
app: MyApp
ports:
# By default and for convenience, the `targetPort` is set to the same value as the `port` field.
- port: 80
targetPort: 8080
# Optional field
# By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
nodePort: 30007
You access it using http://<NODEIP>:30007
where <NODEIP>
is any of the kubernetes node's IP.您可以使用
http://<NODEIP>:30007
访问它,其中<NODEIP>
是 kubernetes 节点的 IP 中的任何一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.