After your labsetup
check the minikube status
system where the kubernetes server run is also known control plane.
This setup i have early done in my previous blog
visit : https://mayank2001.hashnode.dev/kubernetes-lab-setup
let say I am the user having IP address 192.45.12.12 and k8s server having IP 101.48.24.24
whenever as a client connect to the server it connect to the certain portnumber and this port number running on a process called kube API server
as a user i am going to send my requirement that what i want to do let say i ask them to launch one port or five ports.
so all the requirements are sent to kube API server by internally by kubectl.
check the cluster info
since you have proper connectivity with control plane means your server and it connected to port number 8443.
To check the pods running the command is :
kubectl.exe get pods
and to launch the pod == container we require an image so we have to write the image name
so to launch the container the command is :
kubectl.exe run myweb --image=httpd
now to check pod is created or not
use : kubectl.exe get pods
when you launch first time it takes sometimes to run
kubectl.exe run (Pod name ) (image name)
to check the status of pods running
kubectl get pods
to check every information of all pods are
kubectl describe pods
so overall we send the instruction through kubectl
whenever you use this command internally it convert into some kind of code and this code they actually submit to API server
so if you know to generate the code then we can do thing deeply
if we check the description of kubectl
command check it kubectl.exe -h
so we must know how to write the code
we as a user kubernetes say I only know code written in YAML language. so as a user you have to create or write the code and submit the code to kubernetes.
YAML ( yet another markup language)
YAML files use a .yml or .yaml extension, YAML is also a superset of JSON, so JSON files are valid in YAML.
since phone as element like we use list in python but if we want to write it in yaml
in phone is a key and it has three values represented by -
here we use key value pair for example in this ๐๐ age: 26 is key value pair
here indentation tell it belong to same key like in programming language we make the one function in curly bracket for saying that information is completed and if we want to make another function we use another set of curly bracket .
since every time you use same path to use the command kubectl and minikube etc
so lets add it in enviroment of windows so that we can run these command from any path
just search the env
you will get to edit the enviroment variables control panel
click on enviromental variables then click path on upper window
then click to edit it and then click new and add it C:\Program Files\Kubernetes\Minikube
then click ok ok ok
so now you go to any folder and create the file run from anywhere
so first create the folder where you create the files
mkdir kubecontainer-2023
go to this folder and create file
lets check the pods running if yes remove it as we use to run a pod through YAML file
understand one thing guys pod is like a box we launch the container inside the pod
kubernetes doesn't launch the container directly it launch the container inside the pod
so lets start with launching the containers with the help of YAML code
a) first collect the information that what we want to do
--> like i want to create a pod with image httpd having name myweb what we want to do is creating container thats all we want
we can also name the pod also
here we are going to launch single container pod means one pod contain only one container after going deep we are able to launch multi-container pod means one pod contain multi containers these are different design patterns
Here containers are the specification .
The YAML code is defining the specifications (spec
) for the Pod. Within the spec
section, we define the containers that will run inside the Pod.
In this case, we have a single container defined under the containers
section. The container is given the name "myc1" using the name
property.
The -image="httpd"
line specifies the image to be used for the container. In this case, the image being used is "httpd". "httpd" is the official Apache HTTP Server image, which is commonly used for hosting websites and serving web content.
In kubectl
when you check the helpsection we have so much things
so in yaml how we can tell that we want pod association
for this we a keyword kind
as a key and value pair is pod and name of pod is under metadata
In yaml take care of indentation
so this is our yaml code lets save it and run it and see if some error arises
we have to run this file
we use kubectl.exe create -f first_pod.yml
create means we want to create something and -f for filename
so lets run and check the error
we have two errors as i don't tell the apiversion and second syntax error that is indentation error . To check the error write the code in vscode for YAML
again with error lets resolve it . here is the error in 9th line we have give space after - name
lets run again
this run successfully and pod get created . so lets check the status.
if you have deploy you can see here through kubectl get deploy
lets take more information about the pods running
use kubectl describe pods
you can check if any error cause then check it under event section . it will tell the reason
you can launch another pod with same file by changing the file name
to check the status of particular pods
kubectl get pods/mypod1
same thing describe
kubectl describe pods/podname
so we successfully launch our first pod with the help of code. our today motive is complete.
I hope you guys enjoys the blog do share and like it
want to connect with me
My Contact Info:
๐ฉEmail:- mayank07082001@gmail.com
LinkedIn:- linkedin.com/in/mayank-sharma-devops