๐ Are you ready to dive into the world of Kubernetes from scratch? ๐ป
๐ Calling all aspiring developers! Whether you're an Angular, .NET, or Java enthusiast, a frontend or backend guru, or a full stack enthusiast, this step-by-step beginner's guide is perfect for you! ๐
๐ In this comprehensive tutorial, we will start from the very basics and guide you through the process of getting started with Kubernetes. You don't need any prior knowledge of Kubernetes or containerization - we'll cover everything from the ground up. You'll learn about the core conce# Getting started with Kubernetes on your local macOS. ๐ Are you ready to dive into the world of Kubernetes from scratch? ๐ป
๐ Calling all aspiring developers! Whether you're an Angular, .NET, or Java enthusiast, a frontend or backend guru, or a full stack enthusiast, this step-by-step beginner's guide is perfect for you! ๐
๐ In this comprehensive tutorial, we will start from the very basics and guide you through the process of getting started with Kubernetes. You don't need any prior knowledge of Kubernetes or containerization - we'll cover everything from the ground up. You'll learn about the core concepts, containerization, Kubernetes architecture, and how to deploy and manage your applications using Kubernetes.
So, if you're excited to learn Kubernetes and take your application development skills to the next level, let's dive in and embark on this Kubernetes journey together! ๐โจ
Before we proceed with setting up Minikube, it is essential to ensure that Docker is installed and running on your macOS machine. Here are the steps to install Docker Desktop on macOS and start the Docker service:
Next run docker to see if your docker is running
Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.
curl -LO https://github.com/kubernetes/minikube/releases/download/v1.30.1/minikube-darwin-arm64
sudo install minikube-darwin-arm64 /usr/local/bin/minikube
Start Minikube, before starting minikube make sure docker is running by openeing docker desktop on mac. Minikube start may take few minutes to generate the cluster.
minikube start
Next lets explore you Kubernetes(K8) cluster
kubectl cluster-info
You will see the ip address as localhost address since this cluster is setup on your machine running at https://127.0.0.1:53273
Next check all the nodes
kubectl get nodes
We get the error that means our cluster is not running yet. Let's run minikube start
one more time. And then re-run kubectl get nodes
One node with name minikube
with role of control-plane
my k8 is running with version 1.26
.
Let's check namespaces created by default
kubectl get namespaces
You isolate and manage applications and services using namespace.
Next let's see the pods created in all namespaces by passing -A
.
kubectl get pods -A
These pods, how containers are running k8 these pods have softwares to run k8 cluster itself.
Now let's see all the services. Services act as the loadbalancer and direct the traffic to the pods.
kubectl get services -A
If you are using single cluster for your applicaiton then You can namespace
to isolate and organize workloads. Example create dev
and prod
namespaces to separate them.
Check existing namespaces
kubectl get namespaces
K8 menefest to create a namespace called development
in file namespace.yml
---
apiVersion: v1
kind: Namespace
metadata:
name: development
Let's create the namesapce by runing command
kubectl apply -f namespace.yaml
Let's change the namespace.yaml to have both production and development namespaces and run kubectl apply -f namespace.yaml
to create both of them.
---
apiVersion: v1
kind: Namespace
metadata:
name: development
--- # way to signify new document in yaml
apiVersion: v1
kind: Namespace
metadata:
name: production
Now let's delete these 2 namespaces
kubectl delete -f namespace.yaml
Let's create Highly available application that will be deployed in 3 different pods. We will declare our dpplicaiton inside the deployment.yaml
file how we want our application to be deployed in development
namespace, with 3
replicas. We will run container in the pod which will display the information of the pod that it is running within you will use kimschles/pod-info-app:latest
image that will have that pod info app already created. We will setup container with 3 environment variables for pod name, namespace and ip that will be used by our app.
Let's create the development
namespace first. Run previous command kubectl apply -f namespace.yaml
to deploy namespace.
Next create deployment.yaml
with below definition.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-info-deployment
namespace: development
labels:
app: pod-info
spec:
replicas: 3
selector:
matchLabels:
app: pod-info
template:
metadata:
labels:
app: pod-info
spec:
containers:
- name: pod-info-container
image: kimschles/pod-info-app:latest
ports:
- containerPort: 3000
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
We do not have any deployment in our cluster yet kubectl get deployments
Now Let's create the deployment
kubectl apply -f deployment.yaml
Next let's check if the deployment is created kubectl get deployments -n development
pod-info-deployment
is created with 3 containers not ready yet after 15s
but wait for few more time and again check you should have 3 pods ready to go and available
Next let's check all the pods in the development
namespace
kubectl get pods -n development
Notice all the pods are running.
You have set the replica as 3
so always 3 pods will be running. To proove that go ahead and delete a pod and check.
Delete first pod by copy it's name and use delete pod
command.
kubectl delete pod pod-info-deployment-757cb75bbb-l2jd8 -n development
Check how much pods you left kubectl get pods -n development
๐ฒ You see still 3 pods, K8 deployment automatically terminated the one that you asked to delete and created brand new pod to make sure at any time 3 pods are running.
๐ Pet yourself ๐ถ, you created 3 pods with k8 deployment.
You check the health of a pod by looking at the event logs. Why pods may not work: container image not available, Worker nodes are out of space so pod can not be schedule.
# Find the pod that you want to check logs
kubectl get pods -n development
kubectl describe pod <pod-name> -n development
# We will take first pod and check its logs
kubectl describe pod pod-info-deployment-757cb75bbb-8cgf8 -n development
If your pod is not working check at the bottom and you will see the events with error messages.
You can use BusyBox tool to debug and troubleshoot issues in linux environment. For this you have to re-deploy your application with busybox tool.
In below definition busybox.yaml
of deployment, we will use 1 replica and deploy application in default
namespace. We will pull the image from busybox:latest
.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox
namespace: default
labels:
app: busybox
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox-container
image: busybox:latest
# Keep the container running
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
resources:
requests:
cpu: 30m
memory: 64Mi
limits:
cpu: 100m
memory: 128Mi
Deploy it
kubectl apply -f busybox.yaml
Get pods kubectl get pods
๐ Are you ready to dive into the world of Kubernetes from scratch? ๐ป
๐ Calling all aspiring developers! Whether you're an Angular, .NET, or Java enthusiast, a frontend or backend guru, or a full stack enthusiast, this step-by-step beginner's guide is perfect for you! ๐
๐ In this comprehensive tutorial, we will start from the very basics and guide you through the process of getting started with Kubernetes. You don't need any prior knowledge of Kubernetes or containerization - we'll cover everything from the ground up. You'll learn about the core concepts, containerization, Kubernetes architecture, and how to deploy and manage your applications using Kubernetes.
So, if you're excited to learn Kubernetes and take your application development skills to the next level, let's dive in and embark on this Kubernetes journey together! ๐โจ
Before we proceed with setting up Minikube, it is essential to ensure that Docker is installed and running on your macOS machine. Here are the steps to install Docker Desktop on macOS and start the Docker service:
Next run docker to see if your docker is running
Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.
curl -LO https://github.com/kubernetes/minikube/releases/download/v1.30.1/minikube-darwin-arm64
sudo install minikube-darwin-arm64 /usr/local/bin/minikube
Start Minikube, before starting minikube make sure docker is running by openeing docker desktop on mac. Minikube start may take few minutes to generate the cluster.
minikube start
Next lets explore you Kubernetes(K8) cluster
kubectl cluster-info
You will see the ip address as localhost address since this cluster is setup on your machine running at https://127.0.0.1:53273
Next check all the nodes
kubectl get nodes
We get the error that means our cluster is not running yet. Let's run minikube start
one more time. And then re-run kubectl get nodes
One node with name minikube
with role of control-plane
my k8 is running with version 1.26
.
Let's check namespaces created by default
kubectl get namespaces
You isolate and manage applications and services using namespace.
Next let's see the pods created in all namespaces by passing -A
.
kubectl get pods -A
These pods, how containers are running k8 these pods have softwares to run k8 cluster itself.
Now let's see all the services. Services act as the loadbalancer and direct the traffic to the pods.
kubectl get services -A
If you are using single cluster for your applicaiton then You can namespace
to isolate and organize workloads. Example create dev
and prod
namespaces to separate them.
Check existing namespaces
kubectl get namespaces
K8 menefest to create a namespace called development
in file namespace.yml
---
apiVersion: v1
kind: Namespace
metadata:
name: development
Let's create the namesapce by runing command
kubectl apply -f namespace.yaml
Let's change the namespace.yaml to have both production and development namespaces and run kubectl apply -f namespace.yaml
to create both of them.
---
apiVersion: v1
kind: Namespace
metadata:
name: development
--- # way to signify new document in yaml
apiVersion: v1
kind: Namespace
metadata:
name: production
Now let's delete these 2 namespaces
kubectl delete -f namespace.yaml
Let's create Highly available application that will be deployed in 3 different pods. We will declare our dpplicaiton inside the deployment.yaml
file how we want our application to be deployed in development
namespace, with 3
replicas. We will run container in the pod which will display the information of the pod that it is running within you will use kimschles/pod-info-app:latest
image that will have that pod info app already created. We will setup container with 3 environment variables for pod name, namespace and ip that will be used by our app.
Let's create the development
namespace first. Run previous command kubectl apply -f namespace.yaml
to deploy namespace.
Next create deployment.yaml
with below definition.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-info-deployment
namespace: development
labels:
app: pod-info
spec:
replicas: 3
selector:
matchLabels:
app: pod-info
template:
metadata:
labels:
app: pod-info
spec:
containers:
- name: pod-info-container
image: kimschles/pod-info-app:latest
ports:
- containerPort: 3000
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
We do not have any deployment in our cluster yet kubectl get deployments
Now Let's create the deployment
kubectl apply -f deployment.yaml
Next let's check if the deployment is created kubectl get deployments -n development
pod-info-deployment
is created with 3 containers not ready yet after 15s
but wait for few more time and again check you should have 3 pods ready to go and available
Next let's check all the pods in the development
namespace
kubectl get pods -n development
Notice all the pods are running.
You have set the replica as 3
so always 3 pods will be running. To proove that go ahead and delete a pod and check.
Delete first pod by copy it's name and use delete pod
command.
kubectl delete pod pod-info-deployment-757cb75bbb-l2jd8 -n development
Check how much pods you left kubectl get pods -n development
๐ฒ You see still 3 pods, K8 deployment automatically terminated the one that you asked to delete and created brand new pod to make sure at any time 3 pods are running.
๐ Pet yourself ๐ถ, you created 3 pods with k8 deployment.
You check the health of a pod by looking at the event logs. Why pods may not work: container image not available, Worker nodes are out of space so pod can not be schedule.
# Find the pod that you want to check logs
kubectl get pods -n development
kubectl describe pod <pod-name> -n development
# We will take first pod and check its logs
kubectl describe pod pod-info-deployment-757cb75bbb-8cgf8 -n development
If your pod is not working check at the bottom and you will see the events with error messages.
You can use BusyBox tool to debug and troubleshoot issues in linux environment. For this you have to re-deploy your application with busybox tool.
In below definition busybox.yaml
of deployment, we will use 1 replica and deploy application in default
namespace. We will pull the image from busybox:latest
.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox
namespace: default
labels:
app: busybox
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox-container
image: busybox:latest
# Keep the container running
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
resources:
requests:
cpu: 30m
memory: 64Mi
limits:
cpu: 100m
memory: 128Mi
Deploy it
kubectl apply -f busybox.yaml
Get pods kubectl get pods
Open new terminal and fetch all pods in development with its ip details -o wide
gives pods extra info like IP address
kubectl get pods -n development -o wide
Next, run command to get into the busybox pod and open bash shell. Copy the busybox pod name from previous open terminal.
kubectl exec -it busybox-6b95744666-zh9tx -- /bin/sh
You will see command shell type wget
to see it is installed or not.
Next from busybox pod I will try to wget
one of the IP address from development pod. Copy one of the IP of the pod from development namespace and run below script on busybox interactive terminal.
wget 10.244.0.13
You will get connection refused error
Notice that busybox is trying to access pod with default port 80 (10.244.0.13:80)
however, our pod in development is deployed in port 3000 so lets change the script to include port number 3000 and run in busybox terminal
wget 10.244.0.13:3000
You are able to connect good news
Check the output of the pod application saved in the index.html
file. Wget saved info in the html file.
cat index.html
So you deployed an application in development namespace and used busybox to check if it is working or not. Next you will learn how to check application logs.
Run exit
to go out of terminal of pod.
If you want to debug application issues use application logs.
kubectl get pods -n development
Inspect log
kubectl logs <pod-name> -n development
kubectl logs pod-info-deployment-757cb75bbb-pdtxc -n development
So we were able to access our pods using busybox however how do you access your pods from internet? You will learn next.
K8 Service is a LoadBalancer service, it directs traffic from internet to pods. Loadbalancer service has public and private static IP addess. We had deployed pod with selector pod-info
.
There are 3 types of kubernetes services: 1) LoadBalancer, 2) Nodeport 3) ClusterIP.
You will create LoadBalancer type service by creating service.yaml
and running it.
---
apiVersion: v1
kind: Service
metadata:
name: demo-service
namespace: development
spec:
selector:
app: pod-info
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
Creae Service
kubectl apply -f service.yaml
Get Service external/internal IP
kubectl get services -n development
Next in order to get external ip lets run below command in another terminal
sudo minikube tunnel
Next rerun service command
kubectl get services -n development
Notice external IP is displayed as localhost. Since minikube has setup your cluster in localbox it will use localhost as external IP. If you create Loadbalancer from GCP, Azure or AWS then you would get real external internet exposed IP address.
Next, you will access the IP address to visit http://127.0.0.1 from your laptop. Notice site not loading so go to the terminal where you run tunnel command there you have to enter your password to start this app and refresh the browser again.
http://127.0.0.1 site is giving the output where it shows the pod details.
You have used k8 loadbalancer service to expose the pod into the internet. Next you will restrict the resource request limit on the container in the pods.
pts, containerization, Kubernetes architecture, and how to deploy and manage your applications using Kubernetes.
So, if you're excited to learn Kubernetes and take your application development skills to the next level, let's dive in and embark on this Kubernetes journey together! ๐โจ
Before we proceed with setting up Minikube, it is essential to ensure that Docker is installed and running on your macOS machine. Here are the steps to install Docker Desktop on macOS and start the Docker service:
Next run docker to see if your docker is running
Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.
curl -LO https://github.com/kubernetes/minikube/releases/download/v1.30.1/minikube-darwin-arm64
sudo install minikube-darwin-arm64 /usr/local/bin/minikube
Start Minikube, before starting minikube make sure docker is running by openeing docker desktop on mac. Minikube start may take few minutes to generate the cluster.
minikube start
Next lets explore you Kubernetes(K8) cluster
kubectl cluster-info
You will see the ip address as localhost address since this cluster is setup on your machine running at https://127.0.0.1:53273
Next check all the nodes
kubectl get nodes
We get the error that means our cluster is not running yet. Let's run minikube start
one more time. And then re-run kubectl get nodes
One node with name minikube
with role of control-plane
my k8 is running with version 1.26
.
Let's check namespaces created by default
kubectl get namespaces
You isolate and manage applications and services using namespace.
Next let's see the pods created in all namespaces by passing -A
.
kubectl get pods -A
These pods, how containers are running k8 these pods have softwares to run k8 cluster itself.
Now let's see all the services. Services act as the loadbalancer and direct the traffic to the pods.
kubectl get services -A
If you are using single cluster for your applicaiton then You can namespace
to isolate and organize workloads. Example create dev
and prod
namespaces to separate them.
Check existing namespaces
kubectl get namespaces
K8 menefest to create a namespace called development
in file namespace.yml
---
apiVersion: v1
kind: Namespace
metadata:
name: development
Let's create the namesapce by runing command
kubectl apply -f namespace.yaml
Let's change the namespace.yaml to have both production and development namespaces and run kubectl apply -f namespace.yaml
to create both of them.
---
apiVersion: v1
kind: Namespace
metadata:
name: development
--- # way to signify new document in yaml
apiVersion: v1
kind: Namespace
metadata:
name: production
Now let's delete these 2 namespaces
kubectl delete -f namespace.yaml
Let's create Highly available application that will be deployed in 3 different pods. We will declare our dpplicaiton inside the deployment.yaml
file how we want our application to be deployed in development
namespace, with 3
replicas. We will run container in the pod which will display the information of the pod that it is running within you will use kimschles/pod-info-app:latest
image that will have that pod info app already created. We will setup container with 3 environment variables for pod name, namespace and ip that will be used by our app.
Let's create the development
namespace first. Run previous command kubectl apply -f namespace.yaml
to deploy namespace.
Next create deployment.yaml
with below definition.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-info-deployment
namespace: development
labels:
app: pod-info
spec:
replicas: 3
selector:
matchLabels:
app: pod-info
template:
metadata:
labels:
app: pod-info
spec:
containers:
- name: pod-info-container
image: kimschles/pod-info-app:latest
ports:
- containerPort: 3000
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
We do not have any deployment in our cluster yet kubectl get deployments
Now Let's create the deployment
kubectl apply -f deployment.yaml
Next let's check if the deployment is created kubectl get deployments -n development
pod-info-deployment
is created with 3 containers not ready yet after 15s
but wait for few more time and again check you should have 3 pods ready to go and available
Next let's check all the pods in the development
namespace
kubectl get pods -n development
Notice all the pods are running.
You have set the replica as 3
so always 3 pods will be running. To proove that go ahead and delete a pod and check.
Delete first pod by copy it's name and use delete pod
command.
kubectl delete pod pod-info-deployment-757cb75bbb-l2jd8 -n development
Check how much pods you left kubectl get pods -n development
๐ฒ You see still 3 pods, K8 deployment automatically terminated the one that you asked to delete and created brand new pod to make sure at any time 3 pods are running.
๐ Pet yourself ๐ถ, you created 3 pods with k8 deployment.
You check the health of a pod by looking at the event logs. Why pods may not work: container image not available, Worker nodes are out of space so pod can not be schedule.
# Find the pod that you want to check logs
kubectl get pods -n development
kubectl describe pod <pod-name> -n development
# We will take first pod and check its logs
kubectl describe pod pod-info-deployment-757cb75bbb-8cgf8 -n development
If your pod is not working check at the bottom and you will see the events with error messages.
You can use BusyBox tool to debug and troubleshoot issues in linux environment. For this you have to re-deploy your application with busybox tool.
In below definition busybox.yaml
of deployment, we will use 1 replica and deploy application in default
namespace. We will pull the image from busybox:latest
.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox
namespace: default
labels:
app: busybox
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox-container
image: busybox:latest
# Keep the container running
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
resources:
requests:
cpu: 30m
memory: 64Mi
limits:
cpu: 100m
memory: 128Mi
Deploy it
kubectl apply -f busybox.yaml
Get pods kubectl get pods
๐ Are you ready to dive into the world of Kubernetes from scratch? ๐ป
๐ Calling all aspiring developers! Whether you're an Angular, .NET, or Java enthusiast, a frontend or backend guru, or a full stack enthusiast, this step-by-step beginner's guide is perfect for you! ๐
๐ In this comprehensive tutorial, we will start from the very basics and guide you through the process of getting started with Kubernetes. You don't need any prior knowledge of Kubernetes or containerization - we'll cover everything from the ground up. You'll learn about the core concepts, containerization, Kubernetes architecture, and how to deploy and manage your applications using Kubernetes.
So, if you're excited to learn Kubernetes and take your application development skills to the next level, let's dive in and embark on this Kubernetes journey together! ๐โจ
Before we proceed with setting up Minikube, it is essential to ensure that Docker is installed and running on your macOS machine. Here are the steps to install Docker Desktop on macOS and start the Docker service:
Next run docker to see if your docker is running
Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.
curl -LO https://github.com/kubernetes/minikube/releases/download/v1.30.1/minikube-darwin-arm64
sudo install minikube-darwin-arm64 /usr/local/bin/minikube
Start Minikube, before starting minikube make sure docker is running by openeing docker desktop on mac. Minikube start may take few minutes to generate the cluster.
minikube start
Next lets explore you Kubernetes(K8) cluster
kubectl cluster-info
You will see the ip address as localhost address since this cluster is setup on your machine running at https://127.0.0.1:53273
Next check all the nodes
kubectl get nodes
We get the error that means our cluster is not running yet. Let's run minikube start
one more time. And then re-run kubectl get nodes
One node with name minikube
with role of control-plane
my k8 is running with version 1.26
.
Let's check namespaces created by default
kubectl get namespaces
You isolate and manage applications and services using namespace.
Next let's see the pods created in all namespaces by passing -A
.
kubectl get pods -A
These pods, how containers are running k8 these pods have softwares to run k8 cluster itself.
Now let's see all the services. Services act as the loadbalancer and direct the traffic to the pods.
kubectl get services -A
If you are using single cluster for your applicaiton then You can namespace
to isolate and organize workloads. Example create dev
and prod
namespaces to separate them.
Check existing namespaces
kubectl get namespaces
K8 menefest to create a namespace called development
in file namespace.yml
---
apiVersion: v1
kind: Namespace
metadata:
name: development
Let's create the namesapce by runing command
kubectl apply -f namespace.yaml
Let's change the namespace.yaml to have both production and development namespaces and run kubectl apply -f namespace.yaml
to create both of them.
---
apiVersion: v1
kind: Namespace
metadata:
name: development
--- # way to signify new document in yaml
apiVersion: v1
kind: Namespace
metadata:
name: production
Now let's delete these 2 namespaces
kubectl delete -f namespace.yaml
Let's create Highly available application that will be deployed in 3 different pods. We will declare our dpplicaiton inside the deployment.yaml
file how we want our application to be deployed in development
namespace, with 3
replicas. We will run container in the pod which will display the information of the pod that it is running within you will use kimschles/pod-info-app:latest
image that will have that pod info app already created. We will setup container with 3 environment variables for pod name, namespace and ip that will be used by our app.
Let's create the development
namespace first. Run previous command kubectl apply -f namespace.yaml
to deploy namespace.
Next create deployment.yaml
with below definition.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-info-deployment
namespace: development
labels:
app: pod-info
spec:
replicas: 3
selector:
matchLabels:
app: pod-info
template:
metadata:
labels:
app: pod-info
spec:
containers:
- name: pod-info-container
image: kimschles/pod-info-app:latest
ports:
- containerPort: 3000
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
We do not have any deployment in our cluster yet kubectl get deployments
Now Let's create the deployment
kubectl apply -f deployment.yaml
Next let's check if the deployment is created kubectl get deployments -n development
pod-info-deployment
is created with 3 containers not ready yet after 15s
but wait for few more time and again check you should have 3 pods ready to go and available
Next let's check all the pods in the development
namespace
kubectl get pods -n development
Notice all the pods are running.
You have set the replica as 3
so always 3 pods will be running. To proove that go ahead and delete a pod and check.
Delete first pod by copy it's name and use delete pod
command.
kubectl delete pod pod-info-deployment-757cb75bbb-l2jd8 -n development
Check how much pods you left kubectl get pods -n development
๐ฒ You see still 3 pods, K8 deployment automatically terminated the one that you asked to delete and created brand new pod to make sure at any time 3 pods are running.
๐ Pet yourself ๐ถ, you created 3 pods with k8 deployment.
You check the health of a pod by looking at the event logs. Why pods may not work: container image not available, Worker nodes are out of space so pod can not be schedule.
# Find the pod that you want to check logs
kubectl get pods -n development
kubectl describe pod <pod-name> -n development
# We will take first pod and check its logs
kubectl describe pod pod-info-deployment-757cb75bbb-8cgf8 -n development
If your pod is not working check at the bottom and you will see the events with error messages.
You can use BusyBox tool to debug and troubleshoot issues in linux environment. For this you have to re-deploy your application with busybox tool.
In below definition busybox.yaml
of deployment, we will use 1 replica and deploy application in default
namespace. We will pull the image from busybox:latest
.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox
namespace: default
labels:
app: busybox
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox-container
image: busybox:latest
# Keep the container running
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
resources:
requests:
cpu: 30m
memory: 64Mi
limits:
cpu: 100m
memory: 128Mi
Deploy it
kubectl apply -f busybox.yaml
Get pods kubectl get pods
Open new terminal and fetch all pods in development with its ip details -o wide
gives pods extra info like IP address
kubectl get pods -n development -o wide
Next, run command to get into the busybox pod and open bash shell. Copy the busybox pod name from previous open terminal.
kubectl exec -it busybox-6b95744666-zh9tx -- /bin/sh
You will see command shell type wget
to see it is installed or not.
Next from busybox pod I will try to wget
one of the IP address from development pod. Copy one of the IP of the pod from development namespace and run below script on busybox interactive terminal.
wget 10.244.0.13
You will get connection refused error
Notice that busybox is trying to access pod with default port 80 (10.244.0.13:80)
however, our pod in development is deployed in port 3000 so lets change the script to include port number 3000 and run in busybox terminal
wget 10.244.0.13:3000
You are able to connect good news
Check the output of the pod application saved in the index.html
file. Wget saved info in the html file.
cat index.html
So you deployed an application in development namespace and used busybox to check if it is working or not. Next you will learn how to check application logs.
Run exit
to go out of terminal of pod.
If you want to debug application issues use application logs.
kubectl get pods -n development
Inspect log
kubectl logs <pod-name> -n development
kubectl logs pod-info-deployment-757cb75bbb-pdtxc -n development
So we were able to access our pods using busybox however how do you access your pods from internet? You will learn next.
K8 Service is a LoadBalancer service, it directs traffic from internet to pods. Loadbalancer service has public and private static IP addess. We had deployed pod with selector pod-info
.
There are 3 types of kubernetes services: 1) LoadBalancer, 2) Nodeport 3) ClusterIP.
You will create LoadBalancer type service by creating service.yaml
and running it.
---
apiVersion: v1
kind: Service
metadata:
name: demo-service
namespace: development
spec:
selector:
app: pod-info
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
Creae Service
kubectl apply -f service.yaml
Get Service external/internal IP
kubectl get services -n development
Next in order to get external ip lets run below command in another terminal
sudo minikube tunnel
Next rerun service command
kubectl get services -n development
Notice external IP is displayed as localhost. Since minikube has setup your cluster in localbox it will use localhost as external IP. If you create Loadbalancer from GCP, Azure or AWS then you would get real external internet exposed IP address.
Next, you will access the IP address to visit http://127.0.0.1 from your laptop. Notice site not loading so go to the terminal where you run tunnel command there you have to enter your password to start this app and refresh the browser again.
http://127.0.0.1 site is giving the output where it shows the pod details.
You have used k8 loadbalancer service to expose the pod into the internet. Next you will restrict the resource request limit on the container in the pods.