Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run PaddleCloud on minikube. #463

Merged
merged 12 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ English tutorials(comming soon...)
using [Sextant](https://github.com/k8sp/sextant) or any tool you like.


### Run on minikube
Please see [here](https://github.com/PaddlePaddle/cloud/blob/develop/doc/run_on_minikube.md)

### Run on kubernetes
- Build Paddle Cloud Docker Image

Expand Down
113 changes: 113 additions & 0 deletions doc/run_on_minikube.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Run PaddleCloud on your local machine

This documentation shows how to run PaddleCloud on minikube.
(This surports only mac now.On unbuntu-16.04,we met a bug of kubernetes when we use `hostpath` to volume a file.)
Copy link

@putcn putcn Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Currently, This guide works with Mac OS only. On Ubuntu 16.04, the bug for Kubernetes to mount a single file with hostpath is a show stopper"
also, do we have a link for this bug in kubernetes repo?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubernetes/kubernetes#44815 (comment)
can this help solve the issue?

Copy link
Collaborator Author

@gongweibao gongweibao Nov 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will test it later.
Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's amazing to find that we can volume a file on Linux now!


## Prerequisites

- [install minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/)
- [install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)

1. Start a local minikube cluster:

```bash
minikube start --kubernetes-version v1.6.4
```

If you can't connect to minikube distribution server,add https_proxy like that:

```bash
https_proxy=<your's> minikube start --kubernetes-version v1.6.4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.

```
1. Enable ingress addon:

```
minikube addons enable ingress
```

1. Create workspace directory:

```
mkdir <yourpath>
```
Minikube mount `$Home` path default,and you'd better to create path under it or you may find that it can't be changed in minikube virtual mathine or in kubertes pod.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Minikube mounts $Home path by default, we recommend creating the path under $Home which offers the flexibility of switching between directories in your deployment without stopping the MiniKube and mounting another one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.


1. Copy `ca` and generate `admin` certificate:
(We must use `ca` under `~/.minikube` instead of under `~/.minikube/certs`.)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must use ca under ~/.minikube rather than ~/.minikube/certs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.


```
mkdir <yourpath>/certs && cd <yourpath>/certs
openssl genrsa -out admin-key.pem 2048
openssl req -new -key admin-key.pem -out admin.csr -subj "/CN=kube-admin"
openssl x509 -req -in admin.csr -CA ~/.minikube/ca.crt -CAkey ~/.minikube/ca.key \
-CAcreateserial -out admin.pem -days 365
cp ~/.minikube/ca.crt .
cp ~/.minikube/ca.key .
```

1. Copy and configure paddlecloud configures:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy and update paddlecloud configurations:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.


```
git clone https://github.com/PaddlePaddle/cloud
cp cloud/k8s/minikube/* <yourpath>/
sed -i'.bak' -e "s#<yourpath>#yourpath#g" <yourpath>/*.yaml
```

1. Edit `/etc/hosts` and add `$(minikube ip) cloud.testpcloud.org` to it.
1. Start all jobs:

```
kubectl create -f cloud_ingress.yaml
kubectl create -f cloud_service.yaml
kubectl create -f mysql_deployment.yaml
kubectl create -f mysql_service.yaml
kubectl create -f pfs_deployment.yaml
kubectl create -f pfs_service.yaml
kubectl create -f cloud_deployment.yaml
```
1. Type `$(minikube ip)` into browser,and sign up a user.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open cloud.testpcloud.org in your browser and sign up a user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.

1. Edit `~/.paddle/config` like this:

```
datacenters:
- name: testpcloud
username: g1@163.com
password: 1
endpoint: http://cloud.testpcloud.org
current-datacenter: testpcloud
```

You can use PaddleCloud command line now.


## FAQ
1. We can't get anything when we type `$(minikube ip)` into browser.
You can use `minikube get po --all-namespaces` to check it,it should like:
Copy link

@putcn putcn Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible cause is: default-http-backend is not ready yet. Run minikube get po --all-namespaces to check its status.
If it's stuck at pulling the image, one alternative is to manually download the image and load it with minikube's docker.

  • run kubectrl describe po name --namespace=kube-system to get docker image uri.
  • docker save <docker-image-uri> > <tarname>.tar to save the image to a tar file. You may need to use proxy with this step
  • 'minikube ssh' to login to Minikube's command line
  • docker load < <tarname>.tar to load the image to Kubenetes' local docker image repo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.


```
NAMESPACE NAME READY STATUS RESTARTS AGE
default paddle-cloud-3328278932-pqtf0 1/1 Running 5 3h
default paddle-cloud-mysql-2598050360-rdzpr 1/1 Running 4 3h
g1-163-com cloud-notebook-deployment-2982752518-6gr0m 0/1 Pending 0 3h
kube-system default-http-backend-cwqd4 1/1 Running 4 4h
kube-system kube-addon-manager-minikube 1/1 Running 4 4h
kube-system kube-dns-4149932207-0clkw 3/3 Running 12 4h
kube-system kubernetes-dashboard-tqrd7 1/1 Running 4 4h
kube-system nginx-ingress-controller-gxgl8 1/1 Running 4 4h
```

But docker images such as `default-http-backend` can't be downloaded sometimes , you can use

- `kubectrl describe po name --namespace=kube-system` to get docker image uri.
- and then pull with proxy and then save to tar `docker save <docker-image-uri> > <tarname>.tar`.
- `minikube ssh`.
- `docker load < <tarname>.tar`.

1. I edit a file,but it not change in minikube virtual machine some times.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indention issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited a file in host file system, but it remained unchanged in Minikube virtual machine sometimes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.

Ye, it seems that minikube has a cache of files.You'd better `minikube stop` `minikube start --kubernetes-version v1.6.4` to fix it.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be due to the files cache mechanism of Minikube. You can try to restart the Minikube with minikube stop minikube start --kubernetes-version v1.6.4 to fix it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.


## TODO
1. The `mysql` docker runs `mysqld` under user `mysql` instead of `root`,so it's difficult to save `mysql` data to hostpath.
1. Fix bug: `kubernetes can't mount a file use host to volume a file` on linux.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kubernetes can't mount the volume with hostpath to a single file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done.



38 changes: 38 additions & 0 deletions k8s/minikube/cloud_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: paddle-cloud
spec:
replicas: 1
template:
metadata:
labels:
app: paddle-cloud
spec:
volumes:
- name: cert-volume
hostPath:
path: <yourpath>/certs
- name: settings
hostPath:
path: <yourpath>/settings.py
containers:
- name: paddle-cloud
imagePullPolicy: IfNotPresent
image: paddlepaddle/cloud
volumeMounts:
- name: cert-volume
mountPath: /certs
- name: settings
mountPath: /pcloud/paddlecloud/settings.py
ports:
- containerPort: 8000
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: PORT
value: "8000"
nodeSelector:
kubernetes.io/hostname: minikube
18 changes: 18 additions & 0 deletions k8s/minikube/cloud_ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: paddle-cloud-ingress
spec:
rules:
- host: cloud.testpcloud.org
http:
paths:
- path: /api/v1/pfs
backend:
serviceName: pfs-service
servicePort: 8080
- path: /
backend:
serviceName: paddle-cloud-service
servicePort: 8000

11 changes: 11 additions & 0 deletions k8s/minikube/cloud_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Service
apiVersion: v1
metadata:
name: paddle-cloud-service
spec:
selector:
app: paddle-cloud
ports:
- protocol: TCP
port: 8000
targetPort: 8000
30 changes: 30 additions & 0 deletions k8s/minikube/mysql_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: paddle-cloud-mysql
spec:
replicas: 1
template:
metadata:
labels:
app: paddle-cloud-mysql
spec:
volumes:
- name: mysql-data
hostPath:
path: "<yourpath>/mysql"
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
#volumeMounts:
#- name: mysql-data
#mountPath: /var/lib/mysql2
env:
- name: MYSQL_ROOT_PASSWORD
value: root
- name: MYSQL_DATABASE
value: paddlecloud
args: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
nodeSelector:
kubernetes.io/hostname: minikube
11 changes: 11 additions & 0 deletions k8s/minikube/mysql_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Service
apiVersion: v1
metadata:
name: paddle-cloud-mysql-service
spec:
selector:
app: paddle-cloud-mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
36 changes: 36 additions & 0 deletions k8s/minikube/pfs_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: pfsserver
spec:
replicas: 1
template:
metadata:
labels:
app: pfsserver
spec:
volumes:
- name: public-data-storage
hostPath:
path: "<yourpath>/public"
- name: data-storage
hostPath:
path: "<yourpath>/users"
containers:
- name: pfs
imagePullPolicy: IfNotPresent
image: paddlepaddle/pfsserver:latest
env:
- name: CURRENT_DATACENTER
value: "datacenter"
command: ["/pfsserver/pfsserver", "-tokenuri", "http://paddle-cloud-service:8000", "-logtostderr=true", "-log_dir=./log", "-v=4"]
volumeMounts:
- name: data-storage
mountPath: /pfs/datacenter/home
- name: public-data-storage
mountPath: /pfs/datacenter/public/dataset
ports:
- containerPort: 8080
nodeSelector:
kubernetes.io/hostname: minikube

12 changes: 12 additions & 0 deletions k8s/minikube/pfs_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: Service
apiVersion: v1
metadata:
name: pfs-service
spec:
selector:
app: pfsserver
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: NodePort
Loading