apiVersion: v1
kind: Namespace
metadata:
name: devns
below command will help us to create the object/resource
kubectl create -f /opt/yaml-files/ns.yaml
kubectl get ns will give us the list of the namespaces which are there in the cluster.
same way we will have a look on the imperative methodology to create namespace, so for that i'm deleting the namespace and will create with the help of imperative methodology,
Now Imperative methodology, i did not provided any manifest file or declarative steps to create. just given below command it will create namespace with DEVNS.
kubectl create ns devns
kubectl get ns
Now i would like to jump in to the Kubectl commands on each objects/Resources.
Nodes:
To list out the nodes from the cluster use: kubectl get nodes
To watch the node status on every second use : watch -n1 kubectl get nodes
To watch the node status on every 2 seconds use : watch kubectl get nodes
TO fetch the more details of the Nodes use: kubectl describe nodes worker-01
To list the only Worker Nodes : kubectl get node --selector='!node-role.kubernetes.io/master'
POD:
we can create the resources/objects with both the ways which we discussed above.
To list the Pods use : kubectl get pods (initially there was no pods)
To Create the pod with Declarative methodology:
create a file using yaml file: vi /opt/yaml-files/pod.yaml add below content and save.
apiVersion: v1
kind: Pod
metadata:
name: cafe-app
spec:
containers:
- image: nginxdemos/hello
name: cafe
now execute the manifest file to create the POD object.
kubectl create -f pod.yaml
now see the list of the pods running on the cluster: kubectl get pods
To Create the pod with Imperative methodology:
same Image i used to create the pod by Imperative command.
so we can create/delete/modify/ our objects both the ways.
some more Commands to use on the pods:
To fetch the more details of the POD use : kubectl describe pod cafe-app
To list all pods in all namespaces : kubectl get pods --all-namespaces
To list all pods in the current namespace, with more details : kubectl get pods -o wide
To get a pod's YAML : kubectl get pod my-pod -o yaml
To get a pod's JSON : kubectl get pod my-pod -o json
To delete pod : kubectl delete -f pod.yaml (OR) kubectl delete pod <POD_NAME>
To see the logs of the pod use : kubectl logs <POD_NAME>
To login to the pod : kubectl exec -it centos-pod -- /bin/bash
To see the Process running on the pod : kubectl exec <POD_NAME> -- ps
To Show the labels for all the pods: kubectl get pods --show-labels
To Edit the pod : Kubectl edit pod <POD_NAME>
No comments:
Post a Comment