mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-09-26 19:31:17 +08:00
feat: add more description
This commit is contained in:
30
README.md
30
README.md
@@ -67,38 +67,44 @@ kubectl apply -f https://raw.githubusercontent.com/KubeNetworks/kubevpn/master/s
|
||||
### Connect to k8s cluster network
|
||||
|
||||
```shell
|
||||
➜ ~ kubevpn connect
|
||||
➜ ~ kubevpn connect -n default --kubeconfig ~/.kube/config
|
||||
Password:
|
||||
start to connect
|
||||
get cidr from cluster info...
|
||||
get cidr from cluster info ok
|
||||
get cidr from cni...
|
||||
wait pod cni-net-dir-kubevpn to be running timeout, reason , ignore
|
||||
get cidr from svc...
|
||||
get cidr from svc ok
|
||||
get cidr successfully
|
||||
traffic manager not exist, try to create it...
|
||||
pod [kubevpn-traffic-manager] status is Pending
|
||||
Container Reason Message
|
||||
|
||||
pod [kubevpn-traffic-manager] status is Pending
|
||||
label namespace default
|
||||
create serviceAccount kubevpn-traffic-manager
|
||||
create roles kubevpn-traffic-manager
|
||||
create roleBinding kubevpn-traffic-manager
|
||||
create service kubevpn-traffic-manager
|
||||
create deployment kubevpn-traffic-manager
|
||||
pod kubevpn-traffic-manager-799b5f5474-d7bp7 is Pending
|
||||
Container Reason Message
|
||||
control-plane ContainerCreating
|
||||
vpn ContainerCreating
|
||||
webhook ContainerCreating
|
||||
|
||||
pod [kubevpn-traffic-manager] status is Running
|
||||
pod kubevpn-traffic-manager-799b5f5474-d7bp7 is Running
|
||||
Container Reason Message
|
||||
control-plane ContainerRunning
|
||||
vpn ContainerRunning
|
||||
webhook ContainerRunning
|
||||
|
||||
Creating mutatingWebhook_configuration for kubevpn-traffic-manager
|
||||
update ref count successfully
|
||||
port forward ready
|
||||
your ip is 223.254.0.101
|
||||
tunnel connected
|
||||
dns service ok
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
Now you can access resources in the kubernetes cluster, enjoy it :)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
+---------------------------------------------------------------------------+
|
||||
| Now you can access resources in the kubernetes cluster, enjoy it :) |
|
||||
+---------------------------------------------------------------------------+
|
||||
➜ ~
|
||||
```
|
||||
|
||||
**after you see this prompt, then leave this terminal alone, open a new terminal, continue operation**
|
||||
|
@@ -16,7 +16,8 @@ import (
|
||||
|
||||
func CmdConfig(f cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "config",
|
||||
Use: "config",
|
||||
Short: "Proxy kubeconfig which behind of ssh jump server",
|
||||
}
|
||||
cmd.AddCommand(cmdConfigAdd(f))
|
||||
cmd.AddCommand(cmdConfigRemove(f))
|
||||
@@ -27,36 +28,17 @@ func cmdConfigAdd(f cmdutil.Factory) *cobra.Command {
|
||||
var sshConf = &util.SshConfig{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "add",
|
||||
Short: i18n.T("Clone workloads to target-kubeconfig cluster with same volume、env、and network"),
|
||||
Long: templates.LongDesc(i18n.T(`Clone workloads to target-kubeconfig cluster with same volume、env、and network`)),
|
||||
Short: "Proxy kubeconfig",
|
||||
Long: templates.LongDesc(i18n.T(`proxy kubeconfig which behind of ssh jump server`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# clone
|
||||
- clone deployment in current cluster and current namespace
|
||||
kubevpn clone deployment/productpage
|
||||
|
||||
- clone deployment in current cluster with different namespace
|
||||
kubevpn clone deployment/productpage -n test
|
||||
|
||||
- clone deployment to another cluster
|
||||
kubevpn clone deployment/productpage --target-kubeconfig ~/.kube/other-kubeconfig
|
||||
|
||||
- clone multiple workloads
|
||||
kubevpn clone deployment/authors deployment/productpage
|
||||
or
|
||||
kubevpn clone deployment authors productpage
|
||||
|
||||
# clone with mesh, traffic with header a=1, will hit cloned workloads, otherwise hit origin workloads
|
||||
kubevpn clone deployment/productpage --headers a=1
|
||||
|
||||
# clone workloads which api-server behind of bastion host or ssh jump host
|
||||
kubevpn clone deployment/productpage --ssh-addr 192.168.1.100:22 --ssh-username root --ssh-keyfile ~/.ssh/ssh.pem --headers a=1
|
||||
# proxy api-server which api-server behind of bastion host or ssh jump host
|
||||
kubevpn config add --ssh-addr 192.168.1.100:22 --ssh-username root --ssh-keyfile ~/.ssh/ssh.pem
|
||||
|
||||
# it also support ProxyJump, like
|
||||
┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌────────────┐
|
||||
│ pc ├────►│ ssh1 ├────►│ ssh2 ├────►│ ssh3 ├─────►... ─────► │ api-server │
|
||||
└──────┘ └──────┘ └──────┘ └──────┘ └────────────┘
|
||||
kubevpn clone service/productpage --ssh-alias <alias> --headers a=1
|
||||
|
||||
kubevpn config add --ssh-alias <alias>
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
// startup daemon process and sudo process
|
||||
@@ -88,36 +70,11 @@ func cmdConfigAdd(f cmdutil.Factory) *cobra.Command {
|
||||
func cmdConfigRemove(f cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "remove",
|
||||
Short: i18n.T("Clone workloads to target-kubeconfig cluster with same volume、env、and network"),
|
||||
Long: templates.LongDesc(i18n.T(`Clone workloads to target-kubeconfig cluster with same volume、env、and network`)),
|
||||
Short: "Remove proxy kubeconfig",
|
||||
Long: templates.LongDesc(i18n.T(`Remove proxy kubeconfig which behind of ssh jump server`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# clone
|
||||
- clone deployment in current cluster and current namespace
|
||||
kubevpn clone deployment/productpage
|
||||
|
||||
- clone deployment in current cluster with different namespace
|
||||
kubevpn clone deployment/productpage -n test
|
||||
|
||||
- clone deployment to another cluster
|
||||
kubevpn clone deployment/productpage --target-kubeconfig ~/.kube/other-kubeconfig
|
||||
|
||||
- clone multiple workloads
|
||||
kubevpn clone deployment/authors deployment/productpage
|
||||
or
|
||||
kubevpn clone deployment authors productpage
|
||||
|
||||
# clone with mesh, traffic with header a=1, will hit cloned workloads, otherwise hit origin workloads
|
||||
kubevpn clone deployment/productpage --headers a=1
|
||||
|
||||
# clone workloads which api-server behind of bastion host or ssh jump host
|
||||
kubevpn clone deployment/productpage --ssh-addr 192.168.1.100:22 --ssh-username root --ssh-keyfile ~/.ssh/ssh.pem --headers a=1
|
||||
|
||||
# it also support ProxyJump, like
|
||||
┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌────────────┐
|
||||
│ pc ├────►│ ssh1 ├────►│ ssh2 ├────►│ ssh3 ├─────►... ─────► │ api-server │
|
||||
└──────┘ └──────┘ └──────┘ └──────┘ └────────────┘
|
||||
kubevpn clone service/productpage --ssh-alias <alias> --headers a=1
|
||||
|
||||
# remove proxy api-server which api-server behind of bastion host or ssh jump host
|
||||
kubevpn config remove --kubeconfig /var/folders/30/cmv9c_5j3mq_kthx63sb1t5c0000gn/T/947048961.kubeconfig
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
// startup daemon process and sudo process
|
||||
|
@@ -16,8 +16,8 @@ func CmdDaemon(_ cmdutil.Factory) *cobra.Command {
|
||||
var opt = &daemon.SvrOption{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "daemon",
|
||||
Short: i18n.T("Startup GRPC server"),
|
||||
Long: i18n.T(`Startup GRPC server`),
|
||||
Short: i18n.T("Startup kubevpn daemon server"),
|
||||
Long: i18n.T(`Startup kubevpn daemon server`),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
sockPath := daemon.GetSockPath(opt.IsSudo)
|
||||
err := os.Remove(sockPath)
|
||||
|
@@ -18,10 +18,13 @@ import (
|
||||
|
||||
func CmdDisconnect(f cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "disconnect",
|
||||
Short: i18n.T("Disconnect from kubernetes cluster network"),
|
||||
Long: templates.LongDesc(i18n.T(`Disconnect from kubernetes cluster network`)),
|
||||
Example: templates.Examples(i18n.T(``)),
|
||||
Use: "disconnect",
|
||||
Short: i18n.T("Disconnect from kubernetes cluster network"),
|
||||
Long: templates.LongDesc(i18n.T(`Disconnect from kubernetes cluster network`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# disconnect from cluster network and restore proxy resource
|
||||
kubevpn disconnect
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
err = daemon.StartupDaemon(cmd.Context())
|
||||
return err
|
||||
|
@@ -16,9 +16,10 @@ import (
|
||||
|
||||
func CmdGet(f cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Short: i18n.T("Get resource to kubernetes cluster network"),
|
||||
Long: templates.LongDesc(i18n.T(`Connect to kubernetes cluster network`)),
|
||||
Use: "get",
|
||||
Hidden: true,
|
||||
Short: i18n.T("Get cluster resources which connected"),
|
||||
Long: templates.LongDesc(i18n.T(`Get cluster resources which connected`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# Get resource to k8s cluster network
|
||||
kubevpn get pods
|
||||
@@ -31,7 +32,6 @@ func CmdGet(f cmdutil.Factory) *cobra.Command {
|
||||
│ pc ├────►│ ssh1 ├────►│ ssh2 ├────►│ ssh3 ├─────►... ─────► │ api-server │
|
||||
└──────┘ └──────┘ └──────┘ └──────┘ └────────────┘
|
||||
kubevpn get service --ssh-alias <alias>
|
||||
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
// startup daemon process and sudo process
|
||||
|
@@ -9,6 +9,8 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/pkg/daemon"
|
||||
"github.com/wencaiwulue/kubevpn/pkg/daemon/rpc"
|
||||
@@ -17,8 +19,12 @@ import (
|
||||
func CmdLeave(f cmdutil.Factory) *cobra.Command {
|
||||
var leaveCmd = &cobra.Command{
|
||||
Use: "leave",
|
||||
Short: "leave reverse remote resource traffic to local machine",
|
||||
Long: `leave remote traffic to local machine`,
|
||||
Short: "Leave proxy resource",
|
||||
Long: `leave proxy resource and restore it to origin`,
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# leave proxy resource and restore it to origin
|
||||
kubevpn leave deployment/authors
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
return daemon.StartupDaemon(cmd.Context())
|
||||
},
|
||||
|
@@ -14,10 +14,13 @@ import (
|
||||
|
||||
func CmdList(f cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: i18n.T("Disconnect from kubernetes cluster network"),
|
||||
Long: templates.LongDesc(i18n.T(`Disconnect from kubernetes cluster network`)),
|
||||
Example: templates.Examples(i18n.T(``)),
|
||||
Use: "list",
|
||||
Short: i18n.T("List proxy resources"),
|
||||
Long: templates.LongDesc(i18n.T(`List proxy resources`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# list proxy resources
|
||||
kubevpn list
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
return daemon.StartupDaemon(cmd.Context())
|
||||
},
|
||||
|
@@ -19,10 +19,15 @@ import (
|
||||
func CmdLogs(f cmdutil.Factory) *cobra.Command {
|
||||
req := &rpc.LogRequest{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "logs",
|
||||
Short: i18n.T("Logs to kubernetes cluster network"),
|
||||
Long: templates.LongDesc(i18n.T(`Logs to kubernetes cluster network`)),
|
||||
Example: templates.Examples(i18n.T(``)),
|
||||
Use: "logs",
|
||||
Short: i18n.T("Log kubevpn daemon server"),
|
||||
Long: templates.LongDesc(i18n.T(`Log kubevpn daemon server`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# show log for kubevpn daemon server
|
||||
kubevpn logs
|
||||
# follow more log
|
||||
kubevpn logs -f
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
// startup daemon process and sudo process
|
||||
return daemon.StartupDaemon(cmd.Context())
|
||||
|
@@ -19,10 +19,13 @@ import (
|
||||
|
||||
func CmdQuit(f cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "quit",
|
||||
Short: i18n.T("Quit daemon"),
|
||||
Long: templates.LongDesc(i18n.T(`Disconnect from cluster, leave proxy resources, and quit daemon`)),
|
||||
Example: templates.Examples(i18n.T(``)),
|
||||
Use: "quit",
|
||||
Short: i18n.T("Quit kubevpn daemon server"),
|
||||
Long: templates.LongDesc(i18n.T(`Disconnect from cluster, leave proxy resources, and quit daemon`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# before quit kubevpn, it will leave proxy resources to origin and disconnect from cluster
|
||||
kubevpn quit
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
return daemon.StartupDaemon(cmd.Context())
|
||||
},
|
||||
|
@@ -9,6 +9,8 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/pkg/daemon"
|
||||
"github.com/wencaiwulue/kubevpn/pkg/daemon/rpc"
|
||||
@@ -17,8 +19,12 @@ import (
|
||||
func CmdRemove(f cmdutil.Factory) *cobra.Command {
|
||||
var cmd = &cobra.Command{
|
||||
Use: "remove",
|
||||
Short: "Remove reverse remote resource traffic to local machine",
|
||||
Long: `Remove remote traffic to local machine`,
|
||||
Short: "Remove cloned resource",
|
||||
Long: `Remove cloned resource`,
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# leave proxy resources to origin
|
||||
kubevpn remove deployment/authors
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
return daemon.StartupDaemon(cmd.Context())
|
||||
},
|
||||
|
@@ -47,25 +47,15 @@ func NewKubeVPNCommand() *cobra.Command {
|
||||
|
||||
groups := templates.CommandGroups{
|
||||
{
|
||||
Message: "Client Commands:",
|
||||
Message: "Develop commands:",
|
||||
Commands: []*cobra.Command{
|
||||
CmdConnect(factory),
|
||||
CmdDisconnect(factory),
|
||||
CmdQuit(factory),
|
||||
CmdLogs(factory),
|
||||
CmdProxy(factory),
|
||||
CmdList(factory),
|
||||
CmdGet(factory),
|
||||
CmdLeave(factory),
|
||||
CmdDev(factory),
|
||||
CmdClone(factory),
|
||||
CmdConfig(factory),
|
||||
CmdRemove(factory),
|
||||
CmdCp(factory),
|
||||
CmdUpgrade(factory),
|
||||
CmdReset(factory),
|
||||
CmdVersion(factory),
|
||||
CmdStatus(factory),
|
||||
CmdDev(factory),
|
||||
// Hidden, Server Commands (DO NOT USE IT !!!)
|
||||
CmdControlPlane(factory),
|
||||
CmdServe(factory),
|
||||
@@ -73,6 +63,27 @@ func NewKubeVPNCommand() *cobra.Command {
|
||||
CmdWebhook(factory),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Management commands",
|
||||
Commands: []*cobra.Command{
|
||||
CmdList(factory),
|
||||
CmdGet(factory),
|
||||
CmdConfig(factory),
|
||||
CmdCp(factory),
|
||||
CmdSSH(factory),
|
||||
CmdReset(factory),
|
||||
CmdQuit(factory),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Other commands",
|
||||
Commands: []*cobra.Command{
|
||||
CmdLogs(factory),
|
||||
CmdStatus(factory),
|
||||
CmdVersion(factory),
|
||||
CmdUpgrade(factory),
|
||||
},
|
||||
},
|
||||
}
|
||||
groups.Add(cmd)
|
||||
templates.ActsAsRootCommand(cmd, []string{"options"}, groups...)
|
||||
|
@@ -9,6 +9,8 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/automaxprocs/maxprocs"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/pkg/config"
|
||||
"github.com/wencaiwulue/kubevpn/pkg/core"
|
||||
@@ -22,7 +24,11 @@ func CmdServe(_ cmdutil.Factory) *cobra.Command {
|
||||
Use: "serve",
|
||||
Hidden: true,
|
||||
Short: "Server side, startup traffic manager, forward inbound and outbound traffic",
|
||||
Long: `Server side, startup traffic manager, forward inbound and outbound traffic.`,
|
||||
Long: templates.LongDesc(`Server side, startup traffic manager, forward inbound and outbound traffic.`),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# serve node
|
||||
kubevpn serve -L "tcp://:10800" -L "tun://127.0.0.1:8422?net=223.254.0.123/32"
|
||||
`)),
|
||||
PreRun: func(*cobra.Command, []string) {
|
||||
util.InitLogger(config.Debug)
|
||||
runtime.GOMAXPROCS(0)
|
||||
|
@@ -15,10 +15,13 @@ import (
|
||||
|
||||
func CmdStatus(f cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "status",
|
||||
Short: i18n.T("KubeVPN status"),
|
||||
Long: templates.LongDesc(i18n.T(`KubeVPN status`)),
|
||||
Example: templates.Examples(i18n.T(``)),
|
||||
Use: "status",
|
||||
Short: i18n.T("KubeVPN status"),
|
||||
Long: templates.LongDesc(i18n.T(`KubeVPN status`)),
|
||||
Example: templates.Examples(i18n.T(`
|
||||
# show status for kubevpn status
|
||||
kubevpn status
|
||||
`)),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
return daemon.StartupDaemon(cmd.Context())
|
||||
},
|
||||
|
@@ -892,6 +892,9 @@ func SshJump(ctx context.Context, conf *util.SshConfig, flags *pflag.FlagSet, pr
|
||||
}
|
||||
|
||||
func SshJumpAndSetEnv(ctx context.Context, conf *util.SshConfig, flags *pflag.FlagSet, print bool) error {
|
||||
if conf.Addr == "" && conf.ConfigAlias == "" {
|
||||
return nil
|
||||
}
|
||||
path, err := SshJump(ctx, conf, flags, print)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user