如何配置kubernetes硒容器到达外网?

时间:2017-12-02 06:11:26

标签: selenium kubernetes minikube

我通过windows minikube尝试了selenium的例子。 https://github.com/kubernetes/kubernetes/tree/master/examples/selenium

在容器内部,我无法安装硒,我该怎么办?

pip install selenium

CMD:

kubectl run selenium-hub --image selenium/hub:2.53.1 --port 4444
kubectl expose deployment selenium-hub --type=NodePort
kubectl run selenium-node-chrome --image selenium/node-chrome:2.53.1 --env="HUB_PORT_4444_TCP_ADDR=selenium-hub" --env="HUB_PORT_4444_TCP_PORT=4444"
kubectl scale deployment selenium-node-chrome --replicas=4
kubectl run selenium-python --image=google/python-hello  
kubectl exec --stdin=true --tty=true selenium-python-6479976d89-ww7jv  bash

显示:

PS C:\Program Files\Docker Toolbox\dockerfiles> kubectl get pods
NAME                                    READY     STATUS    RESTARTS   AGE
selenium-hub-5ffc6ff7db-gwq95           1/1       Running   0          15m
selenium-node-chrome-8659b47488-brwb4   1/1       Running   0          8m
selenium-node-chrome-8659b47488-dnrwr   1/1       Running   0          8m
selenium-node-chrome-8659b47488-hwvvk   1/1       Running   0          11m
selenium-node-chrome-8659b47488-t8g59   1/1       Running   0          8m
selenium-python-6479976d89-ww7jv        1/1       Running   0          6m
PS C:\Program Files\Docker Toolbox\dockerfiles>  kubectl get services
NAME           TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
kubernetes     ClusterIP   10.0.0.1     <none>        443/TCP          17m
selenium-hub   NodePort    10.0.0.230   <none>        4444:32469/TCP   16m
PS C:\Program Files\Docker Toolbox\dockerfiles> kubectl exec --stdin=true --tty=true selenium-python-6479976d89-ww7jv  bash
root@selenium-python-6479976d89-ww7jv:/app# ping yahoo.com
ping: unknown host yahoo.com

2 个答案:

答案 0 :(得分:0)

看起来您的pod无法解析DNS。您需要测试您的群集是否在kube-system命名空间中具有正常工作的kube-dns。如果它存在且可操作,请在pod IP直接调用时检查它是否正确解析名称,并在启动时验证您的容器在/etc/resolv.conf中是否具有正确的内容

答案 1 :(得分:0)

您可以通过提供ConfigMap为自定义DNS配置kube-dns来避免此问题。

apiVersion: v1
kind: ConfigMap
metadata:
name: kube-dns
namespace: kube-system
data:
 stubDomains: |
  {"acme.local": ["1.2.3.4"]}
 upstreamNameservers: |
  ["8.8.8.8"]

See more details at Kubernetes Reference Doc