For English- Click here amd watch from 48:44 Timestamp
Kubernetes imperative commands are more useful and make your work easier especially when you want to work faster or save time. if you are giving exams like CKA, you must be aware of this to save lot of time.
since we have have used microk8s, let us use alias command or .bashrc file, please do note that if you have updated alias command in .bashrc, we don't need to run alias command everytime we turn on the server
case1: run alias command every time you log into server
alias kubectl="microk8s kubectl"
case2: Update the command in .bashrc file so we don't have to run command every time we login
sudo vi .bashrc
Note: Do not disturb any other contents of the file.
once you placed the command, sign out and sign in to user, you can simply switch to any other user and login to our user for changes to take place
sudo su - root
sudo su - ubuntu
Now lets start with commands, for our practise, we recommend creating seperate namespace first as not to disturb existing resources
kubectl create ns practise
case1: to make pod up directly
kubectl run podname --image=nginx -n practise
In place of podname, you can give any of your desired name, in image, you have to give image that you created or that already exists in dockerhub. i am taking nginx as an image for example, and -n flag stands for namespace
As you can see this command created pod directly, you can verify with this command
kubectl get pods -n practise
Now if you don't want to run the pods, rather check what does command do, run the command
kubectl run podname --image=nginx -n practise --dry-run=client -o yaml > manifest.yaml
now you can edit the file
sudo vi manifest.yaml
here i have made changes like podname to podname2 , and image nginx to alpine2.once the changes are done, run the command
kubectl apply -f manifest.yaml
in case you forgot any command, if you had remember first lines of command , you can use help command
kubectl run --help
In case the pod is already running and you want to check the detailed information of pod
kubectl describe pod podname -n practise
kubectl logs -f podname -n practise
kubectl edit pod podname -n practise
Play with these commands to get real-time practise
Similarly for Service:
kubectl create service clusterip service-name --tcp=8080:80 -n practise
once you are done with practise, delete namespace to delete all your resources at once
To check what is present in your namespace.
kubectl get all -n practise
kubectl delete ns practise
Note: Deleting namespace is never recommended in real-time scenarios
##I Post most of my content in Telugu related to contrafactums(changing
lyrics to original songs),fun vlogs, Travel stories and much more to
explore, You can subscribe here at
sagar kakkala's world Youtube,You can also follow me on other sites
Sagar Kakkala LinkedIn,
Sagar Kakkalas world Instagram
Entertainment meme Page ##
🖊feedback,queries and suggestions about blog are welcome in the
comments.
Comments
Post a Comment