private async Task CreateAutoscaler(string deploymentName, string nameSpace, int minInstances, int maxInstances, int cpuPercentage = 60)
        {
            var cmd = $"autoscale deploy {deploymentName} --cpu-percent={cpuPercentage} --max={maxInstances} --min={minInstances} --namespace={nameSpace}";

            if (!string.IsNullOrEmpty(configFile))
            {
                cmd += $" --kubeconfig {configFile}";
            }

            await KubernetesHelper.RunKubectl(cmd);
        }
Esempio n. 2
0
        private async Task Deploy(string name, string image, string nameSpace, int min, int max)
        {
            var isHTTP = IsHTTPTrigger(name);

            await CreateNamespace(nameSpace);

            client.DefaultNamespace = nameSpace;

            ColoredConsole.WriteLine();
            ColoredConsole.WriteLine("Deploying function to Knative...");

            var knativeService = GetKnativeService(name, image, nameSpace, min, max, isHTTP);
            var json           = Newtonsoft.Json.JsonConvert.SerializeObject(knativeService,
                                                                             Newtonsoft.Json.Formatting.None,
                                                                             new Newtonsoft.Json.JsonSerializerSettings
            {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });

            File.WriteAllText("deployment.json", json);
            await KubernetesHelper.RunKubectl($"apply -f deployment.json");

            File.Delete("deployment.json");

            var endpoint = await GetIstioClusterIngressEndpoint();

            var host = GetFunctionHost(name, nameSpace);

            ColoredConsole.WriteLine();
            ColoredConsole.WriteLine("Function deployed successfully!");
            ColoredConsole.WriteLine();
            if (string.IsNullOrEmpty(endpoint))
            {
                ColoredConsole.WriteLine($"Function URL: http://{endpoint}");
            }
            else
            {
                ColoredConsole.WriteLine("Couldn't identify Function URL: Couldn't find Istio Cluster Ingress endpoint");
            }
            ColoredConsole.WriteLine($"Function Host: {host}");
            ColoredConsole.WriteLine();
            ColoredConsole.WriteLine("Plese note: it may take a few minutes for the knative service to be reachable");
        }
Esempio n. 3
0
 private async Task CreateNamespace(string name)
 {
     await KubernetesHelper.RunKubectl($"create ns {name}");
 }
        private async Task Deploy(string name, string image, string nameSpace, int min, int max, double cpu = 0.1, int memory = 128, string port = "80")
        {
            await CreateNamespace(nameSpace);

            client.DefaultNamespace = nameSpace;

            var deploymentName = $"{name}-deployment";

            await DeleteDeploymentIfExists(deploymentName, nameSpace);

            ColoredConsole.WriteLine("Deploying function to Kubernetes...");

            var deployment = GetDeployment(deploymentName, image, cpu, memory, port, nameSpace, min);
            var json       = Newtonsoft.Json.JsonConvert.SerializeObject(deployment,
                                                                         Newtonsoft.Json.Formatting.None,
                                                                         new Newtonsoft.Json.JsonSerializerSettings
            {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });

            File.WriteAllText("deployment.json", json);
            KubernetesHelper.RunKubectl($"apply -f deployment.json");

            ColoredConsole.WriteLine("Deployment successful");

            var service = GetService(deploymentName, nameSpace, port);

            try
            {
                // we can safely ignore the error here
                await client.ServicesV1().Create(service);
            }
            catch { }

            await TryRemoveAutoscaler(deploymentName, nameSpace);
            await CreateAutoscaler(deploymentName, nameSpace, min, max);

            var externalIP = "";

            ColoredConsole.WriteLine("Waiting for External IP...");

            while (string.IsNullOrEmpty(externalIP))
            {
                var svc = await client.ServicesV1().Get($"{deploymentName}-service", nameSpace);

                if (svc != null)
                {
                    if (svc.Status.LoadBalancer.Ingress.Count > 0)
                    {
                        externalIP = svc.Status.LoadBalancer.Ingress[0].Ip;
                    }
                }
            }

            File.Delete("deployment.json");

            ColoredConsole.WriteLine("");

            ColoredConsole.WriteLine("Function deployed successfully!");
            ColoredConsole.WriteLine($"Function IP: {externalIP}");
        }
 private async Task TryRemoveAutoscaler(string deploymentName, string nameSpace)
 {
     await KubernetesHelper.RunKubectl($"delete hpa {deploymentName} -n {nameSpace}");
 }
 public async Task GetKubernetesFunctionLogs(string functionName)
 {
     string nameSpace = KUBERNETES_DEFAULT_NAMESPACE;
     await KubernetesHelper.RunKubectl($"logs -l app={functionName}-deployment -n {nameSpace}", true);
 }