Posts

lables,selector,replicaset,deploymentset

 Labels:- Labels are the mechanism to organize Kubernetes objects such as Pods   A label is a key-value pair. Labels can be attached to objects at creation time or added and modified at any time.    "metadata" : { "labels" : { "key1" : "value1" , "key2" : "value2" } } To create lables imperative we can use kubectl label pods delhipod myname=ajay  // delhipod is pod name  to check the lables  kubectl get pods --show-labels // to show the lables of pods  To get the pods where env is not equal to development  kubectl get pods -l env!=development   // We need to use ! sign before key (env is key hear) We can also delete the pods using lables kubectl delete pod -l env!=development   Labels Selector Once the lables are attached to an object, we would need filters to narrow down and these are called as labels selector The API currently supports two types of selector -  1 equality based  ( =, !=)...

Kuberntes architecture

Image
 Differnce between docker and kuberntes kuberntes have  cluster management  autoscaling autohealing enterprise application support like loadbalancing , fariewall  Docker shim is container runtime in docker to run containers  The smallest unit of deployment in docker is container The smallest unit of deployment in kuberntes is pod Kublete :-  The Kubelet is responsible for  managing the deployment of pods to Kubernetes nodes What Is a Container Runtime? A container runtime, also known as container engine, is a software component that can run containers on a host operating system. In a  containerized architecture , container runtimes are responsible for loading container images from a repository, monitoring local system resources, isolating system resources for use of a container, and managing container lifecycle.  Common container runtimes commonly work together with container orchestrators. The orchestrator is responsible for managing cluster...

Docker

  hostnamectl set-hostname docker-host     // Change the hostname to docker-host Docker  There is not password for run pull request for docker   yum update -y      yum install docker* systemctl status docker systemctl start docker systemctl enable docker systemctl enable docker.service   // auto enable service for docker  systemctl status docker pull the images for docker hub https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.82/bin/apache-tomcat-9.0.82.tar.gz docker pull centos // if we do not put tags it will download the latest images docker pull centos: 7 // It has verion 7 tags Note we can pull docker images without login to dockerhub    docker images        docker info | grep -i dir     // Docker info for storing docker images        ls -l /var/lib/docker/    //Location where docker images are stored    ls -l /var/lib/docker/overlay2/6a61...

Advanced Pods

  Scheduling  :- The process of assigning Pods to Nodes so kubelets can run them.  Scheduler :-  Control plane component that handles scheduling  Scheduling Process The kubernets scheduler selects a suitable Node for each pod. It takes into account thins like Resource requests vs. avaiable node resource Various configurations that affect scheduling using node labels NodeSelector :- We can configure a node Selector for our pods to limit which nodes the pod can be scheduled on. Node selectos use node labels to filter suitable nodes.  Create labeles to node :- kubectl label nodes k8s-worker1 special=true NodeName :- We can bypass scheduling and assign a pod to specific node by name using nodeName.  What is DaemonSet  DaemonSet Automatically runs a copy of a Pod on each node.  DaemonSets will run a copy of the Pod on new nodes as they are added to the cluster.  DaemonSets and Scheduling DaemonSets respect normal scheduling rules around node ...

Pods

Image
Pod:- definition of how to run a container?   Inspecting POD Resource Usage Kubernetes Metric Server In order to view metrics about the resources pods and containers are using, we need an add-on to collect and provide that data. One such add-on is Kubernetes Metric Server.  kubectl top  with kubectl top we can view data about resource usage in our pods and nodes. kubectl top also supports flags like --sort-by and --selector kubectl top pod --sort-by <JSONPATH> -- selector <selector>  Command to install metric server commont kubectl apply -f https://raw.githubusercontent.com/linuxacademy/content-cka-resources/master/metrics-server-components.yaml to check its installed kubectl get --raw /apis/metrics.k8s.io/ kubectl top pod // to check CPU usage and memory  kubectl top node  // to check CPU usage of nodes Application Configuration :- When we are running applications in kubernetes, we may want to pass dyunamic values to our applications at ru...

RBAC

Image
 RBAC in K8s Role-based access control (RBAC) in k8s allows us to control what users are allowed to do and access within your cluster. For example, we can use RBAC to allow developers to read metadata and logs from Kubernetes pods but not make changes to them.  Roles and ClusterRoles are kubernetes object that define a set of permissions. These permissions determine what users can do in the cluster.  A role defines permissions within a particular namespace, and a cluster role defines cluster-wide permissions not specific to a single namespace.  RoleBininding and cluserRoleBinding are objects that connect Roles and ClusterRoles to users.  Service accounts What is service accounts ? Service account is an account used by container processes within Pods to authenticate with the k8s API.  If your Pods need to communicate with the k8s, we can use service accounts to control their access.  Creating Service accounts A service account object can be created wit...

Kubectl

 What is kubectl ? Kubectl is a command line tool that allows us to interact with kubernetes. Kubectl uses the kubernetes API to communicate with the cluster and carry out our command  We can use kubectl to deploy applications, insepct and manage cluster resources, and view logs.  Kubectl get  use kubectl get to list objects in the Kubernetes cluster kubectl get <object type> <object name> -o <output> --sort-by <JSONPATH> -- selector <selector>  -o = Set output format --sort-by = Sort output using a JSONPath expression. --selector - Filter results by label.  kubectl get pods // its to give to you the list of pods  kubectl describe  We can get detailed information about kubernetes objects using kubectl describe.  Kubectl describe <object type> <object name>  kubectl describe pods my-pod // to detail information of my-pod kubectl create kubectl create to create objects.  Supply a yaml file wit...