/kubernetes-conc

In this repo, you'll find all the concepts of Kubernetes: lab setup, introduction to Kubernetes, basic commands, and also important YAML code that allows you to easily create pods, ReplicaSets, and much more. So, what are you waiting for? Just visit the repo for more info.

What is Kubernetes?

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.

In Summary -

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.

Set up Kubernetes by installing Minikube:

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*

Basic Important Commands in Kubernetes -

  1. Creation of Pods

    kubectl run azfarpod --image=httpd
  2. To check the Pods

    kubectl get pods
  3. To delete a Pods

    kubectl delete pods --all 

    or

    kubectl delete pods azfarpod
  4. To create a pod from a YAML code

      kubectl create -f filename.yml
  5. 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'.

  1. 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👆
  2. To check the services(svc) in cluster

    kubectl get svc
  3. 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
  4. To see the port and much more about your services

    kubectl describe svc azfar-replication-controller
  5. To Retrieve the cluster's IP address for accessing deployed services

    minikube ip
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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.

What is Rollout?

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.

  1. 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.

  2. 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.
  3. 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.

  4. 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.
  5. 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.
  6. 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

  7. 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.

What is Kubernetes Ingress?

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.

  1. To check Ingress

    minikube addons enable ingress
  2. 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.

  1. 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

  1. To check network policy

    kubectl get networkpolicy

Important Commands in Kubernetes which you should known about -

  1. 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.
  2. 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

Keep Learning & Sharing.. ✨