阿里云ECI日志

satuo20 6月前 ⋅ 226 阅读

https://help.aliyun.com/zh/eci/user-guide/collect-logs-by-using-environment-variables-1

private List<CreateContainerGroupRequest.Container.EnvironmentVar> getEnvironmentList() {
        List<CreateContainerGroupRequest.Container.EnvironmentVar> environmentVarList = new ArrayList<>();
        CreateContainerGroupRequest.Container.EnvironmentVar var1 = new CreateContainerGroupRequest.Container.EnvironmentVar();
        var1.setKey("aliyun_logs_kp-yun-micro");
        var1.setValue("stdout");
        environmentVarList.add(var1);
        CreateContainerGroupRequest.Container.EnvironmentVar var2 = new CreateContainerGroupRequest.Container.EnvironmentVar();
        var2.setKey("aliyun_logs_kp-yun-micro_project");
        var2.setValue("k8s-log-c9d3141525a5a4577abac00962fd3ce03");
        environmentVarList.add(var2);
        CreateContainerGroupRequest.Container.EnvironmentVar var3 = new CreateContainerGroupRequest.Container.EnvironmentVar();
        var3.setKey("aliyun_logs_kp-yun-micro_logstore");
        var3.setValue("kp-yun-micro");
        environmentVarList.add(var3);
        CreateContainerGroupRequest.Container.EnvironmentVar var4 = new CreateContainerGroupRequest.Container.EnvironmentVar();
        var4.setKey("aliyun_logs_k8s-group-c9d3141525a5a4577abac00962fd3ce03-singleton_machinegroup");
        var4.setValue("kp-yun-micro");
        environmentVarList.add(var4);
        return environmentVarList;
    }
    
    
    
    public void createEciNode(int size) {
        if (!openEci) {
            return;
        }
        creator.setContainerGroupName(containerGroup);
        creator.setRestartPolicy("Never");//不重启
        List<CreateContainerGroupRequest.Container> containers = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            CreateContainerGroupRequest.Container container = new CreateContainerGroupRequest.Container();
            container.setName("kp-render-app-eci");
            container.setImage(image);
            container.setMemory(4F);
            container.setCpu(2F);
            container.setEnvironmentVars(this.getEnvironmentList());
            containers.add(container);
        }
        CreateContainerGroupRequest.Tag tag = new CreateContainerGroupRequest.Tag();
        tag.setKey(containerGroup);
        tag.setValue(containerGroup);
        creator.setTags(Collections.singletonList(tag));
        creator.setContainers(containers);
        try {
            CreateContainerGroupResponse response = iAcsClient.getAcsResponse(creator);
            log.info("创建的eci节点 -> {}", response.getContainerGroupId());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

全部评论: 0

    我有话说: