简体   繁体   English

如何在Kubernetes中访问没有服务的pod

[英]How to access pods without services in Kubernetes

I was wondering how pods are accessed when no service is defined for that specific pod. 我想知道在没有为该特定pod定义服务时如何访问pod。 If it's through the environment variables, how does the cluster retrieve these? 如果是通过环境变量,群集如何检索这些?

Also, when services are defined, where on the master node is it stored? 此外,在定义服务时,主节点上的存储位置是什么?

Kind regards, Charles 亲切的问候,查尔斯

  • If you define a service for your app , you can access it outside the cluster using that service 如果为应用程序定义服务,则可以使用该服务在群集外部访问它

  • Services are of several types , including nodePort , where you can access that port on any cluster node and you will have access to the service regardless of the actual location of the pod 服务有多种类型,包括nodePort,您可以在任何群集节点上访问该端口,无论Pod的实际位置如何,您都可以访问该服务

  • you can access the endpoints or actual pod ports inside the cluster as well , but not outside 您也可以访问群集内的端点或实际pod端口,但不能访问外部端点

  • all of the above uses the kubernetes service discovery 以上所有都使用kubernetes服务发现

  • There are two type of service dicovery though 虽然有两种类型的服务dicovery
  • Internal Service discovery 内部服务发现
  • External Service Discovery. 外部服务发现。

在此输入图像描述

You cannot "access" a pods container port(s) without a service. 没有服务,您无法“访问”pods容器端口。 Services are objects that define the desired state of an ultimate set of iptable rule(s). 服务是定义最终iptable规则集的期望状态的对象。

Also, services, like all other objects, are stored in etcd and maintained through your master(s). 此外,服务与所有其他对象一样,存储在etcd中并通过主服务器进行维护。

You could however manually create an iptable rule forwarding traffic to the local container port that docker has exposed. 但是,您可以手动创建iptable规则,将流量转发到docker已公开的本地容器端口。

Hope this helps! 希望这可以帮助! If you still have any questions drop them here. 如果你还有任何问题请放在这里。

  • All cluster data is stored in etcd which is a distributed key-value store. 所有集群数据都存储在etcd中,这是一个分布式键值存储。 If etcd goes down, cluster becomes unstable and no new pods can come up. 如果etcd发生故障,群集将变得不稳定,并且不会出现新的pod。

  • Kubernetes has a way to access any pod within the cluster. Kubernetes有一种方法可以访问群集中的任何pod。 Service is a logical way to access a set of pods bound by a selector. 服务是访问由选择器绑定的一组pod的合理方式。 An individual pod can still be accessed irrespective of the service. 无论服务如何,仍然可以访问单个pod。 Further service can be created to access the pods from outside the cluster (NodePort service) 可以创建更多服务以从群集外部访问pod(NodePort服务)

Just for debugging purposes, you can forward a port from your machine to one in the pod: 仅用于调试目的,您可以将机器中的端口转发到容器中的端口:

kubectl port-forward POD_NAME HOST_PORT:POD_PORT

If you have to access it from anywhere, you should use services, but you got to have a deployment created 如果您必须从任何地方访问它,您应该使用服务,但您必须创建部署

Create deployment 创建部署

kubectl create -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/service/networking/run-my-nginx.yaml

Expose the deployment with a NodePort service 使用NodePort服务公开部署

kubectl expose deployment deployment/my-nginx --type=NodePort --name=nginx-service

Then list the services and get the port of the service 然后列出服务并获取服务的端口

kubectl get services | grep nginx-service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM