Skip to main content

Posts

Showing posts from October, 2019

Setting up Helm chart for K8s cluster

Helm is a powerful and flexible package-management and operations tool for Kubernetes. There are two parts to Helm: The Helm client (helm) and the Helm server (Tiller). https://helm.sh/docs/using_helm/#installing-helm 1) ssh to your k8s master node 2) Download the helm client from the url : https://github.com/helm/helm/releases Linux amd64 (checksum) # wget https://get.helm.sh/helm-v2.15.1-linux-amd64.tar.gz # tar -xzvf helm-v2.15.1-linux-amd64.tar.gz # mv linux-amd64/helm /usr/local/bin # which helm # helm version --client --short 3) Now we need to initialize the helm server (Tiller) in the k8s cluster. For this,  > first we need to create a serviceaccount called tiller in the kube-system namespace.  > then create a clusterrolebinding called tiller and attach the clusterrole cluster-admin to the serviceaccount tiller.  # kubectl -n kube-system create serviceaccount tiller  # kubectl create clusterrolebinding tiller --clusterrole cluster-admin --service

How to Build and Deploy a Spring Boot Java application with Docker & Kubernetes

Pre-requisites: Install Docker client/server Install K8s cluster. In the K8s Master Node. git clone https://github.com/spring-guides/gs-spring-boot-docker cd gs-spring-boot-docker/complete ./mvnw install -e -X # This will create a .jar file in the newely created target directory. sudo docker build -t image-sb1 -f Dockerfile . sudo docker images sudo docker tag image-sb1 trow.kube-public:31000/myrepo # Tag the new image with your private registry (Optional) sudo docker push trow.kube-public:31000/myrepo  # Push the new image to your local private registry (Optional) kubectl run image-sb --image=trow.kube-public:31000/myrepo --port=8080 kubectl expose deployment/image-sb --type="NodePort" --port 8080 Testing: ---------------------------------------------------------------------- ubuntu@namenode:~$ kubectl get svc NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE kubernetes    ClusterIP   10.96.0.1                443/TCP   

Running K8s cluster service kubelet with Swap Memory Enabled

For enabling swap memory check the below link : https://jinojoseph.blogspot.com/2019/10/enable-swap-memory-using-swapfile-in.html # sudo vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf Add the KUBELET_EXTRA_ARGS line as below: ---------------------------------------- Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false" ExecStart= ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS Now kubelet.service changed on disk. Run 'systemctl daemon-reload' to reload units # sudo systemctl daemon-reload # sudo systemctl restart kubelet # sudo systemctl status kubelet That is all cheers :p

Enable Swap memory using swapfile in Ubuntu EC2 instance

Calculate the swap space size As a general rule, calculate swap space according to the following:  Amount of physical RAM Recommended swap space 2 GB of RAM or less 2x the amount of RAM but never less than 32 MB More than 2 GB of RAM but less than 32 GB 4 GB + (RAM – 2 GB) 32 GB of RAM or more 1x the amount of RAM Note:  Swap space should never be less than 32 MB. Create a swap file 1.    Use the  dd  command to create a swap file on the root file system, where "bs" is the block size and "count" is the number of blocks. In this example the swap file is 4 GB: $ sudo dd if=/dev/zero of=/swapfile bs=1G count=4 2.    Update the read and write permissions for the swap file:  $ sudo chmod 600 /swapfile 3.    Set up a Linux swap area:  $ sudo mkswap /swapfile 4.    Make the swap file available for immediate use by adding the swap file to swap space:  $ sudo swapon /swapfile 5.    Verify that the procedure wa

Setup Private Registry for K8s Cluster using Trow Script

Pre-requisites: K8S cluster setup and running. If you have not done this before, first check my post for setting the K8s cluster https://jinojoseph.blogspot.com/2019/10/installing-k8s-as-cluster-using-kubeadm.html Once you have done that what if you need to build and run your own image? You're going to need to push your image to a registry that is accessible to Kubernetes. The obvious option is to use the Docker Hub, but what if you want to keep your image private? The answer: run a registry inside the Kubernetes cluster itself. This way there's no need to worry about hidden costs or pushing to external resources. You can use the default Docker registry for this purpose, but to do this securely requires setting up TLS certificates and manual twiddling. A simpler option is to install the Trow registry via its install script, which will also take care of configuring TLS correctly. # git clone https://github.com/ContainerSolutions/trow.git # cd trow # ./insta

Controllers in K8s

CONTROLLERS Controllers are the brain behind the k8s. They are the processes that monitor the k8s objects and respond accordingly. Replication Controller: The replication controller helps us to run multiple instances of a single pod in a k8s cluster, thus providing High Availability. They can also replace a Single failed pod, thus provide HA even without multiple instance of PODs. It also helps in Load Balancing and Scaling. Another reason we need replicaiton controller is to create mulltiple pods and to share the load between them. At first it will increase the number of pods in the same node when demand increases, say when the user is increasing. After the node has reached its bottleneck , we will create additional pods in another new nodes. Thus the replication controller spans across multiple nodes in the cluster. Replication Controller Vs Replica Set: They both have the same purpose, but they are not the same. Replic

Mysql Master Master Replication & LoadBalancing using HaProxy

Requirements ############## Two server running Ubuntu 16.04. Static IP address 10.0.1.12 (dn1) configured on first master server. Static IP address 10.0.1.14 (dn2) configured on second master server. A non-root user with sudo privileges configure on both server. First, you will need to install mysql server and client on dn1 server. You can install it with the following command: # sudo apt-get install mysql-server mysql-client Next, you will need to make some changes in my.cnf file of First server as below: ---------------------------------------------------------------------------------- vi /etc/mysql/mysql.conf.d/mysqld.cnf server-id = 1 log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size   = 100M # service mysql restart Next, you will need to make some changes in my.cnf file of dn2 server as below: ---------------------------------------------------------------------------------- vi /etc/mysql/mysql.conf.d/mysqld.cnf server

INSTALLING K8S AS A CLUSTER USING KUBEADM

############################################################################# Step1: We need multiple systems or VM s created for configuring multinode cluster. Step2: Install container runtime engine (docker) on all the master and worker nodes. Step3: Install kubeadm ( Pronounced as kubeadmin) on all the master and worker nodes. Step4: Initialize the master server in the Master node. Step5: Make sure a POD Network connection is configured between master and worker nodes. Step6: Join the worker node to the master node. ############################################################################# UBUNTU ######### Docker Installation Commands: https://docs.docker.com/install/linux/docker-ce/ubuntu/ Execute the below commands in all the nodes: # apt-get update # sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common # curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # su