Tuesday, February 8, 2022

Bitnami Charts: Tomcat

Install Kapp 

 wget -O- https://carvel.dev/install.sh | bash

Clone the Bitnami Charts

git clone https://github.com/bitnami/charts.git

Add Bitnami repo

helm repo add bitnami https://charts.bitnami.com/bitnami

Verfiy the Repo

helm repo list

Install Helm

helm install caljenkins bitnami/jenkins (here caltomcat is a name and bitnami/tomcat is a location)

Display output:

** Please be patient while the chart is being deployed **

 1. Get the Tomcat URL by running:

 ** Please ensure an external IP is associated to the myapache service before proceeding **

** Watch the status using: kubectl get svc --namespace default -w caltomcat **

   export SERVICE_IP=$(kubectl get svc --namespace default tomcat --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")

  echo URL : http://$SERVICE_IP/

 WARNING: You did not provide a custom web application. Tomcat will be deployed with a default page. Check the README section

 "Deploying your custom web application" in https://github.com/bitnami/charts/blob/master/bitnami/apache/README.md#deploying-your-custom-web-application.

kubectl get svc --namespace default -w caltomcat


access the External Ip in the Browser



To decode the password use the below commands. 

kubectl get secret --namespace default caltomcat -o jsonpath="{.data.tomcat-password}" | base64 --decode

echo Password: $(kubectl get secret --namespace default caltomcat -o jsonpath="{.data.tomcat-password}" | base64 --decode)

Convert the helm template to Ytt template

helm template bitnami/tomcat> tomcatytt.yaml

Install Kapp if it is uninstalled 


>:/ ytt version

Open & Edit the tomcatytt.yaml and remove the commented # line

>:/ vi tomcatytt.yaml

Now change RELEASE-NAME/release-name into small letters and save it

%s/RELEASE-NAME/release-name

Deploy the tomcatytt.yml file

ytt template -f tomcatytt.yml | kapp deploy -a tomcatapp -f- --yes

Verify

kapp ls
kubectl get all







Wednesday, February 2, 2022

Covert helm to ytt template

Prerequisite:

K8s Cluster in GCP or AWS

Steps:

1) Create a yaml file for deployment, pod, replicaset, service in the format of .yml 

2) Run the below command

            kubectl create -f pod.yml

            kubectl create -f replicaset.yml

            kubectl create -f deployment.yml

            kubectl create -f service.yml

pod.yml

apiVersion: v1

kind: Pod

metadata:

  name: myapp-pod

  labels:

    app: myapp

spec:

  containers:

    - name: nginx-image

      image: nginx

replicaset.yml

apiVersion: apps/v1

kind: ReplicaSet

metadata:

  name: myapp-replicaset

  labels:

    app: myapp

    type: front-end

spec:

  template:

    metadata:

      name: myapp-pod

      labels:

        app: myapp

    spec:

      containers:

        - name: nginx-image

          image: nginx

  replicas: 3

  selector:

    matchLabels:

      app: myapp

Service.yml

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
  
spec:
  type: NodePort
  ports:
    - targetPort: 80
      port: 80
      nodePort: 30008
  selector:
    app: myapp

output: 

deployment.yml   

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-replicaset
  labels:
    app: myapp
    type: front-end

spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp

    spec:
      containers:
        - name: nginx-image
          image: nginx

  replicas: 3
  selector:
    matchLabels:
      app: myapp

output: 

3) Verify the pods and cluster, service

            kubectl get all

            kubectl get nodes -o wide 

4)  Install Helm 

             curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3

5) Create a Directory Helm and create a chart. 

            :>/ mkdir Helm

helm:>/helm create demochart

helm:>/ cd demochart

helm/demochart:>/ ls


6) remove the below files inside of templates
  
    rm -rf _helpers hps, ingress.yaml, NOTES, serviceaccounts, tests

7) cd templates
    
      create a deployment.yml and service.yml copy the above content and paste it.

8) Install the demochart

helm:>/ helm install myrelease demochart

output: 
 

8) verify the cluster 

helm:>/ kubectl get all
helm:>/ kubectl get nodes -o wide

localhost:>/helm template demochart

cd helm

helm:>/ ls

             demochart

9) Convert helm file into ytt yml file

helm:>/ helm template demochart > ytt.yml

remove the commented # from the file

helm:/>kubectl get all 

Now delete the deployment and service 

:>/ kubectl delete 

      




Tuesday, February 1, 2022

Enable firewall port for Kubernetes

Prerequisite

yum install firewalld
systemctl start firewalld
systemctl enable firewalld 

Applying Firewall Port Rules

Server is set up on three nodes that have all three Kubernetes roles: etcd, controlplane, and worker. If your server nodes have all three roles, run the following commands on each node:

firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --permanent --add-port=2376/tcp
firewall-cmd --permanent --add-port=2379/tcp
firewall-cmd --permanent --add-port=2380/tcp
firewall-cmd --permanent --add-port=6443/tcp
firewall-cmd --permanent --add-port=8472/udp
firewall-cmd --permanent --add-port=9099/tcp
firewall-cmd --permanent --add-port=10250/tcp
firewall-cmd --permanent --add-port=10254/tcp
firewall-cmd --permanent --add-port=30000-32767/tcp
firewall-cmd --permanent --add-port=30000-32767/udp

If your server nodes have separate roles, use the following commands based on the role of the node:

# For etcd nodes, run the following commands:
firewall-cmd --permanent --add-port=2376/tcp
firewall-cmd --permanent --add-port=2379/tcp
firewall-cmd --permanent --add-port=2380/tcp
firewall-cmd --permanent --add-port=8472/udp
firewall-cmd --permanent --add-port=9099/tcp
firewall-cmd --permanent --add-port=10250/tcp

# For control plane nodes, run the following commands:
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --permanent --add-port=2376/tcp
firewall-cmd --permanent --add-port=6443/tcp
firewall-cmd --permanent --add-port=8472/udp
firewall-cmd --permanent --add-port=9099/tcp
firewall-cmd --permanent --add-port=10250/tcp
firewall-cmd --permanent --add-port=10254/tcp
firewall-cmd --permanent --add-port=30000-32767/tcp
firewall-cmd --permanent --add-port=30000-32767/udp

# For worker nodes, run the following commands:
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --permanent --add-port=2376/tcp
firewall-cmd --permanent --add-port=8472/udp
firewall-cmd --permanent --add-port=9099/tcp
firewall-cmd --permanent --add-port=10250/tcp
firewall-cmd --permanent --add-port=10254/tcp
firewall-cmd --permanent --add-port=30000-32767/tcp
firewall-cmd --permanent --add-port=30000-32767/udp

After the firewall-cmd commands have been run on a node, use the following command to enable the firewall rules:

firewall-cmd --reload

Monday, January 31, 2022

Unable to Schedule pod while Deploying nginx on Master node

 image

image

Resolution: Check for the tainted nodes 

By default, apps won’t get scheduled on the master node. If you want to use the master node for scheduling apps, taint the master node.
kubectl taint nodes --all node-role.kubernetes.io/master

How To Setup Kubernetes Cluster Using Kubeadm - Easy Guide (devopscube.com)