Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use kubectl port-forward in kubernetes

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to use kubectl port-forward in kubernetes, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

One: brief introduction

Kubectl port-forward uses port forwarding to map local ports to designated application ports to access applications in the cluster (Pod).

Two: give an example

1. Create a Pod to run the Redis server

a. Create a Pod:

Kubectl create-f https://k8s.io/docs/tasks/access-application-cluster/redis-master.yaml

After the command runs successfully, the following output verifies that the Pod has been created:

Pod "redis-master" created

b. Check to see if Pod is running and ready:

Kubectl get pods

When Pod is ready, the output shows the status of Running:

NAME READY STATUS RESTARTS AGE

Redis-master 2/2 Running 0 41s

c. Verify that the Redis server is running in Pod and listen on port 6379:

Kubectl get pods redis-master-- template=' {{(index (index .spec.containers 0) .containerPort 0) .containerPort} {{"\ n"}}'

Port output: 6379

two。 Forward the local port to the port in Pod

a. Forward port 6379 on the local workstation to port 6379 on redis-master pod:

Kubectl port-forward redis-master 6379:6379

The output looks like this:

I0710 14 4314 portforward.go:225 38.274550 3655 portforward.go:225] Forwarding from 127.0.0.1 purl 6379-> 6379

I0710 1414 43 portforward.go:225 38.274797 3655 portforward.go:225] Forwarding from [: 1]: 6379-> 6379

b. Launch the Redis command line interface

Redis-cli

c. At the Redis command line prompt, enter the ping command:

127.0.0.1 purl 6379 > ping

The Ping request returned PONG successfully.

Three: summary

Create a connection to forward the local port 6379 to port 6379 of the Redis server running in Pod. With this connection, you can debug the database running in Pod on your local workstation.

The above is all the content of the article "how to use kubectl port-forward in kubernetes". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report