diff --git a/docs/tasks/access-application-cluster/port-forward-access-application-cluster.md b/docs/tasks/access-application-cluster/port-forward-access-application-cluster.md index 909dc31e10ae7..d5a9fa0aee039 100644 --- a/docs/tasks/access-application-cluster/port-forward-access-application-cluster.md +++ b/docs/tasks/access-application-cluster/port-forward-access-application-cluster.md @@ -22,53 +22,93 @@ for database debugging. {% capture steps %} -## Creating a pod to run a Redis server +## Creating Redis deployment and service -1. Create a pod: +1. Create a Redis deployment: - kubectl create -f https://k8s.io/docs/tasks/access-application-cluster/redis-master.yaml + kubectl create -f https://k8s.io/docs/tutorials/stateless-application/guestbook/redis-master-deployment.yaml - The output of a successful command verifies that the pod was created: + The output of a successful command verifies that the deployment was created: - pod "redis-master" created + deployment "redis-master" created + + When the pod is ready, you can get: + + kubectl get pods -1. Check to see whether the pod is running and ready: + NAME READY STATUS RESTARTS AGE + redis-master-765d459796-258hz 1/1 Running 0 50s - kubectl get pods + kubectl get deployment + + NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE + redis-master 1 1 1 1 55s + + kubectl get rs + NAME DESIRED CURRENT READY AGE + redis-master-765d459796 1 1 1 1m + + +2. Create a Redis service: + + kubectl create -f https://k8s.io/docs/tutorials/stateless-application/guestbook/redis-master-service.yaml + + The output of a successful command verifies that the service was created: + + service "redis-master" created + + Check the service created: - When the pod is ready, the output displays a STATUS of Running: + kubectl get svc | grep redis - NAME READY STATUS RESTARTS AGE - redis-master 2/2 Running 0 41s + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + redis-master ClusterIP 10.0.0.213 6379/TCP 27s -1. Verify that the Redis server is running in the pod and listening on port 6379: +3. Verify that the Redis server is running in the pod and listening on port 6379: {% raw %} - kubectl get pods redis-master --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}' + kubectl get pods --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}' {% endraw %} The output displays the port: 6379 + ## Forward a local port to a port on the pod -1. Forward port 6379 on the local workstation to port 6379 of redis-master pod: +1. `kubectl port-forward` allows using resource name to select a matching pod and supports specifying a service to port forward to since Kubernetes v1.10. + + kubectl port-forward redis-master-765d459796-258hz 6379:6379 + + which is the same as + + kubectl port-forward pods/redis-master-765d459796-258hz 6379:6379 + + or + + kubectl port-forward deployment/redis-master 6379:6379 + + or + + kubectl port-forward rs/redis-master 6379:6379 + + or - kubectl port-forward redis-master 6379:6379 + kubectl port-forward svc/redis-master 6379:6379 - The output is similar to this: + Any of the above commands works. The output is similar to this: I0710 14:43:38.274550 3655 portforward.go:225] Forwarding from 127.0.0.1:6379 -> 6379 I0710 14:43:38.274797 3655 portforward.go:225] Forwarding from [::1]:6379 -> 6379 -1. Start the Redis command line interface: +2. Start the Redis command line interface: - redis-cli + redis-cli -1. At the Redis command line prompt, enter the `ping` command: +3. At the Redis command line prompt, enter the `ping` command: - 127.0.0.1:6379>ping + 127.0.0.1:6379>ping A successful ping request returns PONG.