在已安装卷的kubernetes中启动RStudio

时间:2018-11-23 19:01:16

标签: docker kubernetes rstudio

我尝试通过kubernetes在docker容器中启动RStudio。所有对象均已创建,但是当我尝试在Ubuntu 18中使用此类命令打开rstudio时:

kubectl create -f rstudio-ing.yml    
IP=$(minikube ip)
xdg-open http://$IP/rstudio/

有错误:#RStudio initialization error: unable connect to service

通常的docker命令可以正常工作:

docker run -d -p 8787:8787 -e PASSWORD=123 -v /home/aabor/r-projects:/home/rstudio aabor/rstudio

kubernetes中相同的预期操作失败。

rstudio-ing.yml文件可以很好地创建所有对象。如果我没有安装任何文件夹,则可以访问RStudio。但是,如果我添加文件夹安装,则会产生错误。有什么建议吗?

rstudio-ing.yml的内容:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: r-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /rstudio/
        backend:
          serviceName: rstudio
          servicePort: 8787

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rstudio
spec:
  replicas: 1
  selector:
    matchLabels:
      service: rstudio
  template:
    metadata:
      labels:
        service: rstudio
        language: R
    spec:
      containers:
      - name: rstudio
        image: aabor/rstudio
        env:
        - name: PASSWORD
          value: "123"
        volumeMounts:
        - name: home-dir
          mountPath: /home/rstudio/
      volumes: 
      - name: home-dir
        hostPath: 
        #RStudio initialization error: unable connect to service
          path: /home/aabor/r-projects 

---

apiVersion: v1
kind: Service
metadata:
  name: rstudio
spec:
  ports:
  - port: 8787
  selector:
    service: rstudio

这是广告连播说明:

    Name:           rstudio-689c4fd6c8-fgt7w
    Namespace:      default
    Node:           minikube/10.0.2.15
    Start Time:     Fri, 23 Nov 2018 21:42:35 +0300
    Labels:         language=R
                    pod-template-hash=2457098274
                    service=rstudio
    Annotations:    <none>
    Status:         Running
    IP:             172.17.0.9
    Controlled By:  ReplicaSet/rstudio-689c4fd6c8
    Containers:
    rstudio:
        Container ID:   docker://a6bdcbfdf8dc5489a4c1fa6f23fb782bc3d58dd75d50823cd370c43bd3bffa3c
        Image:          aabor/rstudio
        Image ID:       docker-pullable://aabor/rstudio@sha256:2326e5daa3c4293da2909f7e8fd15fdcab88b4eb54f891b4a3cb536395e5572f
        Port:           <none>
        Host Port:      <none>
        State:          Running
        Started:      Fri, 23 Nov 2018 21:42:39 +0300
        Ready:          True
        Restart Count:  0
        Environment:
        PASSWORD:  123
        Mounts:
        /home/rstudio/ from home-dir (rw)
        /var/run/secrets/kubernetes.io/serviceaccount from default-token-mrkd8 (ro)
    Conditions:
    Type           Status
    Initialized    True 
    Ready          True 
    PodScheduled   True 
    Volumes:
    home-dir:
        Type:          HostPath (bare host directory volume)
        Path:          /home/aabor/r-projects
        HostPathType:  
    default-token-mrkd8:
        Type:        Secret (a volume populated by a Secret)
        SecretName:  default-token-mrkd8
        Optional:    false
    QoS Class:       BestEffort
    Node-Selectors:  <none>
    Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                    node.kubernetes.io/unreachable:NoExecute for 300s
    Events:
    Type    Reason                 Age   From               Message
    ----    ------                 ----  ----               -------
    Normal  Scheduled              10s   default-scheduler  Successfully assigned rstudio-689c4fd6c8-fgt7w to minikube
    Normal  SuccessfulMountVolume  10s   kubelet, minikube  MountVolume.SetUp succeeded for volume "home-dir"
    Normal  SuccessfulMountVolume  10s   kubelet, minikube  MountVolume.SetUp succeeded for volume "default-token-mrkd8"
    Normal  Pulling                9s    kubelet, minikube  pulling image "aabor/rstudio"
    Normal  Pulled                 7s    kubelet, minikube  Successfully pulled image "aabor/rstudio"
    Normal  Created                7s    kubelet, minikube  Created container
    Normal  Started                6s    kubelet, minikube  Started container

1 个答案:

答案 0 :(得分:1)

您已经创建了ClusterIP类型的服务,该服务只能在群集中访问,而不能在外部访问。因此,要使其在集群外部可用,请更改服务类型LoadBalancer

apiVersion: v1
kind: Service
metadata:
  name: rstudio
spec:
  ports:
  - port: 8787
  selector:
    service: rstudio
  type: LoadBalancer

在这种情况下,loadbalancer类型的服务不需要入口并将URL用作:

$ minikube service rstudio --url