Skip to content

Commit 1de3503

Browse files
add lecture 002 materials
0 parents  commit 1de3503

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

lec002/hello_kube/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx:1.27.3-alpine
2+
COPY html/ /usr/share/nginx/html/

lec002/hello_kube/README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
```

lec002/hello_kube/html/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<h1>Hello everybody! I'm Alireza from @GolemCourse</h1>
4+
<h2>Happy learning Kubernetes!</h2>
5+
</body>
6+
</html>

0 commit comments

Comments
 (0)