我在一个节点上有一个k0s Kubernetes集群。我正在尝试运行一个selenium/standalone-chrome来创建一个远程Selenium节点。我遇到的问题是,如果我从吊舱中转发4444,但似乎无法通过服务端口访问它,它就会做出响应。我被拒绝了。我不知道是不是因为忽略了非本地主机的连接。
Pod对pod/standalone-chrome的定义是:
apiVersion: v1
kind: Pod
metadata:
name: standalone-chrome
spec:
containers:
- name: standalone-chrome
image: selenium/standalone-chrome
ports:
- containerPort: 4444
env:
- name: JAVA_OPTS
value: '-Dwebdriver.chrome.whitelistedIps=""'我为service/standalone-chrome-service提供的service/standalone-chrome-service定义是:
apiVersion: v1
kind: Service
metadata:
name: standalone-chrome-service
labels:
app: standalone-chrome
spec:
ports:
- port: 4444
name: standalone-chrome
type: ClusterIP
selector:
app: standalone-chrome这将创建以下内容,以及用于测试连接性的busybox容器。
NAME READY STATUS RESTARTS AGE
pod/busybox1 1/1 Running 70 2d22h
pod/standalone-chrome 1/1 Running 0 3m15s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 18d
service/standalone-chrome-service ClusterIP 10.111.12.1 <none> 4444/TCP 3m5s我现在面临的问题是,我无法通过standalone-chrome-service访问远程Selenium服务。我被拒绝了。例如,这里试图通过busybox1容器来达到它:
$ wget http://standalone-chrome-service:4444
Connecting to standalone-chrome-service:4444 (10.111.12.1:4444)
wget: can't connect to remote host (10.111.12.1): Connection refused不过,我可以使用pod/standalone-chrome将其从kubectl port-forward转发到主机,并且工作正常,我认为这可以确认服务正在成功运行,但无法通过Service访问。
$ kubectl port-forward pod/standalone-chrome 4444:4444 &
Forwarding from 127.0.0.1:4444 -> 4444
Forwarding from [::1]:4444 -> 4444
$ wget http://localhost:4444
--2021-11-22 13:37:20-- http://localhost:4444/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:4444... connected.
...对于如何通过Service访问Selenium远程服务器,我将非常感激您的帮助。
编辑:这是使用name更新的服务定义.
apiVersion: v1
kind: Service
metadata:
name: standalone-chrome-service
labels:
app: standalone-chrome
spec:
ports:
- port: 4444
name: standalone-chrome
type: ClusterIP
selector:
name: standalone-chrome以下是“描述”的输出:
Name: standalone-chrome-service
Namespace: default
Labels: app=standalone-chrome
Annotations: <none>
Selector: name=standalone-chrome
Type: ClusterIP
IP Families: <none>
IP: 10.100.179.116
IPs: 10.100.179.116
Port: standalone-chrome 4444/TCP
TargetPort: 4444/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>发布于 2021-11-23 11:14:22
服务的语法有:
selector:
app: standalone-chrome是正确的,selector应该由label匹配。
服务使用标签和选择器匹配一组Pods,这是一个分组原语,允许对Kubernetes中的对象进行逻辑操作。标签是附加在对象上的键/值对。
有关更多细节,使用服务公开应用程序。
现在,您需要将这个label (即app: standalone-chrome)添加到pod.yaml元数据中:
apiVersion: v1
kind: Pod
metadata:
name: standalone-chrome
labels:
app: standalone-chrome # this label should match to selector in service
spec:
containers:
- name: standalone-chrome
image: selenium/standalone-chrome
ports:
- containerPort: 4444
env:
- name: JAVA_OPTS
value: '-Dwebdriver.chrome.whitelistedIps=""'https://stackoverflow.com/questions/70071293
复制相似问题