Pig Installation

  1. Download the latest version of Pig from Apache
    1
    2
    wget https://dlcdn.apache.org/pig/pig-0.17.0/pig-0.17.0.tar.gz
    tar xvzf pig-0.17.0.tar.gz
  1. Change the directory of pig-0.17.0 folder

    1
    2
    3
    sudo mkdir -p /usr/local/pig
    cd pig-0.17.0
    sudo mv * /usr/local/pig
  2. Create .bashrc file with following environment

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    vi .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
2
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Add kernel Parameters

1
2
3
4
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
1
2
sudo modprobe overlay
sudo modprobe br_netfilter
1
2
3
4
5
sudo tee /etc/sysctl.d/kubernetes.conf <<EOT
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
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
2
3
4
5
6
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install -y containerd.io
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
1
2
sudo systemctl restart containerd
sudo systemctl enable containerd

Install Docker

1
2
sudo apt update
sudo apt install ca-certificates curl
1
2
3
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
1
2
3
4
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
1
2
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
1
2
3
sudo docker run hello-world
sudo systemctl enable docker
sudo systemctl start docker

Install Kubernetes Package

1
2
3
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
1
2
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold 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
    3
    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Control-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
2
sudo kubeadm reset
rm -r $HOME/.kube

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
    2
    wget https://mobitec.ie.cuhk.edu.hk/ierg4330/static_files/assignments/hadoop.yaml
    kubectl create -f hadoop.yaml
  • Validation
    Check the distribution of the pods and containers, visit the Hadoop and Application Master UI via the IP of the instance which setup the hdfs-master pod.

    1
    kubectl get pods -o wide
  • Execution
    Submit the MapReduce jobs through the yarn-master pod.

    1
    2
    3
    4
    5
    6
    7
    kubectl 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