Introduction:-
Kubernetes is a powerful container orchestration tool that enables developers to deploy, manage, and scale containerized applications. While Kubernetes is designed to be easy to use, it's not without its challenges, and troubleshooting is a critical skill that all Kubernetes users must possess. In this blog, we'll explore some common Kubernetes troubleshooting techniques that you can use to diagnose and fix issues with your Kubernetes clusters.
Prerequisites for deployment-
- Update the system and install docker:
sudo apt update -y
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
- Kubeadm installation:
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update -y
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
- To connect with the cluster(for the master node):
sudo su
kubeadm init
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
kubeadm token create --print-join-command
- To connect with the cluster(for the Worker node):
sudo su
kubeadm reset pre-flight checks
(*Paste the Join command on worker node and append `--v=5` at end*)
(*kubeadm token create --print-join-command*)
- To verify cluster connection:-
kubectl get nodes
Let's dive into our deployment------>
Clone the repo:-
1. Create the docker file
vim Dockerfile
- Configuration of the docker file
FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENV PORT 5000
EXPOSE 5000
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
3. Now we will make a new deployment file of taskmaster.yml
apiVersion: apps/v1 kind: Deployment metadata: name: taskmaster labels: app: taskmaster spec: replicas: 1 selector: matchLabels: app: taskmaster template: metadata: labels: app: taskmaster spec: containers: - name: taskmaster image: gauriyadav1504/gauri-micro:latest ports: - containerPort: 5000 imagePullPolicy: Always
- Make new taskmaster service file known as taskmaster-svc.yml
kind: Service
metadata:
name: taskmaster-svc
spec:
selector:
app: taskmaster
ports:
- port: 80
targetPort: 5000
nodePort: 30007
type: NodePort
- Make Mongo persistent volume file, that is mongo-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongo-pv
spec:
capacity:
storage: 256Mi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/db
- Make a file to claim persistent volume, that is mongo-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongo-pv
spec:
capacity:
storage: 256Mi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/db
- Make a mongo file vim mongo.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo
labels:
app: mongo
spec:
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongo
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: storage
mountPath: /data/db
volumes:
- name: storage
persistentVolumeClaim:
claimName: mongo-pvc
- make service for mongo file vim mongo-svc.yml
apiVersion: v1
kind: Service
metadata:
labels:
app: mongo
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
selector:
app: mongo
Thank you for reading!!
\...................................................................................................................................................
~Dushyant Kumar
The above information is up to my understanding. Suggestions are always welcome.
#Kubernetes #DevOps #90daysofdevops #KubeWeek
Shubham Londhe Sir
Follow for many such contents: