This post shows how to create pods on Kubernetes cluster by kubectl command.
You hardly create pods by command directly, but rarely use such as on a test.
Create pod
(1) Run the following command to create a pod on a kubernetes cluster.
kubectl run app1 --image=user/app1 --port=8080 --restart=Never
--image : container image
-- port : listener port of container
--restart :
- Always (Default): Create a Deployment
- OnFailure: Create a Job
- Never: Create a normal Pod
It shows the following.
pod/app1 created
(2) Run the following command to confirm created pod.
kubectl get pods
It shows the following.
NAME READY STATUS RESTARTS AGE
app1 1/1 Running 0 5m14s
(3) Run the following command to confirm the node on which the pod works and pod’s ip address.
kubectl get pods -o wide
It shows the following
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
app1 1/1 Running 0 5m14s 10.45.0.3 node1 <none> <none>
NOTE: If you create a pod according to this post, you can access the above ip address 10.45.0.3 from only within the cluster.
Delete pod
Run the following command to delete a pod.
kubectl delete pod app1
It shows the following.
pod "app1" deleted
That’s about it.