ktctl connect可以将本地环境连接至k8s集群,看到All looks good, now you can access to resources in the kubernetes cluster表示连接成功
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ sudo ktctl connect --namespace test
5:31PM INF Using cluster context kubernetes-admin@kubernetes (kubernetes) 5:31PM INF KtConnect 0.3.6 start at 91483 (darwin amd64) 5:31PM INF Fetching cluster time ... 5:31PM INF Using tun2socks mode 5:31PM INF Successful create config map kt-connect-shadow-jhqrg 5:31PM INF Deploying shadow pod kt-connect-shadow-jhqrg in namespace test ...... 5:31PM INF Setup local DNS with upstream [tcp:127.0.0.1:20626 udp:192.168.9.200:53] 5:31PM INF Creating udp dns on port 10053 5:31PM INF --------------------------------------------------------------- 5:31PM INF All looks good, now you can access to resources in the kubernetes cluster 5:31PM INF ---------------------------------------------------------------
#这里名称空间我选择的test,因为我测试服务起在这个名称空间下
Exchange
当看到Now all request to service '{your_service_in_k8s}' will be redirected to local 的时候说明k8s的请求都被转到本地
12:39PM INF Using cluster context {k8s_cluster_context} ({k8s_cluster_context}) 12:39PM INF KtConnect 0.3.6 start at 28585 (linux amd64) 12:39PM INF Fetching cluster time ... 12:39PM INF Using selector mode 12:39PM INF Service {your_service_in_k8s} locked 12:39PM INF Successful create config map {your_service_in_k8s}-kt-exchange-zikkt 12:39PM INF Deploying shadow pod aide-be-service-kt-exchange-zikkt in namespace {your_namespace_in_k8s} 12:39PM INF Waiting for pod {your_service_in_k8s}-kt-exchange-zikkt ... 12:39PM INF Pod {your_service_in_k8s}-kt-exchange-zikkt is ready 12:39PM INF Forwarding pod {your_service_in_k8s}-kt-exchange-zikkt to local via port {your_local_service_port_in_k8s}}:{your_service_target_port_in_k8s} 12:39PM INF Port forward local:41512 -> pod {your_service_in_k8s}-kt-exchange-zikkt:22 established 12:39PM INF Reverse tunnel 0.0.0.0:{your_local_service_port_in_k8s}} -> 127.0.0.1:{your_service_target_port_in_k8s} established 12:39PM INF Service aide-be-service unlocked 12:39PM INF --------------------------------------------------------------- 12:39PM INF Now all request to service '{your_service_in_k8s}' will be redirected to local 12:39PM INF --------------------------------------------------------------- ^C12:39PM INF Terminal Signal is interrupt 12:39PM INF Removed pid file /home/PJLAB/leidaoyu/.kt/pid/exchange-28585.pid 12:39PM INF Removed key file /home/PJLAB/leidaoyu/.kt/key/aide-be-service-kt-exchange-zikkt.key 12:39PM INF Pid file was removed 12:39PM INF Original service aide-be-service recovered 12:39PM INF Cleaning configmap aide-be-service-kt-exchange-zikkt 12:39PM INF Cleaning shadow pod aide-be-service-kt-exchange-zikkt
Mesh
当看到Now you can access your service by header 'VERSION: jnuie' 的时候说明k8s的请求都被转到本地,在向k8s发请求的时候在header里面加入VERSION: jnuie 参数,请求就会被转发回本地
ktctl exchange -n {your_namespace_in_k8s} {your_service_in_k8s} --expose {your_local_service_port_in_k8s}:{your_service_target_port_in_k8s} 1:21PM INF Using cluster context {k8s_cluster_context} ({k8s_cluster_context}) 1:21PM INF KtConnect 0.3.6 start at 2965 (linux amd64) 1:21PM INF Fetching cluster time ... 1:21PM INF Using auto mode 1:21PM INF Service {your_service_in_k8s}e locked 1:21PM INF Service {your_service_in_k8s}e-kt-stuntman created 1:21PM INF Service {your_service_in_k8s}-kt-mesh-jnuie created 1:21PM INF Router pod {your_service_in_k8s}-kt-router created 1:21PM INF Waiting for pod {your_service_in_k8s}-kt-router ... 1:21PM INF Pod {your_service_in_k8s}-kt-router is ready 1:21PM INF Router pod is ready 1:21PM INF Router pod configuration done 1:21PM INF Successful create config map {your_service_in_k8s}-kt-mesh-jnuie 1:21PM INF Deploying shadow pod {your_service_in_k8s}-kt-mesh-jnuie in namespace {your_namespace_in_k8s} 1:21PM INF Waiting for pod {your_service_in_k8s}-kt-mesh-jnuie ... 1:21PM INF Pod {your_service_in_k8s}-kt-mesh-jnuie is ready 1:21PM INF Forwarding pod {your_service_in_k8s}-kt-mesh-jnuie to local via port {your_local_service_port_in_k8s}:{your_service_target_port_in_k8s} 1:21PM INF Port forward local:54156 -> pod aide-be-service-kt-mesh-jnuie:22 established 1:21PM INF Reverse tunnel 0.0.0.0:{your_local_service_port_in_k8s} -> 127.0.0.1:{your_service_target_port_in_k8s} established 1:21PM INF --------------------------------------------------------------- 1:21PM INF Now you can access your service by header 'VERSION: jnuie' 1:21PM INF --------------------------------------------------------------- 1:21PM INF Service aide-be-service unlocked