feat: add more description

This commit is contained in:
fengcaiwen
2023-09-28 10:51:11 +08:00
committed by naison
parent a0f7fd0f06
commit 31369a19d6
14 changed files with 121 additions and 109 deletions

View File

@@ -67,38 +67,44 @@ kubectl apply -f https://raw.githubusercontent.com/KubeNetworks/kubevpn/master/s
### Connect to k8s cluster network ### Connect to k8s cluster network
```shell ```shell
➜ ~ kubevpn connect ➜ ~ kubevpn connect -n default --kubeconfig ~/.kube/config
Password:
start to connect
get cidr from cluster info... get cidr from cluster info...
get cidr from cluster info ok get cidr from cluster info ok
get cidr from cni... get cidr from cni...
wait pod cni-net-dir-kubevpn to be running timeout, reason , ignore
get cidr from svc... get cidr from svc...
get cidr from svc ok get cidr from svc ok
get cidr successfully
traffic manager not exist, try to create it... traffic manager not exist, try to create it...
pod [kubevpn-traffic-manager] status is Pending label namespace default
Container Reason Message create serviceAccount kubevpn-traffic-manager
create roles kubevpn-traffic-manager
pod [kubevpn-traffic-manager] status is Pending 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 Container Reason Message
control-plane ContainerCreating control-plane ContainerCreating
vpn ContainerCreating vpn ContainerCreating
webhook ContainerCreating webhook ContainerCreating
pod [kubevpn-traffic-manager] status is Running pod kubevpn-traffic-manager-799b5f5474-d7bp7 is Running
Container Reason Message Container Reason Message
control-plane ContainerRunning control-plane ContainerRunning
vpn ContainerRunning vpn ContainerRunning
webhook ContainerRunning webhook ContainerRunning
Creating mutatingWebhook_configuration for kubevpn-traffic-manager
update ref count successfully update ref count successfully
port forward ready port forward ready
your ip is 223.254.0.101
tunnel connected tunnel connected
dns service ok 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** **after you see this prompt, then leave this terminal alone, open a new terminal, continue operation**

View File

@@ -16,7 +16,8 @@ import (
func CmdConfig(f cmdutil.Factory) *cobra.Command { func CmdConfig(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "config", Use: "config",
Short: "Proxy kubeconfig which behind of ssh jump server",
} }
cmd.AddCommand(cmdConfigAdd(f)) cmd.AddCommand(cmdConfigAdd(f))
cmd.AddCommand(cmdConfigRemove(f)) cmd.AddCommand(cmdConfigRemove(f))
@@ -27,36 +28,17 @@ func cmdConfigAdd(f cmdutil.Factory) *cobra.Command {
var sshConf = &util.SshConfig{} var sshConf = &util.SshConfig{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "add", Use: "add",
Short: i18n.T("Clone workloads to target-kubeconfig cluster with same volume、env、and network"), Short: "Proxy kubeconfig",
Long: templates.LongDesc(i18n.T(`Clone workloads to target-kubeconfig cluster with same volume、env、and network`)), Long: templates.LongDesc(i18n.T(`proxy kubeconfig which behind of ssh jump server`)),
Example: templates.Examples(i18n.T(` Example: templates.Examples(i18n.T(`
# clone # proxy api-server which api-server behind of bastion host or ssh jump host
- clone deployment in current cluster and current namespace kubevpn config add --ssh-addr 192.168.1.100:22 --ssh-username root --ssh-keyfile ~/.ssh/ssh.pem
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 # it also support ProxyJump, like
┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌────────────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌────────────┐
│ pc ├────►│ ssh1 ├────►│ ssh2 ├────►│ ssh3 ├─────►... ─────► │ api-server │ │ 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) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
// startup daemon process and sudo process // startup daemon process and sudo process
@@ -88,36 +70,11 @@ func cmdConfigAdd(f cmdutil.Factory) *cobra.Command {
func cmdConfigRemove(f cmdutil.Factory) *cobra.Command { func cmdConfigRemove(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "remove", Use: "remove",
Short: i18n.T("Clone workloads to target-kubeconfig cluster with same volume、env、and network"), Short: "Remove proxy kubeconfig",
Long: templates.LongDesc(i18n.T(`Clone workloads to target-kubeconfig cluster with same volume、env、and network`)), Long: templates.LongDesc(i18n.T(`Remove proxy kubeconfig which behind of ssh jump server`)),
Example: templates.Examples(i18n.T(` Example: templates.Examples(i18n.T(`
# clone # remove proxy api-server which api-server behind of bastion host or ssh jump host
- clone deployment in current cluster and current namespace kubevpn config remove --kubeconfig /var/folders/30/cmv9c_5j3mq_kthx63sb1t5c0000gn/T/947048961.kubeconfig
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
`)), `)),
PreRunE: func(cmd *cobra.Command, args []string) (err error) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
// startup daemon process and sudo process // startup daemon process and sudo process

View File

@@ -16,8 +16,8 @@ func CmdDaemon(_ cmdutil.Factory) *cobra.Command {
var opt = &daemon.SvrOption{} var opt = &daemon.SvrOption{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "daemon", Use: "daemon",
Short: i18n.T("Startup GRPC server"), Short: i18n.T("Startup kubevpn daemon server"),
Long: i18n.T(`Startup GRPC server`), Long: i18n.T(`Startup kubevpn daemon server`),
PreRunE: func(cmd *cobra.Command, args []string) error { PreRunE: func(cmd *cobra.Command, args []string) error {
sockPath := daemon.GetSockPath(opt.IsSudo) sockPath := daemon.GetSockPath(opt.IsSudo)
err := os.Remove(sockPath) err := os.Remove(sockPath)

View File

@@ -18,10 +18,13 @@ import (
func CmdDisconnect(f cmdutil.Factory) *cobra.Command { func CmdDisconnect(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "disconnect", Use: "disconnect",
Short: i18n.T("Disconnect from kubernetes cluster network"), Short: i18n.T("Disconnect from kubernetes cluster network"),
Long: templates.LongDesc(i18n.T(`Disconnect from kubernetes cluster network`)), Long: templates.LongDesc(i18n.T(`Disconnect from kubernetes cluster network`)),
Example: templates.Examples(i18n.T(``)), Example: templates.Examples(i18n.T(`
# disconnect from cluster network and restore proxy resource
kubevpn disconnect
`)),
PreRunE: func(cmd *cobra.Command, args []string) (err error) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
err = daemon.StartupDaemon(cmd.Context()) err = daemon.StartupDaemon(cmd.Context())
return err return err

View File

@@ -16,9 +16,10 @@ import (
func CmdGet(f cmdutil.Factory) *cobra.Command { func CmdGet(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "get", Use: "get",
Short: i18n.T("Get resource to kubernetes cluster network"), Hidden: true,
Long: templates.LongDesc(i18n.T(`Connect to kubernetes cluster network`)), Short: i18n.T("Get cluster resources which connected"),
Long: templates.LongDesc(i18n.T(`Get cluster resources which connected`)),
Example: templates.Examples(i18n.T(` Example: templates.Examples(i18n.T(`
# Get resource to k8s cluster network # Get resource to k8s cluster network
kubevpn get pods kubevpn get pods
@@ -31,7 +32,6 @@ func CmdGet(f cmdutil.Factory) *cobra.Command {
│ pc ├────►│ ssh1 ├────►│ ssh2 ├────►│ ssh3 ├─────►... ─────► │ api-server │ │ pc ├────►│ ssh1 ├────►│ ssh2 ├────►│ ssh3 ├─────►... ─────► │ api-server │
└──────┘ └──────┘ └──────┘ └──────┘ └────────────┘ └──────┘ └──────┘ └──────┘ └──────┘ └────────────┘
kubevpn get service --ssh-alias <alias> kubevpn get service --ssh-alias <alias>
`)), `)),
PreRunE: func(cmd *cobra.Command, args []string) error { PreRunE: func(cmd *cobra.Command, args []string) error {
// startup daemon process and sudo process // startup daemon process and sudo process

View File

@@ -9,6 +9,8 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util" 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"
"github.com/wencaiwulue/kubevpn/pkg/daemon/rpc" "github.com/wencaiwulue/kubevpn/pkg/daemon/rpc"
@@ -17,8 +19,12 @@ import (
func CmdLeave(f cmdutil.Factory) *cobra.Command { func CmdLeave(f cmdutil.Factory) *cobra.Command {
var leaveCmd = &cobra.Command{ var leaveCmd = &cobra.Command{
Use: "leave", Use: "leave",
Short: "leave reverse remote resource traffic to local machine", Short: "Leave proxy resource",
Long: `leave remote traffic to local machine`, 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) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
return daemon.StartupDaemon(cmd.Context()) return daemon.StartupDaemon(cmd.Context())
}, },

View File

@@ -14,10 +14,13 @@ import (
func CmdList(f cmdutil.Factory) *cobra.Command { func CmdList(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list", Use: "list",
Short: i18n.T("Disconnect from kubernetes cluster network"), Short: i18n.T("List proxy resources"),
Long: templates.LongDesc(i18n.T(`Disconnect from kubernetes cluster network`)), Long: templates.LongDesc(i18n.T(`List proxy resources`)),
Example: templates.Examples(i18n.T(``)), Example: templates.Examples(i18n.T(`
# list proxy resources
kubevpn list
`)),
PreRunE: func(cmd *cobra.Command, args []string) (err error) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
return daemon.StartupDaemon(cmd.Context()) return daemon.StartupDaemon(cmd.Context())
}, },

View File

@@ -19,10 +19,15 @@ import (
func CmdLogs(f cmdutil.Factory) *cobra.Command { func CmdLogs(f cmdutil.Factory) *cobra.Command {
req := &rpc.LogRequest{} req := &rpc.LogRequest{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "logs", Use: "logs",
Short: i18n.T("Logs to kubernetes cluster network"), Short: i18n.T("Log kubevpn daemon server"),
Long: templates.LongDesc(i18n.T(`Logs to kubernetes cluster network`)), Long: templates.LongDesc(i18n.T(`Log kubevpn daemon server`)),
Example: templates.Examples(i18n.T(``)), 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) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
// startup daemon process and sudo process // startup daemon process and sudo process
return daemon.StartupDaemon(cmd.Context()) return daemon.StartupDaemon(cmd.Context())

View File

@@ -19,10 +19,13 @@ import (
func CmdQuit(f cmdutil.Factory) *cobra.Command { func CmdQuit(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "quit", Use: "quit",
Short: i18n.T("Quit daemon"), Short: i18n.T("Quit kubevpn daemon server"),
Long: templates.LongDesc(i18n.T(`Disconnect from cluster, leave proxy resources, and quit daemon`)), Long: templates.LongDesc(i18n.T(`Disconnect from cluster, leave proxy resources, and quit daemon`)),
Example: templates.Examples(i18n.T(``)), 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) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
return daemon.StartupDaemon(cmd.Context()) return daemon.StartupDaemon(cmd.Context())
}, },

View File

@@ -9,6 +9,8 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util" 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"
"github.com/wencaiwulue/kubevpn/pkg/daemon/rpc" "github.com/wencaiwulue/kubevpn/pkg/daemon/rpc"
@@ -17,8 +19,12 @@ import (
func CmdRemove(f cmdutil.Factory) *cobra.Command { func CmdRemove(f cmdutil.Factory) *cobra.Command {
var cmd = &cobra.Command{ var cmd = &cobra.Command{
Use: "remove", Use: "remove",
Short: "Remove reverse remote resource traffic to local machine", Short: "Remove cloned resource",
Long: `Remove remote traffic to local machine`, 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) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
return daemon.StartupDaemon(cmd.Context()) return daemon.StartupDaemon(cmd.Context())
}, },

View File

@@ -47,25 +47,15 @@ func NewKubeVPNCommand() *cobra.Command {
groups := templates.CommandGroups{ groups := templates.CommandGroups{
{ {
Message: "Client Commands:", Message: "Develop commands:",
Commands: []*cobra.Command{ Commands: []*cobra.Command{
CmdConnect(factory), CmdConnect(factory),
CmdDisconnect(factory), CmdDisconnect(factory),
CmdQuit(factory),
CmdLogs(factory),
CmdProxy(factory), CmdProxy(factory),
CmdList(factory),
CmdGet(factory),
CmdLeave(factory), CmdLeave(factory),
CmdDev(factory),
CmdClone(factory), CmdClone(factory),
CmdConfig(factory),
CmdRemove(factory), CmdRemove(factory),
CmdCp(factory), CmdDev(factory),
CmdUpgrade(factory),
CmdReset(factory),
CmdVersion(factory),
CmdStatus(factory),
// Hidden, Server Commands (DO NOT USE IT !!!) // Hidden, Server Commands (DO NOT USE IT !!!)
CmdControlPlane(factory), CmdControlPlane(factory),
CmdServe(factory), CmdServe(factory),
@@ -73,6 +63,27 @@ func NewKubeVPNCommand() *cobra.Command {
CmdWebhook(factory), 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) groups.Add(cmd)
templates.ActsAsRootCommand(cmd, []string{"options"}, groups...) templates.ActsAsRootCommand(cmd, []string{"options"}, groups...)

View File

@@ -9,6 +9,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/automaxprocs/maxprocs" "go.uber.org/automaxprocs/maxprocs"
cmdutil "k8s.io/kubectl/pkg/cmd/util" 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/config"
"github.com/wencaiwulue/kubevpn/pkg/core" "github.com/wencaiwulue/kubevpn/pkg/core"
@@ -22,7 +24,11 @@ func CmdServe(_ cmdutil.Factory) *cobra.Command {
Use: "serve", Use: "serve",
Hidden: true, Hidden: true,
Short: "Server side, startup traffic manager, forward inbound and outbound traffic", 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) { PreRun: func(*cobra.Command, []string) {
util.InitLogger(config.Debug) util.InitLogger(config.Debug)
runtime.GOMAXPROCS(0) runtime.GOMAXPROCS(0)

View File

@@ -15,10 +15,13 @@ import (
func CmdStatus(f cmdutil.Factory) *cobra.Command { func CmdStatus(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "status", Use: "status",
Short: i18n.T("KubeVPN status"), Short: i18n.T("KubeVPN status"),
Long: templates.LongDesc(i18n.T(`KubeVPN status`)), Long: templates.LongDesc(i18n.T(`KubeVPN status`)),
Example: templates.Examples(i18n.T(``)), Example: templates.Examples(i18n.T(`
# show status for kubevpn status
kubevpn status
`)),
PreRunE: func(cmd *cobra.Command, args []string) (err error) { PreRunE: func(cmd *cobra.Command, args []string) (err error) {
return daemon.StartupDaemon(cmd.Context()) return daemon.StartupDaemon(cmd.Context())
}, },

View File

@@ -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 { 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) path, err := SshJump(ctx, conf, flags, print)
if err != nil { if err != nil {
return err return err