Kubernetes Cluster Setup
Pig Installation
- Download the latest version of Pig from Apache
1
2wget https://dlcdn.apache.org/pig/pig-0.17.0/pig-0.17.0.tar.gz
tar xvzf pig-0.17.0.tar.gz
Change the directory of pig-0.17.0 folder
1
2
3sudo mkdir -p /usr/local/pig
cd pig-0.17.0
sudo mv * /usr/local/pigCreate
.bashrcfile with following environment1
2
3
4
5
6
7
8
9
10vi .bashrc
export PIG_HOME=/usr/local/pig
export PATH=$PATH:$PIG_HOME/bin
export PIG_CLASSPATH=$PIG_HOME/conf:$HADOOP_INSTALL/etc/hadoop/bin
export PIG_CONF_DIR=$PIG_HOME/conf
export PIG_CLASSPATH=$PIG_CONF_DIR
# PIG VARIABLES END
source .bashrc
Multi-node Kubernetes Cluster
Disable Swap
The default behavior of a kubelet was to fail to start if swap memory was detected on a node. You MUST disable swap if the kubelet is not properly configured to use swap.1
2sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Add kernel Parameters
1 | sudo tee /etc/modules-load.d/containerd.conf <<EOF |
1 | sudo modprobe overlay |
1 | sudo tee /etc/sysctl.d/kubernetes.conf <<EOT |
1 | sudo sysctl --system |
Install Container
To set up Kubernetes Cluster, you must install the container runtime on all servers so that Pods can run. Multiple container runtimes can be used for Kubernetes deployments such as containerd, CRI-O, Mirantis Container Runtime, and Docker Engine (via cri-dockerd).
When it is used as a container runtime for Kubernetes, Docker is just a middle-man between Kubernetes and containerd. However, Kubernetes can use containerd directly as a container runtime, meaning Docker is no longer needed in this middle-man role.
So, to install containerd, first install its dependencies.
Install Containerd Runtime
1 | sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates |
1 | sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg |
1 | sudo systemctl restart containerd |
Install Docker
1 | sudo apt update |
1 | sudo install -m 0755 -d /etc/apt/keyrings |
1 | echo \ |
1 | sudo apt update |
1 | sudo docker run hello-world |
Install Kubernetes Package
1 | curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg |
1 | sudo apt install -y kubelet kubeadm kubectl |
Install Kubernetes Cluster
Initialize Control-plane Node
Initialize Control-plane Node
Execute the following command to initialize the control-plane node in the master node that we treat it as control-plane node. Run the following command on the master node.1
sudo kubeadm init --control-plane-endpoint=<node-name>
Start interacting with cluster
Run following commands on the control-plane node (master node):1
2
3mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/configControl-plane Node Isolation
By default, the cluster will not schedule Pods on the control plane nodes for security reasons. If you want to be able to schedule Pods on the control plane nodes, for example for a single machine Kubernetes cluster, run:1
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
Join Worker Nodes
Run following commands on the worker nodes:
1 | kubeadm join --token <token> <control-plane-host>:<control-plane-port> --discovery-token-ca-cert-hash sha256:<hash> |
Reset the Cluster
Execute the following command on all nodes to reset the node and remove the folder
1 | sudo kubeadm reset |
Install Calico Network Plugin
A network plugin is required to enable communication between pods in the cluster. Run following kubectl command to install Calico network plugin from the master node
1 | kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.0/manifests/calico.yaml |
1 | kubectl get pods -n kube-system |
Deploy Hadoop
Deployment
Deploy the hadoop using the yaml script.1
2wget https://mobitec.ie.cuhk.edu.hk/ierg4330/static_files/assignments/hadoop.yaml
kubectl create -f hadoop.yamlValidation
Check the distribution of the pods and containers, visit the Hadoop and Application Master UI via the IP of the instance which setup thehdfs-masterpod.1
kubectl get pods -o wide
Execution
Submit the MapReduce jobs through theyarn-masterpod.1
2
3
4
5
6
7kubectl exec -it yarn-master -- /bin/bash
# Teragen
hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar teragen 20000000 /user/hadoop/input2
# Terasort
hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar terasort /user/hadoop/input2 /user/hadoop/output_fault
Deletion
Delete all pods, services and deployments.1
kubectl delete -f hadoop.yaml
cd $SPARK_HOME
spark-submit \
—master k8s://https://vm-1:6443 \
—deploy-mode cluster \
—name spark-pi \
—class org.apache.spark.examples.SparkPi \
—conf spark.executor.instances=5 \
—conf spark.kubernetes.namespace=spark \
—conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \
—conf spark.kubernetes.container.image=manholam8/spark:3.5.1-hadoop3 \
local:///opt/spark/examples/jars/spark-examples_2.12-3.5.1.jar
$SPARK_HOME/bin/docker-image-tool.sh -r myharbor.com/bigdata -t 3.5.1-hadoop3 build build
$SPARK_HOME/bin/docker-image-tool.sh -r myharbor.com/bigdata -t 3.5.1-hadoop3 push
sudo $SPARK_HOME/bin/docker-image-tool.sh -r my-spark-exmaple -t 3.5.1 build
val sparkConf = new SparkConf()
.setAppName(“MySparkApp”)
.setMaster(“k8s://https://vm-1:6443“)
.set(“spark.kubernetes.container.image”, “manholam8/spark:3.5.1”)
.set(“spark.executor.instances”, “2”)
.set(“spark.executor.memory”, “2g”)
.set(“spark.executor.cores”, “1”)
spark-submit \
—master k8s://https://vm-1:6443 \
—deploy-mode cluster \
—name spark-pi \
—class org.apache.spark.examples.SparkPi \
—conf spark.executor.instances=5 \
—conf spark.kubernetes.namespace=spark \
—conf spark.kubernetes.authenticate.driver.serviceAccountName=spark \
—conf spark.kubernetes.container.image=manholam8/spark:3.5.1 \
local:///opt/spark/examples/jars/spark-examples_2.12-3.5.1.jar

