You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+48-4
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,13 @@
1
1
## Learning Kubernetes
2
2
3
-
This is just a simple demonstration to get a basic understanding of how kubernetes works while working step by step.
3
+
This is just a simple demonstration to get a basic understanding of how kubernetes works while working step by step. We won't be going into depth about docker :blush: but will see sufficient content to get you basic understanding to learn and work with kuberntes. :v: Hope you enjoy learning. If you like it please give it a :star2:.
4
+
4
5
5
6
## Contents
6
7
7
8
1.[Requirements](#requirements)
8
9
2.**Docker**
9
-
-[What is docker](#what-is-docker?)
10
+
-[What is docker?](#what-is-docker)
10
11
-[Creating a web server](#creating-a-web-server)
11
12
-[Building docker image](#building-docker-image)
12
13
-[Getting docker images](#getting-docker-images)
@@ -38,6 +39,9 @@ This is just a simple demonstration to get a basic understanding of how kubernet
38
39
-[Examining a YAML descriptor of an existing pod](#examining-a-yaml-descriptor-of-an-existing-pod)
39
40
-[Introducing the main parts of a POD definition](#introducing-the-main-parts-of-a-pod-definition)
40
41
-[Creating a simple YAML descriptor for a pod](#creating-a-simple-yaml-descriptor-for-a-pod)
42
+
-[Using kubectl create to create the pod](#using-kubectl-create-to-create-the-pod)
43
+
-[Retrieving a PODs logs with Kubectl logs](#retrieving-a-pods-logs-with-kubectl-logs)
44
+
-[Forwarding a Local Network to a port in the Pod](#forwarding-a-local-network-to-a-port-in-the-pod)
41
45
42
46
## Requirements
43
47
@@ -47,7 +51,7 @@ This is just a simple demonstration to get a basic understanding of how kubernet
47
51
48
52
## Simple concepts before we start
49
53
50
-
#### What is docker?
54
+
#### What is docker
51
55
52
56
Docker is a platform for packaging, distribution and running applications. It allows you to package your application together with its whole environment. This can be either a few libraries that the app requires or even all the files that are usually available on the filesystem of an installed operating system. Docker makes it possible to transfer this package to a central repository from which it can then be transferred to any computer running Docker and executed there
53
57
@@ -399,7 +403,7 @@ Going through all the individual properties in the previous YAML doesn’t make
399
403
400
404
#### Creating a simple YAML descriptor for a pod
401
405
402
-
You’re going to create a file called kubia-manual.yaml (you can create it in any directory you want), or copy from this repo directory, where you’ll find the file inside the [PODS folder](https://github.com/knrt10/kubernetes-basicLearning/blob/master/PODS/kubia-manual.yaml). The following listing shows the entire contents of the file.
406
+
You’re going to create a file called kubia-manual.yaml (you can create it in any directory you want), or copy from this repo, where you’ll find the file with filename [kubia-manual.yaml](https://github.com/knrt10/kubernetes-basicLearning/blob/master/kubia-manual.yaml). The following listing shows the entire contents of the file.
403
407
404
408
```yaml
405
409
apiVersion: v1
@@ -416,3 +420,43 @@ spec:
416
420
```
417
421
418
422
Let’s examine this descriptor in detail. It conforms to the **v1** version of the Kubernetes API. The type of resource you’re describing is a pod, with the name **kubia-manual**. The pod consists of a single container based on the **knrt10/kubia** image. You’ve also given a name to the container and indicated that it’s listening on port **8080**.
423
+
424
+
#### Using kubectl create to create the pod
425
+
426
+
To create the pod from your YAML file, use the **kubectl create** command:
427
+
428
+
`kubectl create -f kubia-manual.yaml`
429
+
> pod/kubia-manual created
430
+
431
+
The **kubectl create -f** command is used for creating any resource (not only pods) from a YAML or JSON file.
432
+
433
+
#### Retrieving a PODs logs with Kubectl logs
434
+
435
+
Your little Node.js application logs to the process’s standard output. Containerized applications usually log to the standard output and standard error stream instead of writing their logs to files. This is to allow users to view logs of different applications in a simple, standard way.
436
+
437
+
To see your pod’s log (more precisely, the container’s log) you run the following command on your local machine (no need to ssh anywhere):
438
+
439
+
`kubectl logs kubia-manual`
440
+
> Kubia server starting...
441
+
442
+
You haven’t sent any web requests to your Node.js app, so the log only shows a single log statement about the server starting up. As you can see, retrieving logs of an application running in Kubernetes is incredibly simple if the pod only contains a single container.
443
+
444
+
##### Specifying the container name when getting logs of multiple container pod
445
+
446
+
If your pod includes multiple containers, you have to explicitly specify the container name by including the **-c container name** option when running **kubectl logs**. In your kubia-manual pod, you set the container’s name to **kubia**, so if additional containers exist in the pod, you’d have to get its logs like this:
447
+
448
+
`kubectl logs kubia-manual -c kubia`
449
+
450
+
Note that you can only retrieve container logs of pods that are still in existence. When a pod is deleted, its logs are also deleted.
451
+
452
+
#### Forwarding a Local Network to a port in the Pod
453
+
454
+
When you want to talk to a specific pod without going through a service (for debugging or other reasons), Kubernetes allows you to configure port forwarding to the pod. This is done through the **kubectl port-forward** command. The following command will forward your machine’s local port **8888** to port **8080** of your **kubia-manual** pod:
455
+
456
+
457
+
In a different terminal, you can now use curl to send an HTTP request to your pod through the kubectl port-forward proxy running on localhost:8888:
458
+
459
+
`curl localhost:8888`
460
+
> You've hit kubia-manual
461
+
462
+
Using port forwarding like this is an effective way to test an individual pod.
0 commit comments