@SneakyThrows
    private String kubeConfigWithServerUrl(String kubeConfigYaml, String serverUrl) {
        ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());

        ObjectNode kubeConfigObjectNode = objectMapper.readValue(kubeConfigYaml, ObjectNode.class);

        JsonNode clusterNode = kubeConfigObjectNode.at("/clusters/0/cluster");
        if (!clusterNode.isObject()) {
            throw new IllegalStateException("'/clusters/0/cluster' expected to be an object");
        }
        ObjectNode clusterConfig = (ObjectNode) clusterNode;
        clusterConfig.replace("server", new TextNode(serverUrl));

        kubeConfigObjectNode.set("current-context", new TextNode("default"));

        return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(kubeConfigObjectNode);
    }
Generate a kubernetes client configuration for use on a docker internal network. The kubeConfig can be used by
another docker container running in the same network as the k3s container. For access from the host, use
the {@link #getKubeConfigYaml()} method instead.

@param networkAlias a valid network alias of the k3s container.
@return the kubeConfig yaml.
modules/k3s/src/main/java/org/testcontainers/k3s/K3sContainer.java