Kubernetes > Run > Pods
We can create a Pod straight away from the command line without defining it in a yaml file, this can be thought of as Imperative mode
To view the list of Pods
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get pods
No resources found.
To create a Pod in imperative mode with name pod1 and the container image as busybox
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl run pod1 --generator=run-pod/v1 --image=busybox
pod/pod1 created
To view the list of Pods again
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get pods
NAME READY STATUS RESTARTS AGE
pod1 0/1 CrashLoopBackOff 1 7s
One more time
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get pods
NAME READY STATUS RESTARTS AGE
pod1 0/1 Completed 2 20s
To see the complete details of the Pod in yaml format, though we have not defined it initially in yaml in a declarative way
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get pod pod1 -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
kubernetes.io/limit-ranger: 'LimitRanger plugin set: cpu request for container
pod1'
creationTimestamp: 2019-03-29T04:09:16Z
labels:
run: pod1
name: pod1
namespace: default
resourceVersion: "2663"
selfLink: /api/v1/namespaces/default/pods/pod1
uid: 6afd684a-51d8-11e9-a0b9-42010a8001a3
spec:
containers:
- image: busybox
imagePullPolicy: Always
name: pod1
resources:
requests:
cpu: 100m
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-p8752
readOnly: true
--TRUNCATED--
To delete the Pod
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl delete pod pod1
pod "pod1" deleted
The Pod list should now be empty
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get pods
No resources found.
Reference: https://subscription.packtpub.com/video/networking_and_servers/9781789531565/65894/65899/lab-creating-pods-imperatively?uuid=034ba50c-bfea-46e9-89e4-b01aa655bede
--end-of-post--