We will run our first pod with
kubectl run my-frontend --image blog-frontend:0.1To check that it is running we can do
kubectl get podsWe should see that it has STATUS Running
We can also check the logs of the running pod with
kubectl logs my-frontendTo temporarily expose the frontend on localhost we can run the following command
kubectl port-forward pod/my-frontend 8045:8045and let it run. Then it is possible to access the frontend on http://localhost:8045
kubectl delete pod my-frontendWe can use the same command as in the first section, but append --dry-run=client and -o yaml to get a yaml template, which is what kubernetes uses as IaC.
In the following command we also pipe the output into a file:
kubectl run my-frontend --image blog-frontend:0.1 --dry-run=client -o yaml > frontend-pod.yamlWith the above command, the pod does not get scheduled to the cluster, and we need to apply the yaml definition to get the pod in the cluster with
kubectl apply -f frontend-pod.yamlTo check that it is running we can again do
kubectl get podsWe can delete the pod again with
kubectl delete -f frontend-pod.yamlCheck that there is no pod running with
kubectl get podsand delete the frontend-pod.yaml
rm frontend-pod.yaml