How to access pods without services in Kubernetes

后端 未结 4 1874
攒了一身酷
攒了一身酷 2021-01-02 12:20

I was wondering how pods are accessed when no service is defined for that specific pod. If it\'s through the environment variables, how does the cluster retrieve these?

相关标签:
4条回答
  • 2021-01-02 13:00
    • 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

    • you can access the endpoints or actual pod ports inside the cluster as well , but not outside

    • all of the above uses the kubernetes service discovery

    • There are two type of service dicovery though
    • Internal Service discovery
    • External Service Discovery.

    0 讨论(0)
  • 2021-01-02 13:02

    You cannot "access" a pods container port(s) without a service. Services are objects that define the desired state of an ultimate set of iptable rule(s).

    Also, services, like all other objects, are stored in etcd and maintained through your master(s).

    You could however manually create an iptable rule forwarding traffic to the local container port that docker has exposed.

    Hope this helps! If you still have any questions drop them here.

    0 讨论(0)
  • 2021-01-02 13:05
    • All cluster data is stored in etcd which is a distributed key-value store. If etcd goes down, cluster becomes unstable and no new pods can come up.

    • Kubernetes has a way to access any pod within the cluster. Service is a logical way to access a set of pods bound by a selector. An individual pod can still be accessed irrespective of the service. Further service can be created to access the pods from outside the cluster (NodePort service)

    0 讨论(0)
  • 2021-01-02 13:07

    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

    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
    
    0 讨论(0)
提交回复
热议问题