Kubernetes, also known as K8s, is an open-source platform for managing containerized workloads and services. facilitates both declarative configuration and automation. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation.
- Kubernetes orchestrates clusters of virtual machines and schedules containers to run on those virtual machines based on their available compute resources and the resource requirements of each container.
- Containers are grouped into pods, the basic operational unit for Kubernetes, and those pods scale to your desired state.
- Kubernetes also automatically manages service discovery, incorporates load balancing, tracks resource allocation, and scales based on compute utilization.
Kubernetes provides a way to schedule and deploy containers, scale them to your desired state, and manage their lifecycles. It makes workloads portable and allows you to implement your container-based applications in a portable, scalable, and extensible way.
If you want to set up Kubernetes by installing Minikube, just visit the Kubernetes Lab-Setup. In this blog, you will find a step-by-step guide from start to finish, allowing you to easily complete your Kubernetes lab setup. So, what are you waiting for? Just click on Kubernetes Lab-Setup*
-
Creation of Pods
kubectl run azfarpod --image=httpd
-
To check the Pods
kubectl get pods
-
To delete a Pods
kubectl delete pods --all
or
kubectl delete pods azfarpod
-
To create a pod from a YAML code
kubectl create -f filename.yml
-
Now, if you want to create a ReplicaSet or ReplicationController, it will be created by the YAML code only. You'll find both codes in the above repo.
kubectl create -f ymlfilename.yml
Note
If you want to create anything using a YAML file, use the command with the YAML file name like 'kubectl apply -f youryamlfilename.yml'.
-
To create more ReplicationController(rc) after after
kubectl scale --replicas=3 rc/azfar-replicationcontroller
- This command is help you. Suppose you've already created only one ReplicationController, and you want to create more. In that case, you can use the above command👆
-
To check the services(svc) in cluster
kubectl get svc
-
To create your own svc by the ReplicationController
kubectl expose --type=NodePort --port=80 rc/azfar-replication-controller
-
This configuration depends on the type you want to create. If you prefer creating it with a ClusterIP instead of a NodePort, replace it. Then, specify the type's name on the cluster. You can explore more options by checking this below command 👇
kubectl expose --help
-
-
To see the port and much more about your services
kubectl describe svc azfar-replication-controller
-
To Retrieve the cluster's IP address for accessing deployed services
minikube ip
-
TO check StorageClass
kubectl get sc
- It retrieve information about the StorageClasses in your Kubernetes cluster. It provides details about the available storage classes, such as their name, provisioner, parameters, and other relevant information.
-
To check the PersistenceVolumeClaim
kubectl get pvc
- This command displays information about the PersistentVolumeClaims in the cluster. It shows details like the name of the PVC, the associated volume, the storage capacity requested and allocated, the status of the claim, and more.
-
To check only PersistenceVolume
kubectl get pv
- It provides information about the PersistentVolumes in the cluster. It includes details such as the name of the PV, its capacity, access modes, status, and the PersistentVolumeClaim it might be bound to.
-
To check deploy
kubectl get deploy
- is used to retrieve information about the Deployments in your Kubernetes cluster. Deployments are a higher-level abstraction for managing and updating a set of pods in your cluster.
-
To see the history of rollout
kubectl rollout history deploy azfard
- it will provide you with a historical record of deployments and revisions associated with the "azfard" Deployment. It includes information such as revision numbers, deployment status, and the date and time of each deployment.
-
To check the status of the rollout
kubectl rollout status deploy azfard
- When you run this command, it will provide real-time information about the status of the ongoing rollout. It will show you whether the update is still in progress, has successfully completed, or if there are any issues.
In the context of Kubernetes, a "rollout" typically refers to the process of updating or rolling out a new version of an application or a set of resources in a controlled and incremental manner. The goal is to minimize downtime and ensure a smooth transition from the old version to the new one.
-
To create new secrets and password
kubectl create secret generic azfarsecret --from-literal=p=redhat --from-literal=u=azfar
-
The kubectl create secret generic command you provided is used to create a generic secret named "azfarsecret" in Kubernetes. This secret contains two key-value pairs:
--> key: p (for password), Value: redhat
--> Key: u (for username), Value: azfar
This command creates a secret with these key-value pairs and stores them securely in the cluster. Secrets are often used to store sensitive information such as passwords, API keys, and other confidential data.
-
-
To check secrets
kubectl get secrets
- It is used to retrieve information about the secrets in your Kubernetes cluster. When you run this command without specifying a particular secret, it will display a list of all secrets in the default namespace.
-
To check namespace
kubectl get ns
-
The kubectl get ns command is used to retrieve information about the namespaces in your Kubernetes cluster. When you run this command, it will display a list of all the namespaces along with details such as the name of the namespace and its status.
Namespaces in Kubernetes provide a way to organize and isolate resources within a cluster. They are particularly useful for managing and segregating applications or environments.
-
-
To check the status of clusterrole
kubectl get clusterrole
- it will display a list of ClusterRoles along with details such as the name of the ClusterRole, the age, and other relevant information.
-
To get rolebinding
kubectl get rolebinding -n testing
- This command is used to retrieve information about RoleBindings in the specific namespace "testing" in your Kubernetes cluster. RoleBindings are used to bind roles to subjects (such as users or service accounts) within a specific namespace.
-
to test rolebinding
kubectl describe rolebinding -n testing
-
When you run this command, it will display information such as:
--> Name of the RoleBinding
--> Namespace it belongs to ("testing" in this case)
--> Role associated with the RoleBinding
--> Subjects (users, groups, or service accounts) bound by the RoleBinding
--> Creation timestamp
--> Other relevant details about the RoleBinding configuration
-
-
To create new configmap attaching your own port in the .txt file
kubectl create configmap azfarcm --from-file myweb.txt
-
It is used to create a ConfigMap named "azfarcm" in your Kubernetes cluster. This ConfigMap is populated with the contents of a file named "myweb.txt."
-->
kubectl create configmap
Initiates the creation of a ConfigMap.-->
azfarcm
Specifies the name of the ConfigMap as "azfarcm."-->
--from-file myweb.txt:
Populates the ConfigMap with the contents of the "myweb.txt" file.- ConfigMaps are useful for storing configuration data that can be consumed by pods in a Kubernetes cluster.
-
Kubernetes Ingress is a set of rules that manage external access to the services in a Kubernetes cluster. It is an API object that allows you to configure routing protocols, typically via HTTPS/HTTP. By using Ingress, you can consolidate your routing rules into a single resource.
-
To check Ingress
minikube addons enable ingress
-
Verify that the NGINX Ingress controller is running
kubectl get pods -n ingress-nginx
Note
It can take up to a minute before you see these pods running OK.
-
To check Ingress
kubectl get ingress
- It is used to retrieve information about Ingress resources in your Kubernetes cluster. Ingress is an API object that provides HTTP and HTTPS routing to services based on rules.
To know more about the Ingress-Minikube then visit once Kubernetes-Ingress here you will get the whole command as well as yaml code also so visit once Kubernetes-Ingress
-
To check network policy
kubectl get networkpolicy
-
To check the services in Kubernetes
kubectl api-resources
- It display a list of available API resources in your Kubernetes cluster. When you run this command, it provides a list of resource types along with their short names, API group, and whether they are namespaced.
-
To get CustomResourceDefinitions
kubectl get crd
- To retrieve information about CustomResourceDefinitions (CRDs) in your Kubernetes cluster. CRDs allow you to define custom resources and their behavior in a Kubernetes cluster, extending the API and enabling the creation of custom resources.
This is all that I've covered, but it's not exhaustive. It was just the basics. If you want to know more about Kubernetes, feel free to ask anything. I love to help you. You can contact me on LinkedIn or Discord