-
Notifications
You must be signed in to change notification settings - Fork 288
Markdown linting and Langauge fixes #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c17db52
89b6670
a0c2785
fc4599f
c55c34a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,13 +10,13 @@ | |||||
|
|
||||||
| Deploying a pod is not enough to make it accessible from outside the cluster. | ||||||
|
|
||||||
| In this exercise you will learn how to make temporary connections to a pod inside the cluster via | ||||||
| In this exercise, you will learn how to make temporary connections to a pod inside the cluster via | ||||||
| `kubectl port-forward`. | ||||||
|
|
||||||
| ## Port-forward | ||||||
|
|
||||||
| The `kubectl port-forward` command allows you to forward one or more local ports to a pod. This can | ||||||
| be used to access a pod that is running in the cluster, using for example a web browser or a | ||||||
| be used to access a pod that is running in the cluster, using a web browser or a | ||||||
| command line tool like `curl`. | ||||||
|
|
||||||
| The command takes two arguments: the pod name and the port to forward. The port is specified as | ||||||
|
|
@@ -32,14 +32,16 @@ You can then access the pod on `localhost:8080`. | |||||
| <details> | ||||||
| <summary>:bulb: How does this port-forward work?</summary> | ||||||
|
|
||||||
| Port forwarding is a network address translation that redirects internet packets form one IP address | ||||||
| with specified port number to another `IP:PORT` set. | ||||||
| Port forwarding is a network address translation that redirects Internet packets from one IP address | ||||||
| to another with a specified port number to another `IP:PORT` set. | ||||||
|
|
||||||
| In Kubernetes `port-forward` creates a tunnel between your local machine and Kubernetes cluster on | ||||||
| the specified `IP:PORT` pairs in order to establish connection to the cluster. | ||||||
| `kubectl port-forward` allows you to forward not only pods but also services, deployments and other. | ||||||
| The `port-forward` command in Kubernetes forwards incoming traffic to the machine, the command is | ||||||
| executed on, to the specified `IP:PORT` pairs inside the Kubernetes cluster. This effectively | ||||||
| lets traffic from outside the cluster reach applications running inside the cluster. | ||||||
| `kubectl port-forward` allows you to forward traffic to pods, services, deployments, and others. | ||||||
|
|
||||||
| More information can be found from [here](https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/) | ||||||
| More information can be found in the Kubernetes docs at | ||||||
| [Use Port Forwarding to Access Applications in a Cluster](https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/) | ||||||
|
|
||||||
| </details> | ||||||
|
|
||||||
|
|
@@ -58,7 +60,7 @@ More information can be found from [here](https://kubernetes.io/docs/tasks/acces | |||||
|
|
||||||
| > :bulb: If you get stuck somewhere along the way, you can check the solution in the done folder. | ||||||
|
|
||||||
| ### Step by step instructions | ||||||
| ### Step-by-step instructions | ||||||
|
|
||||||
| <details> | ||||||
| <summary> | ||||||
|
|
@@ -78,7 +80,7 @@ The pod is defined in the `frontend-pod.yaml` file. | |||||
|
|
||||||
| </details> | ||||||
|
|
||||||
| - Check that the pod is running with `kubectl get pods` command. | ||||||
| - Use the `kubectl get pods` command to verify that the pod is running. | ||||||
|
|
||||||
| You should see something like this: | ||||||
|
|
||||||
|
|
@@ -87,32 +89,32 @@ NAME READY STATUS RESTARTS AGE | |||||
| frontend 1/1 Running 0 2m | ||||||
| ``` | ||||||
|
|
||||||
| - Expose the frontend with port-forward | ||||||
| - Expose the frontend with `port-forward` | ||||||
|
|
||||||
| Port forward can be achieved with: | ||||||
| Port forwarding can be achieved with: | ||||||
|
|
||||||
| `kubectl port-forward --address 0.0.0.0 frontend 8080:5000` | ||||||
|
|
||||||
| > :bulb: We add the `--address 0.0.0.0` option to the port-forward command to make it accept | ||||||
| > commands coming from remote machines, like your laptop! `0.0.0.0` Means any address, so you | ||||||
jbrejner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| > probably don't want to do this on your own machine in, unless you want to expose something | ||||||
| > probably don't want to do this on your machine unless you want to expose something | ||||||
| > to the internet. | ||||||
|
Comment on lines
+100
to
101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
|
||||||
| It can now be accessed on `http://workstation-<number>.<prefix>.eficode.academy:8080` | ||||||
| (from the internet). Notice the plain, unencrypted `http` connection. It is not `https`, and your | ||||||
| browser may complain about it. TLS is an advanced topic and out of scope for now. | ||||||
| browser may complain about it. TLS is an advanced topic and is currently out of scope. | ||||||
|
|
||||||
| > :bulb: VSCode will ask you if you what to see the open port. Unfortunately vscode proxy does not | ||||||
| > proxy requests correctly back to the pod, so use the URL of the instance instead. | ||||||
| :bulb: VSCode will prompt you to view the open port. Unfortunately, vscode proxy does not | ||||||
jbrejner marked this conversation as resolved.
Show resolved
Hide resolved
jbrejner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| > proxy requests correctly back to the pod, so use the URL of the workstation instance instead. | ||||||
|
|
||||||
| - Look at it in the browser. | ||||||
|
|
||||||
| Now we will deploy both the frontend and backend pods. | ||||||
|
|
||||||
| - Stop the port-forward process by pressing `Ctrl-c` in the terminal. | ||||||
| - Delete the frontend pod with `kubectl delete pod frontend` command. | ||||||
| - Deploy the backend pod with `kubectl apply -f backend-pod.yaml` command. | ||||||
| - Check that the pod is running, and note down the IP with `kubectl get pods -o wide` command. | ||||||
| - Delete the frontend pod with the `kubectl delete pod frontend` command. | ||||||
| - Deploy the backend pod with the `kubectl apply -f backend-pod.yaml` command. | ||||||
| - Check that the pod is running, and note down the IP with the `kubectl get pods -o wide` command. | ||||||
|
|
||||||
| You should see something like this: | ||||||
|
|
||||||
|
|
@@ -123,7 +125,7 @@ NAME READY STATUS RESTARTS AGE IP NODE | |||||
| backend 1/1 Running 0 11s 10.0.40.196 ip-10-0-35-102.eu-west-1.compute.internal <none> <none> | ||||||
| ``` | ||||||
|
|
||||||
| In this case the IP is `10.0.40.196`, but it will be different in your case. | ||||||
| In this case, the IP is `10.0.40.196`, but it will be different in your case. | ||||||
|
|
||||||
| #### Add environment variables to the frontend pod | ||||||
|
|
||||||
|
|
@@ -178,9 +180,9 @@ spec: | |||||
|
|
||||||
| </details> | ||||||
|
|
||||||
| - Deploy the frontend pod with `kubectl apply -f frontend-pod.yaml` command. | ||||||
| - Deploy the frontend pod with the `kubectl apply -f frontend-pod.yaml` command. | ||||||
|
|
||||||
| - Check that the pod is running with `kubectl get pods` command. | ||||||
| - Check that the pod is running with the `kubectl get pods` command. | ||||||
|
|
||||||
| - Forward a local port to the pod using `kubectl port-forward`. | ||||||
|
|
||||||
|
|
@@ -190,9 +192,9 @@ You should see something like this: | |||||
|
|
||||||
|  | ||||||
|
|
||||||
| (if you don't you might need to refresh the page) | ||||||
| (If you don't, you might need to refresh the page.) | ||||||
|
|
||||||
| - Exec into the frontend pod with `kubectl exec -it frontend -- /bin/sh` command. | ||||||
| - Exec into the frontend pod with the command `kubectl exec -it frontend -- /bin/sh`. | ||||||
|
|
||||||
| - Execute a curl command to the backend `curl http://<BACKEND_IP>:5000`. | ||||||
|
|
||||||
|
|
@@ -205,10 +207,10 @@ Extra exercise | |||||
|
|
||||||
| While still having the port-forward running | ||||||
|
|
||||||
| - Access the frontend in the browser and check that it still works and that frontend has access to | ||||||
| - Access the frontend in the browser and check that it still works and that the frontend has access to | ||||||
| the backend. | ||||||
| - Try to delete the backend pod with `kubectl delete pod backend` command. | ||||||
| - Try to recreate the backend pod with `kubectl apply -f backend-pod.yaml` command. | ||||||
| - Try to delete the backend pod with the command `kubectl delete pod backend`. | ||||||
| - Try to recreate the backend pod with the command `kubectl apply -f backend-pod.yaml`. | ||||||
| - Access the frontend in the browser. | ||||||
| - Does it still have access to the backend? | ||||||
|
|
||||||
|
|
@@ -218,10 +220,10 @@ If not, why not? | |||||
| <summary>Solution</summary> | ||||||
|
|
||||||
| The frontend pod is not configured to automatically re-resolve the backend IP address. | ||||||
| So when we deleted the pod, and recreated it, the IP address changed, but the frontend pod still | ||||||
| So when we deleted the pod and recreated it, the IP address changed, but the frontend pod still | ||||||
| has the old IP address in its environment variables. | ||||||
|
|
||||||
| Thankfully Kubernetes has a networking abstraction called `services` which solves this exact (and | ||||||
| Thankfully, Kubernetes has a networking abstraction called `services` which solves this exact (and | ||||||
| more!) problem, which we will learn about in the next exercise. | ||||||
|
|
||||||
| </details> | ||||||
|
|
@@ -230,9 +232,9 @@ more!) problem, which we will learn about in the next exercise. | |||||
|
|
||||||
| ### Clean up | ||||||
|
|
||||||
| - Stop the port-forward with `Ctrl+C` command. | ||||||
| - Delete the pod with `kubectl delete pod frontend` command. | ||||||
| - Delete the pod with `kubectl delete pod backend` command. | ||||||
| - Stop the port-forward with the `Ctrl+C` command. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| - Delete the pod with the `kubectl delete pod frontend` command. | ||||||
| - Delete the pod with the `kubectl delete pod backend` command. | ||||||
|
|
||||||
| Congratulations! You have now learned how to make temporary connections to a pod inside the cluster | ||||||
| via `kubectl port-forward`, and how to use environment variables to configure the pod. | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.