The first step is to configure kubectl
- Install locally
kubectl
, and configure the path to the environment variable. - Find the file on the server
apiserver.crt
, usually in/etc/kubernetes/pki
, and execute theopenssl x509 -in apiserver.crt -noout -text | grep DNS
command. - Add any domain name (usually kubernetes) of the DNS value in the above figure to the local hosts, and the ip address is the external network IP of the k8s server.
- Download the server-side
~/.kube/config
to the local, configured ,kubectl
the file is usually under, and change the address to the domain name configured in hosts.config
config
C:\Users\{用户}\.kube\
clusters:clusters:clusters:
The second step is to configure KT-Connect and use IDEA for development and joint debugging
- Download KT-Connect, install it locally and configure the path to the environment variable.
- IDEA downloads and installs the latest version of the JVM Inject plugin
- Use ktctl in the directory of the project opened by IDEA to start the socks5 proxy service from the local to the cluster,
ktctl connect --method=socks5 --dump2hosts
- Refresh the directory in IDEA until you can see the .jvmrc file, then you can start the project. The VM Inject plugin will automatically read the .jvmrc file when the Java program starts, and append it to the program's startup parameters, as shown below:
java ...省略的其他输出... -Djava.rmi.server.hostname=127.0.0.1 -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dhttp.proxyHost=127.0
- You can access the address in the cluster
@ApiOperation("k8s测试")
@PostMapping("/index")
public Result<String> index() {
String s = HttpUtil.get("http://10.233.99.24:8080");
return Res.ok(s);
}
The effect of the browser directly accessing the address in the cluster:
Java program access effect:
FAQ
- The following error occurs when starting
Solution: Delete .ktctl
the files under the pid
folder
Project Recommendation: Based on Spring Cloud Alibaba technology, a distributed microservice development platform including basic functions, OA, payment, marketing and other modules
{{o.name}}
{{m.name}}