gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:29:14 25 4
gpt4 key购买 nike

我的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

但是在集群中我得到这个:
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

怎么...添加端口号无济于事。

最佳答案

从表面上看,一切正常。我将通过消除可能性开始调试。您可以从“工作人员” Pane 中ping ClusterIP而不是服务名称吗?您可以在任何服务或Pod上成功进行DNS查找吗?如果您可以访问群集IP,但是ping或解析服务名称仍然失败,则DNS似乎更可疑。

关于c# - C#应用程序无法访问kubernetes服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60157620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com