public static k8s.Models.V1Service Service(Models.RepoData RepoData)
        {
            k8s.Models.V1Service KubeObject = k8s.Yaml.LoadFromFileAsync <k8s.Models.V1Service>("/KubernetesObjects/Service.yaml").Result;

            KubeObject.Metadata.Name = RepoData.Name;
            KubeObject.Metadata.NamespaceProperty = Settings.KubernetesNamespace;
            KubeObject.Spec.Selector["app"]       = RepoData.Name;

            return(KubeObject);
        }
Ejemplo n.º 2
0
        public bool CreateFunctionsContainer(string containerName, out string status, string image = "mcr.microsoft.com/azure-functions/mesh:2.0.12490", int numberOfContainers = 1)
        {
            var deploymentList = client.ListDeploymentForAllNamespaces();

            foreach (var item in deploymentList.Items)
            {
                if (item.Metadata.Name == containerName)
                {
                    status = string.Format("Deployment {0} found! Skipping creation", item.Metadata.Name);
                    return(false);
                }
            }


            try
            {
                /*Creating Deployment*/

                var containerport = new k8s.Models.V1ContainerPort
                {
                    ContainerPort = 80
                };

                var containerports = new List <k8s.Models.V1ContainerPort>
                {
                    containerport
                };

                var container = new k8s.Models.V1Container
                {
                    Name  = containerName,
                    Image = image,
                    Ports = containerports
                };

                var containers = new List <k8s.Models.V1Container>
                {
                    container
                };

                var podSpec = new k8s.Models.V1PodSpec
                {
                    Containers = containers
                };

                var template = new k8s.Models.V1PodTemplateSpec
                {
                    Metadata = new k8s.Models.V1ObjectMeta {
                        Labels = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        }
                    },
                    Spec = podSpec
                };

                var spec = new k8s.Models.Appsv1beta1DeploymentSpec
                {
                    Replicas = numberOfContainers,
                    Selector = new k8s.Models.V1LabelSelector {
                        MatchLabels = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        }
                    },
                    Template = template
                };

                var deployment = new k8s.Models.Appsv1beta1Deployment
                {
                    Metadata = new k8s.Models.V1ObjectMeta {
                        Name = containerName
                    },
                    Spec = spec
                };


                client.CreateNamespacedDeployment1(deployment, "default");


                /*Creating Service*/
                var serviceport = new k8s.Models.V1ServicePort
                {
                    Port = 80
                };

                var serviceports = new List <k8s.Models.V1ServicePort>
                {
                    serviceport
                };

                var service = new k8s.Models.V1Service
                {
                    Spec = new k8s.Models.V1ServiceSpec
                    {
                        Type     = "LoadBalancer",
                        Selector = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        },
                        Ports = serviceports
                    },
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name   = containerName,
                        Labels = new Dictionary <string, string>()
                        {
                            { "functions", containerName }
                        }
                    }
                };

                client.CreateNamespacedService(service, "default");
            }
            catch (Exception ex)
            {
                status = ex.Message;
                return(false);
            }

            status = string.Format("Created container {0}", containerName);
            return(true);
        }
Ejemplo n.º 3
0
 public static bool MatchSelector(this k8s.Models.V1Service svc, string selector)
 {
     return(svc.Metadata.MatchSelector(selector));
 }