Skip to content

Commit 805f2c7

Browse files
islinwbk8s-ci-robot
authored andcommitted
Update port-forwarding docs (#7575)
1 parent c431b28 commit 805f2c7

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

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

+59-19
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,93 @@ for database debugging.
2222

2323
{% capture steps %}
2424

25-
## Creating a pod to run a Redis server
25+
## Creating Redis deployment and service
2626

27-
1. Create a pod:
27+
1. Create a Redis deployment:
2828

29-
kubectl create -f https://k8s.io/docs/tasks/access-application-cluster/redis-master.yaml
29+
kubectl create -f https://k8s.io/docs/tutorials/stateless-application/guestbook/redis-master-deployment.yaml
3030

31-
The output of a successful command verifies that the pod was created:
31+
The output of a successful command verifies that the deployment was created:
3232

33-
pod "redis-master" created
33+
deployment "redis-master" created
34+
35+
When the pod is ready, you can get:
36+
37+
kubectl get pods
3438

35-
1. Check to see whether the pod is running and ready:
39+
NAME READY STATUS RESTARTS AGE
40+
redis-master-765d459796-258hz 1/1 Running 0 50s
3641

37-
kubectl get pods
42+
kubectl get deployment
43+
44+
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
45+
redis-master 1 1 1 1 55s
46+
47+
kubectl get rs
48+
NAME DESIRED CURRENT READY AGE
49+
redis-master-765d459796 1 1 1 1m
50+
51+
52+
2. Create a Redis service:
53+
54+
kubectl create -f https://k8s.io/docs/tutorials/stateless-application/guestbook/redis-master-service.yaml
55+
56+
The output of a successful command verifies that the service was created:
57+
58+
service "redis-master" created
59+
60+
Check the service created:
3861

39-
When the pod is ready, the output displays a STATUS of Running:
62+
kubectl get svc | grep redis
4063

41-
NAME READY STATUS RESTARTS AGE
42-
redis-master 2/2 Running 0 41s
64+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
65+
redis-master ClusterIP 10.0.0.213 <none> 6379/TCP 27s
4366

44-
1. Verify that the Redis server is running in the pod and listening on port 6379:
67+
3. Verify that the Redis server is running in the pod and listening on port 6379:
4568

4669
{% raw %}
47-
kubectl get pods redis-master --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'
70+
kubectl get pods redis-master-765d459796-258hz --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'
4871
{% endraw %}
4972

5073
The output displays the port:
5174

5275
6379
5376

77+
5478
## Forward a local port to a port on the pod
5579

56-
1. Forward port 6379 on the local workstation to port 6379 of redis-master pod:
80+
1. `kubectl port-forward` allows using resource name, such as a service name, to select a matching pod to port forward to since Kubernetes v1.10.
81+
82+
kubectl port-forward redis-master-765d459796-258hz 6379:6379
83+
84+
which is the same as
85+
86+
kubectl port-forward pods/redis-master-765d459796-258hz 6379:6379
87+
88+
or
89+
90+
kubectl port-forward deployment/redis-master 6379:6379
91+
92+
or
93+
94+
kubectl port-forward rs/redis-master 6379:6379
95+
96+
or
5797

58-
kubectl port-forward redis-master 6379:6379
98+
kubectl port-forward svc/redis-master 6379:6379
5999

60-
The output is similar to this:
100+
Any of the above commands works. The output is similar to this:
61101

62102
I0710 14:43:38.274550 3655 portforward.go:225] Forwarding from 127.0.0.1:6379 -> 6379
63103
I0710 14:43:38.274797 3655 portforward.go:225] Forwarding from [::1]:6379 -> 6379
64104

65-
1. Start the Redis command line interface:
105+
2. Start the Redis command line interface:
66106

67-
redis-cli
107+
redis-cli
68108

69-
1. At the Redis command line prompt, enter the `ping` command:
109+
3. At the Redis command line prompt, enter the `ping` command:
70110

71-
127.0.0.1:6379>ping
111+
127.0.0.1:6379>ping
72112

73113
A successful ping request returns PONG.
74114

0 commit comments

Comments
 (0)