Skip to content

Commit 9068e70

Browse files
committed
Update content/en/docs/tasks/access-application-cluster/port-forward-access-application-cluster.md
Update page port-forward-access-application-cluster.md to use MongoDB examples instead of Redis examples Commit 99029b9 removes the Redis examples. Signed-off-by: Jailton Lopes <[email protected]>
1 parent 641e7c0 commit 9068e70

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

content/en/docs/tasks/access-application-cluster/port-forward-access-application-cluster.md

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ min-kubernetes-server-version: v1.10
77

88
<!-- overview -->
99

10-
This page shows how to use `kubectl port-forward` to connect to a Redis
10+
This page shows how to use `kubectl port-forward` to connect to a MongoDB
1111
server running in a Kubernetes cluster. This type of connection can be useful
1212
for database debugging.
1313

@@ -19,25 +19,25 @@ for database debugging.
1919

2020
* {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
2121

22-
* Install [redis-cli](http://redis.io/topics/rediscli).
22+
* Install [MongoDB Shell](https://www.mongodb.com/try/download/shell).
2323

2424

2525

2626

2727
<!-- steps -->
2828

29-
## Creating Redis deployment and service
29+
## Creating MongoDB deployment and service
3030

31-
1. Create a Deployment that runs Redis:
31+
1. Create a Deployment that runs MongoDB:
3232

3333
```shell
34-
kubectl apply -f https://k8s.io/examples/application/guestbook/redis-master-deployment.yaml
34+
kubectl apply -f https://k8s.io/examples/application/guestbook/mongo-deployment.yaml
3535
```
3636

3737
The output of a successful command verifies that the deployment was created:
3838

3939
```
40-
deployment.apps/redis-master created
40+
deployment.apps/mongo created
4141
```
4242

4343
View the pod status to check that it is ready:
@@ -49,8 +49,8 @@ for database debugging.
4949
The output displays the pod created:
5050

5151
```
52-
NAME READY STATUS RESTARTS AGE
53-
redis-master-765d459796-258hz 1/1 Running 0 50s
52+
NAME READY STATUS RESTARTS AGE
53+
mongo-75f59d57f4-4nd6q 1/1 Running 0 2m4s
5454
```
5555

5656
View the Deployment's status:
@@ -62,8 +62,8 @@ for database debugging.
6262
The output displays that the Deployment was created:
6363
6464
```
65-
NAME READY UP-TO-DATE AVAILABLE AGE
66-
redis-master 1/1 1 1 55s
65+
NAME READY UP-TO-DATE AVAILABLE AGE
66+
mongo 1/1 1 1 2m21s
6767
```
6868
6969
The Deployment automatically manages a ReplicaSet.
@@ -76,90 +76,90 @@ for database debugging.
7676
The output displays that the ReplicaSet was created:
7777
7878
```
79-
NAME DESIRED CURRENT READY AGE
80-
redis-master-765d459796 1 1 1 1m
79+
NAME DESIRED CURRENT READY AGE
80+
mongo-75f59d57f4 1 1 1 3m12s
8181
```
8282
8383
84-
2. Create a Service to expose Redis on the network:
84+
2. Create a Service to expose MongoDB on the network:
8585
8686
```shell
87-
kubectl apply -f https://k8s.io/examples/application/guestbook/redis-master-service.yaml
87+
kubectl apply -f https://k8s.io/examples/application/guestbook/mongo-service.yaml
8888
```
8989
9090
The output of a successful command verifies that the Service was created:
9191
9292
```
93-
service/redis-master created
93+
service/mongo created
9494
```
9595
9696
Check the Service created:
9797
9898
```shell
99-
kubectl get service redis-master
99+
kubectl get service mongo
100100
```
101101
102102
The output displays the service created:
103103
104104
```
105-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
106-
redis-master ClusterIP 10.0.0.213 <none> 6379/TCP 27s
105+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
106+
mongo ClusterIP 10.96.41.183 <none> 27017/TCP 11s
107107
```
108108
109-
3. Verify that the Redis server is running in the Pod, and listening on port 6379:
109+
3. Verify that the MongoDB server is running in the Pod, and listening on port 27017:
110110
111111
```shell
112-
# Change redis-master-765d459796-258hz to the name of the Pod
113-
kubectl get pod redis-master-765d459796-258hz --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'
112+
# Change mongo-75f59d57f4-4nd6q to the name of the Pod
113+
kubectl get pod mongo-75f59d57f4-4nd6q --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'
114114
```
115115
116-
The output displays the port for Redis in that Pod:
116+
The output displays the port for MongoDB in that Pod:
117117
118118
```
119-
6379
119+
27017
120120
```
121121
122-
(this is the TCP port allocated to Redis on the internet).
122+
(this is the TCP port allocated to MongoDB on the internet).
123123
124124
## Forward a local port to a port on the Pod
125125
126126
1. `kubectl port-forward` allows using resource name, such as a pod name, to select a matching pod to port forward to.
127127
128128
129129
```shell
130-
# Change redis-master-765d459796-258hz to the name of the Pod
131-
kubectl port-forward redis-master-765d459796-258hz 7000:6379
130+
# Change mongo-75f59d57f4-4nd6q to the name of the Pod
131+
kubectl port-forward mongo-75f59d57f4-4nd6q 28015:27017
132132
```
133133
134134
which is the same as
135135
136136
```shell
137-
kubectl port-forward pods/redis-master-765d459796-258hz 7000:6379
137+
kubectl port-forward pods/mongo-75f59d57f4-4nd6q 28015:27017
138138
```
139139
140140
or
141141
142142
```shell
143-
kubectl port-forward deployment/redis-master 7000:6379
143+
kubectl port-forward deployment/mongo 28015:27017
144144
```
145145
146146
or
147147
148148
```shell
149-
kubectl port-forward replicaset/redis-master 7000:6379
149+
kubectl port-forward replicaset/mongo-75f59d57f4 28015:27017
150150
```
151151
152152
or
153153
154154
```shell
155-
kubectl port-forward service/redis-master 7000:redis
155+
kubectl port-forward service/mongo 28015:27017
156156
```
157157
158158
Any of the above commands works. The output is similar to this:
159159
160160
```
161-
Forwarding from 127.0.0.1:7000 -> 6379
162-
Forwarding from [::1]:7000 -> 6379
161+
Forwarding from 127.0.0.1:28015 -> 27017
162+
Forwarding from [::1]:28015 -> 27017
163163
```
164164
165165
{{< note >}}
@@ -168,22 +168,22 @@ for database debugging.
168168
169169
{{< /note >}}
170170
171-
2. Start the Redis command line interface:
171+
2. Start the MongoDB command line interface:
172172
173173
```shell
174-
redis-cli -p 7000
174+
mongosh --port 28015
175175
```
176176
177-
3. At the Redis command line prompt, enter the `ping` command:
177+
3. At the MongoDB command line prompt, enter the `ping` command:
178178
179179
```
180-
ping
180+
db.runCommand( { ping: 1 } )
181181
```
182182
183183
A successful ping request returns:
184184
185185
```
186-
PONG
186+
{ ok: 1 }
187187
```
188188
189189
### Optionally let _kubectl_ choose the local port {#let-kubectl-choose-local-port}
@@ -193,24 +193,31 @@ the local port and thus relieve you from having to manage local port conflicts,
193193
the slightly simpler syntax:
194194

195195
```shell
196-
kubectl port-forward deployment/redis-master :6379
196+
kubectl port-forward deployment/mongo :27017
197+
```
198+
199+
The output is similar to this:
200+
201+
```
202+
Forwarding from 127.0.0.1:63753 -> 27017
203+
Forwarding from [::1]:63753 -> 27017
197204
```
198205
199206
The `kubectl` tool finds a local port number that is not in use (avoiding low ports numbers,
200207
because these might be used by other applications). The output is similar to:
201208
202209
```
203-
Forwarding from 127.0.0.1:62162 -> 6379
204-
Forwarding from [::1]:62162 -> 6379
210+
Forwarding from 127.0.0.1:63753 -> 27017
211+
Forwarding from [::1]:63753 -> 27017
205212
```
206213
207214
208215
<!-- discussion -->
209216
210217
## Discussion
211218
212-
Connections made to local port 7000 are forwarded to port 6379 of the Pod that
213-
is running the Redis server. With this connection in place, you can use your
219+
Connections made to local port 28015 are forwarded to port 27017 of the Pod that
220+
is running the MongoDB server. With this connection in place, you can use your
214221
local workstation to debug the database that is running in the Pod.
215222
216223
{{< note >}}

0 commit comments

Comments
 (0)