|
| 1 | +To build the Docker image, run the following command: |
| 2 | + |
| 3 | +This command creates a local image named `hello_kube` with the tag version `1.0.0`. |
| 4 | + |
| 5 | +```sh |
| 6 | +docker buildx build -t hello_kube:1.0.0 . |
| 7 | +``` |
| 8 | + |
| 9 | +The following command tags the local image with your remote registry username, making it ready to push to the repository. Please replace `aaghamohammadi` with your current registry username for the following commands. |
| 10 | + |
| 11 | +```sh |
| 12 | +docker tag hello_kube:1.0.0 aaghamohammadi/hello_kube:1.0.0 |
| 13 | +``` |
| 14 | + |
| 15 | +Make sure you log in to your registry in order to push the image. |
| 16 | + |
| 17 | +```sh |
| 18 | +docker push aaghamohammadi/hello_kube:1.0.0 |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | +You can run a simple Pod using an imperative command, although it is not recommended. In the future, we will learn other ways (i.e., declarative) to run pods. |
| 23 | + |
| 24 | +The following command runs a pod named `hello-kube` with a single container in it. The restart policy for the pod is determined by the `--restart` flag. Legal values are `["Always", "OnFailure", "Never"]`. The default value is `"Always"`. |
| 25 | + |
| 26 | +```sh |
| 27 | +kubectl run hello-kube --image=aaghamohammadi/hello_kube:1.0.0 --restart=Never |
| 28 | +``` |
| 29 | + |
| 30 | +You can list all the pods in the current cluster using: |
| 31 | + |
| 32 | +```sh |
| 33 | +kubectl get pods |
| 34 | +``` |
| 35 | + |
| 36 | +The `describe` command shows details of a specific resource like a pod. It provides detailed information about a single pod, including its IP address and the node it is running on. |
| 37 | + |
| 38 | +```sh |
| 39 | +kubectl describe pod hello-kube |
| 40 | +``` |
| 41 | + |
| 42 | +To get the full JSON output of a pod, you can use the following command. This is useful for debugging and understanding the pod's configuration and status in detail. |
| 43 | + |
| 44 | +```sh |
| 45 | +kubectl get pod hello-kube -o json |
| 46 | +``` |
| 47 | + |
| 48 | +Kubectl can forward traffic from a node to a Pod, which is a quick way to communicate with a Pod from outside the cluster. |
| 49 | + |
| 50 | +```sh |
| 51 | +kubectl port-forward pod/hello-kube 8080:80 |
| 52 | +``` |
| 53 | + |
| 54 | +Now, browse to `localhost:8080` in your browser. |
| 55 | + |
| 56 | +To remove the pod and return your Kubernetes environment to a clean state, you can use the following command: |
| 57 | + |
| 58 | +```sh |
| 59 | +kubectl delete pod hello-kube |
| 60 | +``` |
0 commit comments