Elastic Kubernetes Service


In case of one pod is dead, Scheduler(Through API ) is schedule one pod in deployment mention 2 pods req.
Mantra - Everything in k8s is manifests files
Whole things like pod, services, deployment,.etc Everything is K8S is either command or manifests file. All manifest file are available k8s document (Web). Ex: Pod
kubernetes.io/docs/concepts/workloads/pods/
Basically It written in YML format
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
yaml file executed through kubectl (kubecontrol). It trigger API server.
apiVersion - As interacts with API server
kind - What I want to make?
metadata - Information of kind(first block) It's Obj. like name
spec - specification These are details
Practice in AWS
Steps
Method 1: Through Command
mkdir k8s-practice
cd k8s-practice
vim pod.yml
apiVersion: v1
kind: Pod
metadata:
name: nignx-pod
spec:
containers:
-name: nginx
image: nginx:latest
ports:
- containerPort: 80
image: nginx:latest
- Executes Docker run
Save the file :wq
If namespace is not assign a default name is given.
kubectl get pods
Checks the available pods.
kubectl create namespace nginx
Create namespace with nginx (Isolated group.)
Method 2: Through Manifest
vim namespace.yml
kubernetes.io/docs/tutorials/cluster-management/namespaces-walkthrough/
apiVersion: v1
kind: Namespace
metadata:
name: development
labels:
name: development
label -> To categorize
kubectl get namespace
kubectl delete namespace nginx
Checks the available namespace and deletes.
kubectl apply -f namespace.yml
Creates namespace.yml file
vim pod.yml
apiVersion: v1
kind: Pod
metadata:
name: nignx-pod
namespace: nginx
spec:
containers:
-name: nginx
image: nginx:latest
ports:
- containerPort: 80
kubectl apply -f pod.yml
kubectl get pods -n nginx
Creates pod.yml file
pod is created with pre-defined namespcae. Whereas w/o flag -n(namespace) is created with default namespace as mentioned in Method-1.
kubectl delete -f pod.yml
Replica If multiple pod req. then deployment is needed.
vim deployment.yml
kubernetes.io/docs/concepts/workloads/controllers/deployment/
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: nginx
labels:
app: nginx
spec:
replicas: 5
selector:
matchLabels:
app: nginx
template:
metadata:
name: nginx-pod
namespace: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
Save the file :wq
Explanation
apiVersion: apps/v1 -> Special type for deployment
kind: Deployment -> What kind of file
metadata : -> Info. above apiVersion
labels: -> Tag/ Categorize
spec: -> Specification
selector -> Criteria
matchLabels: -> Finds the pattern label
deployment.yml file is completed just above template section spec(replicas) from template onwards we are providing pod.yml file config.
In metadata and template, I included namespace as that in nginx group.
kubectl apply --validate=true --dry-run=client --filename=deployment.yml
kubectl apply -f deployment.yml
kubectl get pods -n nginx
validate command is used to check the syntax.
It will show 5 pods has deployed as written as deployment.yml
If I want to increase the pods size (replicas) vi deployment.yml file update the values of replica and save the file. and run kubectl apply -f deployment.yml, file get config. and get pods show pod running status.
To check Auto-Healing status
kubectl delete pod nginx-deploymet-7f78fb778(pod name) -n nginx
kubectl delete pod (pod name) -n nginx
kubectl get pods -n nginx
We notice that even after deletion of pods new pods are created as no. of replica mention in deployment.yml file.
kubectl describe pod (pod_name) -n nginx
Gives whole info. about that particular pod. This cmd is used during crush/downtime of pod.
kubectl get all -n nginx
It gives all the details of pod, deployment, replica set.
To Communicate with external world
kubernetes.io/docs/concepts/services-networking/service/
targetPort -> pod/Deployment (container is running)
port -> Service
In webpage, Search for Load balancer
Video Timestamp 3:05:40
vim service.yml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: nginx
labels:
app: nginx
spec:
selector:
app: ngnix
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
kubectl apply -f service.yml
kubectl get deployment -n nginx
kubectl get service -n nginx
Using External IP from o/p of service cmd. We can view the nginx webpage.
Fun fact
Note-app -> Docker container
Container is formed by Image
Image is formed by Docker file
If we change the image then we access the services inside that the environment.
vim deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: nginx
labels:
app: nginx
spec:
replicas: 5
selector:
matchLabels:
app: nginx
template:
metadata:
name: nginx-pod
namespace: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: trainwithshubham/notes-app:latest
ports:
- containerPort: 8000
vim service.yml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: nginx
labels:
app: nginx
spec:
selector:
app: ngnix
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: LoadBalancer
Save these files :wq
kubectl apply -f deployment.yml
kubectl apply -f service.yml
kubectl get svc -n nginx
Exact external IP to check the service.
To delete eks cluster
Initially delete the resources
kubectl delete -f .
kubectl apply -f .
kubectl get all -n nginx
eksctl delete cluster --name=tws-cluster --region=us-west-2
kubectl apply -f .
It will recreate.
Check manually also whether it has deleted or not.
Hands-on & Quiz is pending.
Do it for free?
Login to killercoda
Select playground -> kubernetes 1.32
git clone github.com/LondheShubham153/aws-eks-devops-best-practices.git
cd aws-eks-devops-best-practices/01-deploy-sample-application
kubectl create namespace eks-sample-app
kubectl apply -f .
kubectl get all -n eks-sample-app # To get external-ip
Quiz
Which Kubernetes component represents the smallest deployable unit? Node Pod Deployment Service
Which component in Kubernetes stores the entire cluster state and can facilitate rollbacks of deployments? etcd ConfigMaps Deployment Service
Which K8s component is responsible for assigning newly created pods to specific nodes based on various criteria like resource requirements and affinity rules? kube-controller-manager kube-scheduler Kubeapi-server kube-proxy
The scheduler is responsible for both deciding where a Pod will run and actually running it. True False
What are the primary components of a Kubernetes master node (Control Plane)? kube-proxy,kubelet,Docker API server, kubelet, kube-proxy kube-proxy,kubelet,Docker APIServer,ControllerManager, etcd, Scheduler
What is Kubernetes kubectl? A Command-line tool used to interact with k8s clusters A tool for managing k8s resources A networking abstraction to access a set of Pods A way to manages K8s nodes
What is Kubernetes Horizontal Pod Autoscaler(HPA)? A tool for managing Kubernetes resources A way to automatically scale the number of pods in a k8s deployment based on resource utilization. A networking abstraction to access a set of pods A way to manages k8s nodes
Which of the following is a main component of k8s architectures? API Server Container Runtime kubectl Command Line interface
What is the primary purose of kubeadm? To deploy K8s cluster To manage k8s To provide security for k8s cluster To provide appln development tools
Which of the following is a kubeadm cmd used to join node to a cluster? kubeadm init kubeadm join kubeadm reset kubeadm version
Answer
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes. A Pod is a group of one or more containers.
etcd is a consistent and highly available key-value store used by K8s to save all cluster data, ensuring cluster state and configuration stability ( etcd is typically present as a present as a separate cluster of nodes or on the master node's)
kube-scheduler intelligently determines the best node for a pod, considering factors like resource availability, node constraints, affinity and anti-affinity specifications and other set policies.
False while the scheduler is responsible for choosing the node on which the pod will run, Kubelet is the one that actually runs the Pod.
APIServer,ControllerManager, etcd, Scheduler Other options like kubeproxy and kubelet are related to worker nodes.
A Command-line tool used to interact with k8s clusters enabling administratives to manages k8s resource, create, modify and delete resource and troubleshoot cluster issues.
Horizontal Pod Autoscaler(HPA) is way to automatically scale the number of pods in a k8s deployment based on resource utilization, enabling administrators to ensure that their applications can handle varying levels of traffic and load
API Server is the main component of K8S arch. It is responsible for accepting user requests and managing the state of the cluster.
Kubeadm is a tool for quickly and easily deploying k8s cluster on existing infrastructure
kubeadm join is used to join a node to a cluster, while kubeadm init is used to initialize a cluster kubeadm reset is used to reset a cluster, and kudeadm version is used to check the version of kubeadm.
Subscribe to my newsletter
Read articles from Kiran Chavan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
