Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#应用程序无法访问kubernetes服务?_C#_Asp.net Core_Kubernetes - Fatal编程技术网

C#应用程序无法访问kubernetes服务?

C#应用程序无法访问kubernetes服务?,c#,asp.net-core,kubernetes,C#,Asp.net Core,Kubernetes,我似乎对我的C#应用程序有问题,我将其装箱并放入pod,似乎无法访问集群中的服务 我做了一个简单的代码示例 using System; using System.Net.NetworkInformation; namespace pingMe { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!");

我似乎对我的C#应用程序有问题,我将其装箱并放入pod,似乎无法访问集群中的服务

我做了一个简单的代码示例

using System;
using System.Net.NetworkInformation;

namespace pingMe
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Ping ping = new Ping();
            PingReply pingresult = ping.Send("example-service.default.svc");
            if (pingresult.Status.ToString() == "Success")
            {
                Console.WriteLine("I can reach");
            }
        }
    }
}
应该能够在群集中ping此

PS C:\Helm> kubectl apply -f https://k8s.io/examples/service/access/hello-application.yaml
deployment.apps/hello-world created
PS C:\Helm> kubectl expose deployment hello-world --type=ClusterIP --name=example-service
service/example-service exposed
PS C:\Helm> kubectl get service/example-service
NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
example-service   ClusterIP   10.97.171.216   <none>        8080/TCP   14s
PS C:\Helm> kubectl get deployment.apps/hello-world
NAME          READY   UP-TO-DATE   AVAILABLE   AGE
hello-world   2/2     2            2           61s

为什么。。。添加端口号没有任何帮助。

表面上看起来一切正常。我将通过排除可能性开始调试。从“worker”pod可以ping集群而不是服务名称吗?您能否成功地在任何服务或pod上执行DNS查找?如果您可以访问群集IP,但ping或解析服务名称仍然失败,那么DNS似乎更可疑

您试图命中的服务和您试图命中的服务是否都在同一集群内运行?如果您试图从集群外部访问一个在集群内运行的服务,您需要公开一个外部IP,并且通过它两者都在同一集群内……其他具有不同基础的POD可以解析主机名C#是否有可能拥有自己的DNS解析程序而不使用标准的resolv.conf配置?您的代码也会说
hello world service
,但您在示例中的命名是
example service
。我不确定dns解析程序,也不确定它为什么要将自身容器化那么多?
Hello World!
Unhandled exception. System.Net.NetworkInformation.PingException: An exception occurred during a Ping request.
 ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name or service not known
   at System.Net.Dns.InternalGetHostByName(String hostName)
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
   at System.Net.NetworkInformation.Ping.GetAddressAndSend(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
   --- End of inner exception stack trace ---
   at System.Net.NetworkInformation.Ping.GetAddressAndSend(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
   at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
   at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress)
   at pingMe.Program.Main(String[] args) in /src/pingMe/Program.cs:line 12