我使用以下配置在Kubernetes中创建了复制控制器:
{
"kind":"ReplicationController",
"apiVersion":"v1",
"metadata":{
"name":"guestbook",
"labels":{
"app":"guestbook"
}
},
"spec":{
"replicas":1,
"selector":{
"app":"guestbook"
},
"template":{
"metadata":{
"labels":{
"app":"guestbook"
}
},
"spec":{
"containers":[
{
"name":"guestbook",
"image":"username/fsharp-microservice:v1",
"ports":[
{
"name":"http-server",
"containerPort":3000
}
],
"command": ["fsharpi", "/home/SuaveServer.fsx"]
}
]
}
}
}
}
端口3000上运行的服务代码基本上是这样的:
#r "Suave.dll"
#r "Mono.Posix.dll"
open Suave
open Suave.Http
open Suave.Successful
open System
open System.Net
open System.Threading
open System.Diagnostics
open Mono.Unix
open Mono.Unix.Native
let app = OK "PONG"
let port = 3000us
let config =
{ defaultConfig with
bindings = [ HttpBinding.mk HTTP IPAddress.Loopback port ]
bufferSize = 8192
maxOps = 10000
}
open System.Text.RegularExpressions
let cts = new CancellationTokenSource()
let listening, server = startWebServerAsync config app
Async.Start(server, cts.Token)
Console.WriteLine("Server should be started at this point")
Console.ReadLine()
创建服务后,我可以看到pod:
$kubectl create -f guestbook.json
replicationcontroller "guestbook" created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
guestbook-0b9py 1/1 Running 0 32m
我想访问我的Web服务并使用type = LoadBalancer创建服务,该服务将使用以下配置公开3000端口:
{
"kind":"Service",
"apiVersion":"v1",
"metadata":{
"name":"guestbook",
"labels":{
"app":"guestbook"
}
},
"spec":{
"ports": [
{
"port":3000,
"targetPort":"http-server"
}
],
"selector":{
"app":"guestbook"
},
"type": "LoadBalancer"
}
}
结果如下:
$ kubectl create -f guestbook-service.json
service "guestbook" created
$ kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
guestbook 10.0.82.40 3000/TCP 7s
kubernetes 10.0.0.1 <none> 443/TCP 3h
$ kubectl describe services
Name: guestbook
Namespace: default
Labels: app=guestbook
Selector: app=guestbook
Type: LoadBalancer
IP: 10.0.82.40
LoadBalancer Ingress: a43eee4a008cf11e68f210a4fa30c03e-1918213320.us-west-2.elb.amazonaws.com
Port: <unset> 3000/TCP
NodePort: <unset> 30877/TCP
Endpoints: 10.244.1.6:3000
Session Affinity: None
Events:
FirstSeen LastSeen Count From SubobjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
18s 18s 1 {service-controller } Normal CreatingLoadBalancer Creating load balancer
17s 17s 1 {service-controller } Normal CreatedLoadBalancer Created load balancer
Name: kubernetes
Namespace: default
Labels: component=apiserver,provider=kubernetes
Selector: <none>
Type: ClusterIP
IP: 10.0.0.1
Port: https 443/TCP
Endpoints: 172.20.0.9:443
Session Affinity: None
No events.
“外部IP”列为空
我尝试使用“LoadBalancer Ingress”访问该服务,但无法解析DNS名称。
如果我签入AWS控制台 - 会创建负载均衡器(但在详细信息面板中,由于运行状况检查,会出现“服务中有2个实例中的0个”消息。)
我还尝试使用kubectl expose --type = Load-Balancer公开我的RC,但结果是一样的。
有什么问题?
答案 0 :(得分:4)
我修正了错误。
事情是在实际的服务中。它需要监听0.0.0.0而不是127.0.0.1或localhost。这样它就会监听每个可用的网络接口。有关0.0.0.0和127.0.0.1之间差异的更多详细信息:https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1