text stringlengths 0 59.1k |
|---|
NAME READY STATUS RESTARTS AGE |
zeppelin-controller-ja09s 1/1 Running 0 53s |
``` |
## Step Five: Do something with the cluster |
Now you have two choices, depending on your predilections. You can do something |
graphical with the Spark cluster, or you can stay in the CLI. |
For both choices, we will be working with this Python snippet: |
```python |
from math import sqrt; from itertools import count, islice |
def isprime(n): |
return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1))) |
nums = sc.parallelize(xrange(10000000)) |
print nums.filter(isprime).count() |
``` |
### Do something fast with pyspark! |
Simply copy and paste the python snippet into pyspark from within the zeppelin pod: |
```console |
$ kubectl exec zeppelin-controller-ja09s -it pyspark |
Python 2.7.9 (default, Mar 1 2015, 12:57:24) |
[GCC 4.9.2] on linux2 |
Type "help", "copyright", "credits" or "license" for more information. |
Welcome to |
____ __ |
/ __/__ ___ _____/ /__ |
_\ \/ _ \/ _ `/ __/ '_/ |
/__ / .__/\_,_/_/ /_/\_\ version 1.5.1 |
/_/ |
Using Python version 2.7.9 (default, Mar 1 2015 12:57:24) |
SparkContext available as sc, HiveContext available as sqlContext. |
>>> from math import sqrt; from itertools import count, islice |
>>> |
>>> def isprime(n): |
... return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1))) |
... |
>>> nums = sc.parallelize(xrange(10000000)) |
>>> print nums.filter(isprime).count() |
664579 |
``` |
Congratulations, you now know how many prime numbers there are within the first 10 million numbers! |
### Do something graphical and shiny! |
Creating the Zeppelin service should have yielded you a Loadbalancer endpoint: |
```console |
$ kubectl get svc zeppelin -o wide |
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR |
zeppelin 10.0.154.1 a596f143884da11e6839506c114532b5-121893930.us-east-1.elb.amazonaws.com 80/TCP 3m component=zeppelin |
``` |
If your Kubernetes cluster does not have a Loadbalancer integration, then we will have to use port forwarding. |
Take the Zeppelin pod from before and port-forward the WebUI port: |
```console |
kubectl port-forward zeppelin-controller-ja09s 8080:8080 |
``` |
This forwards `localhost` 8080 to container port 8080. You can then find |
Zeppelin at [http://localhost:8080/](http://localhost:8080/). |
Once you've loaded up the Zeppelin UI, create a "New Notebook". In there we will paste our python snippet, but we need to add a `%pyspark` hint for Zeppelin to understand it: |
``` |
%pyspark |
from math import sqrt; from itertools import count, islice |
def isprime(n): |
return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1))) |
nums = sc.parallelize(xrange(10000000)) |
print nums.filter(isprime).count() |
``` |
After pasting in our code, press shift+enter or click the play icon to the right of our snippet. The Spark job will run and once again we'll have our result! |
## Result |
You now have services and replication controllers for the Spark master, Spark |
workers and Spark driver. You can take this example to the next step and start |
using the Apache Spark cluster you just created, see |
[Spark documentation](https://spark.apache.org/documentation.html) for more |
information. |
## tl;dr |
```console |
kubectl create ns spark-cluster |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.