public MyStack() { var argocd_serverDeployment = new Kubernetes.Apps.V1.Deployment("argocd_serverDeployment", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs { ApiVersion = "apps/v1", Kind = "Deployment", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Labels = { { "app.kubernetes.io/component", "server" }, { "aws:region", "us-west-2" }, { "key%percent", "percent" }, { "key...ellipse", "ellipse" }, { "key{bracket", "bracket" }, { "key}bracket", "bracket" }, { "key*asterix", "asterix" }, { "key?question", "question" }, { "key,comma", "comma" }, { "key&&and", "and" }, { "key||or", "or" }, { "key!not", "not" }, { "key=>geq", "geq" }, { "key==eq", "equal" }, }, Name = "argocd-server", }, }); }
public Service Deploy(string appName, Pulumi.Kubernetes.Apps.V1.Deployment deployment, bool isLoadBalancer, InputMap <string> appLabels) { var service = new Service(appName, new ServiceArgs { Metadata = new ObjectMetaArgs { Labels = deployment.Spec.Apply(spec => spec.Template.Metadata.Labels ), }, Spec = new ServiceSpecArgs { Type = isLoadBalancer ? "LoadBalancer" : "ClusterIP", Selector = appLabels, Ports = new ServicePortArgs { Port = 80, TargetPort = 80, Protocol = "TCP", }, } }); return(service); }
public MyStack() { var argocd_serverDeployment = new Kubernetes.Apps.V1.Deployment("argocd_serverDeployment", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs { ApiVersion = "apps/v1", Kind = "Deployment", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Name = "argocd-server", }, Spec = new Kubernetes.Types.Inputs.Apps.V1.DeploymentSpecArgs { Template = new Kubernetes.Types.Inputs.Core.V1.PodTemplateSpecArgs { Spec = new Kubernetes.Types.Inputs.Core.V1.PodSpecArgs { Containers = { new Kubernetes.Types.Inputs.Core.V1.ContainerArgs { ReadinessProbe = new Kubernetes.Types.Inputs.Core.V1.ProbeArgs { HttpGet = new Kubernetes.Types.Inputs.Core.V1.HTTPGetActionArgs { Port = 8080, }, }, }, }, }, }, }, }); }
static Task <int> Main() { return(Pulumi.Deployment.RunAsync(() => { //1. Get existed cluster from eks var existedCluster = Pulumi.Aws.Eks.Cluster.Get("your-eks-cluster", "your-eks-cluster"); //2. Create new deployment var cqrsTodoDeployment = new Pulumi.Kubernetes.Apps.V1.Deployment("cqrstodo-deployment", new DeploymentArgs { Metadata = new ObjectMetaArgs { Name = "cqrstodo-deployment", Labels = new InputMap <string> { { "app", "cqrstodo" } } }, Spec = new DeploymentSpecArgs { Replicas = 1, Selector = new LabelSelectorArgs { MatchLabels = new InputMap <string> { { "app", "cqrstodo" } } }, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Name = "cqrstodo", Labels = new InputMap <string> { { "app", "cqrstodo" } } }, Spec = new PodSpecArgs { Containers = new InputList <ContainerArgs> { new ContainerArgs { Name = "cqrstodo", Image = "ecr-url", Ports = new ContainerPortArgs { ContainerPortValue = 80 } } } } } }, }); var output = new Dictionary <string, object> { { "cluster", existedCluster.Name }, { "pod-deployment", cqrsTodoDeployment.GetResourceName() } }; return output; })); }
public MyStack() { var argocd_serverDeployment = new Kubernetes.Apps.V1.Deployment("argocd_serverDeployment", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs { ApiVersion = "apps/v1", Kind = "Deployment", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Name = "argocd-server", }, Spec = new Kubernetes.Types.Inputs.Apps.V1.DeploymentSpecArgs { Selector = new Kubernetes.Types.Inputs.Meta.V1.LabelSelectorArgs { MatchLabels = { { "app", "server" }, }, }, Replicas = 1, Template = new Kubernetes.Types.Inputs.Core.V1.PodTemplateSpecArgs { Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Labels = { { "app", "server" }, }, }, Spec = new Kubernetes.Types.Inputs.Core.V1.PodSpecArgs { Containers = { new Kubernetes.Types.Inputs.Core.V1.ContainerArgs { Name = "nginx", Image = "nginx", ReadinessProbe = new Kubernetes.Types.Inputs.Core.V1.ProbeArgs { HttpGet = new Kubernetes.Types.Inputs.Core.V1.HTTPGetActionArgs { Port = 8080, }, }, }, }, }, }, }, }); }
static Task <int> Main() { return(Pulumi.Deployment.RunAsync(() => { var appLabels = new InputMap <string> { { "app", "nginx" }, }; var deployment = new Pulumi.Kubernetes.Apps.V1.Deployment("nginx", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = appLabels, }, Replicas = 1, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = appLabels, }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "nginx", Image = "nginx", Ports = { new ContainerPortArgs { ContainerPortValue = 80 }, }, }, }, }, }, }, }); return new Dictionary <string, object?> { { "name", deployment.Metadata.Apply(m => m.Name) }, }; })); }
public MyStack() { var appLabels = new InputMap <string> { { "app", "nginx" } }; var deployment = new Pulumi.Kubernetes.Apps.V1.Deployment("nginx", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = appLabels }, Replicas = 1, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = appLabels }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "nginx", Image = "nginx", Ports = { new ContainerPortArgs { ContainerPortValue = 80 } } } } } } } }); this.Name = deployment.Metadata.Apply(m => m.Name); }
public MyStack() { var argocd_serverDeployment = new Kubernetes.Apps.V1.Deployment("argocd_serverDeployment", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs { ApiVersion = "apps/v1", Kind = "Deployment", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Labels = { { "app.kubernetes.io/component", "server" }, { "app.kubernetes.io/instance", "argocd" }, { "app.kubernetes.io/managed-by", "pulumi" }, { "app.kubernetes.io/name", "argocd-server" }, { "app.kubernetes.io/part-of", "argocd" }, { "app.kubernetes.io/version", "v1.6.1" }, { "helm.sh/chart", "argo-cd-2.5.4" }, }, Name = "argocd-server", }, Spec = new Kubernetes.Types.Inputs.Apps.V1.DeploymentSpecArgs { Template = new Kubernetes.Types.Inputs.Core.V1.PodTemplateSpecArgs { Spec = new Kubernetes.Types.Inputs.Core.V1.PodSpecArgs { Containers = { new Kubernetes.Types.Inputs.Core.V1.ContainerArgs { ReadinessProbe = new Kubernetes.Types.Inputs.Core.V1.ProbeArgs { HttpGet = new Kubernetes.Types.Inputs.Core.V1.HTTPGetActionArgs { Port = 8080, }, }, }, }, }, }, }, }); }
public MyStack() { var ns = new K8s.Core.V1.Namespace("app-ns", new K8s.Types.Inputs.Core.V1.NamespaceArgs { Metadata = new K8s.Types.Inputs.Meta.V1.ObjectMetaArgs { Name = "my-name" } }); var appLabels = new InputMap <string> { { "app", "iac-workshop" } }; var deployment = new K8s.Apps.V1.Deployment("app-dep", new K8s.Types.Inputs.Apps.V1.DeploymentArgs { Metadata = new K8s.Types.Inputs.Meta.V1.ObjectMetaArgs { Namespace = ns.Metadata.Apply(m => m.Name) }, Spec = new K8s.Types.Inputs.Apps.V1.DeploymentSpecArgs { Selector = new K8s.Types.Inputs.Meta.V1.LabelSelectorArgs { MatchLabels = appLabels }, Replicas = 1, Template = new K8s.Types.Inputs.Core.V1.PodTemplateSpecArgs { Metadata = new K8s.Types.Inputs.Meta.V1.ObjectMetaArgs { Labels = appLabels }, Spec = new K8s.Types.Inputs.Core.V1.PodSpecArgs { Containers = { new K8s.Types.Inputs.Core.V1.ContainerArgs { Name = "iac-workshop", Image = "gcr.io/google-samples/kubernetes-bootcamp:v1" } } } } } }); }
static Task <int> Main() { return(Deployment.RunAsync(() => { var config = new Config(); var nodeCount = config.GetInt32("nodeCount") ?? 2; var appReplicaCount = config.GetInt32("appReplicaCount") ?? 5; var domainName = config.Get("domainName"); var cluster = new KubernetesCluster("do-cluser", new KubernetesClusterArgs { Region = "sfo2", Version = "latest", NodePool = new KubernetesClusterNodePoolArgs { Name = "default", Size = "s-2vcpu-2gb", NodeCount = nodeCount } }); var k8sProvider = new Provider("do-k8s", new ProviderArgs { KubeConfig = cluster.KubeConfigs.Apply(array => array[0].RawConfig) }); var app = new Pulumi.Kubernetes.Apps.V1.Deployment("do-app-dep", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = { { "app", "app-nginx" } } }, Replicas = appReplicaCount, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = { { "app", "app-nginx" } } }, Spec = new PodSpecArgs { Containers = new ContainerArgs { Name = "nginx", Image = "nginx" } } } } }, new CustomResourceOptions { Provider = k8sProvider }); var appService = new Service("do-app-svc", new ServiceArgs { Spec = new ServiceSpecArgs { Type = "LoadBalancer", Selector = app.Spec.Apply(spec => spec.Template.Metadata.Labels), Ports = new ServicePortArgs { Port = 80 } } }, new CustomResourceOptions { Provider = k8sProvider }); var ingressIp = appService.Status.Apply(status => status.LoadBalancer.Ingress[0].Ip); if (!string.IsNullOrWhiteSpace(domainName)) { var domain = new Domain("do-domain", new DomainArgs { Name = domainName, IpAddress = ingressIp }); var cnameRecord = new DnsRecord("do-domain-cname", new DnsRecordArgs { Domain = domain.Name, Type = "CNAME", Name = "www", Value = "@" }); } return new Dictionary <string, object?> { { "ingressIp", ingressIp } }; })); }
public Deployment Deploy(string name, InputMap <string> appLabels) { var deployment = new Deployment(name, new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = appLabels, }, Replicas = 1, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = appLabels, }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "mssql", Image = "mcr.microsoft.com/mssql/server:2017-CU11-ubuntu", Ports = { new ContainerPortArgs { ContainerPortValue = 1433 }, }, Env = new List <EnvVarArgs> { new EnvVarArgs { Name = "ACCEPT_EULA", Value = "Y" }, new EnvVarArgs { Name = "SA_PASSWORD", ValueFrom = new EnvVarSourceArgs { SecretKeyRef = new SecretKeySelectorArgs { Name = "mssql", Key = "SA_PASSWORD" } } }, }, VolumeMounts = new VolumeMountArgs{ Name = "mssqldb", MountPath = "/var/opt/mssql" } }, }, Volumes = new List <VolumeArgs> { new VolumeArgs { Name = "mssqldb", PersistentVolumeClaim = new PersistentVolumeClaimVolumeSourceArgs { ClaimName = "mssql-volume-claim" }, } } }, }, }, }); return(deployment); }
public MyStack() { var appLabels = new InputMap <string> { { "app", "fistmicroservice" } }; var deployment = new Pulumi.Kubernetes.Apps.V1.Deployment("firstmicroservice", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = appLabels }, Replicas = 1, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = appLabels }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "firstmicroservice", Image = "gopkumr/firstmicroservice:latest", Ports = { new ContainerPortArgs { ContainerPortValue = 80 } } } } } } } }); var frontend = new Service("fistmicroservice", new ServiceArgs { Metadata = new ObjectMetaArgs { Labels = deployment.Spec.Apply(spec => spec.Template.Metadata.Labels ), }, Spec = new ServiceSpecArgs { Type = "LoadBalancer", Selector = appLabels, Ports = new ServicePortArgs { Port = 80, TargetPort = 80, Protocol = "TCP", }, } }); this.IP = frontend.Status.Apply(status => { var ingress = status.LoadBalancer.Ingress[0]; return(ingress.Ip ?? ingress.Hostname); }); }
public MyStack() { var pulumi_kubernetes_operatorDeployment = new Kubernetes.Apps.V1.Deployment("pulumi_kubernetes_operatorDeployment", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs { ApiVersion = "apps/v1", Kind = "Deployment", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Name = "pulumi-kubernetes-operator", }, Spec = new Kubernetes.Types.Inputs.Apps.V1.DeploymentSpecArgs { Replicas = 1, Selector = new Kubernetes.Types.Inputs.Meta.V1.LabelSelectorArgs { MatchLabels = { { "name", "pulumi-kubernetes-operator" }, }, }, Template = new Kubernetes.Types.Inputs.Core.V1.PodTemplateSpecArgs { Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Labels = { { "name", "pulumi-kubernetes-operator" }, }, }, Spec = new Kubernetes.Types.Inputs.Core.V1.PodSpecArgs { ServiceAccountName = "pulumi-kubernetes-operator", ImagePullSecrets = { new Kubernetes.Types.Inputs.Core.V1.LocalObjectReferenceArgs { Name = "pulumi-kubernetes-operator", }, }, Containers = { new Kubernetes.Types.Inputs.Core.V1.ContainerArgs { Name = "pulumi-kubernetes-operator", Image = "pulumi/pulumi-kubernetes-operator:v0.0.2", Command = { "pulumi-kubernetes-operator", }, Args = { "--zap-level=debug", }, ImagePullPolicy = "Always", Env = { new Kubernetes.Types.Inputs.Core.V1.EnvVarArgs { Name = "WATCH_NAMESPACE", ValueFrom = new Kubernetes.Types.Inputs.Core.V1.EnvVarSourceArgs { FieldRef = new Kubernetes.Types.Inputs.Core.V1.ObjectFieldSelectorArgs { FieldPath = "metadata.namespace", }, }, }, new Kubernetes.Types.Inputs.Core.V1.EnvVarArgs { Name = "POD_NAME", ValueFrom = new Kubernetes.Types.Inputs.Core.V1.EnvVarSourceArgs { FieldRef = new Kubernetes.Types.Inputs.Core.V1.ObjectFieldSelectorArgs { FieldPath = "metadata.name", }, }, }, new Kubernetes.Types.Inputs.Core.V1.EnvVarArgs { Name = "OPERATOR_NAME", Value = "pulumi-kubernetes-operator", }, }, }, }, }, }, }, }); var pulumi_kubernetes_operatorRole = new Kubernetes.Rbac.V1.Role("pulumi_kubernetes_operatorRole", new Kubernetes.Types.Inputs.Rbac.V1.RoleArgs { ApiVersion = "rbac.authorization.k8s.io/v1", Kind = "Role", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { CreationTimestamp = null, Name = "pulumi-kubernetes-operator", }, Rules = { new Kubernetes.Types.Inputs.Rbac.V1.PolicyRuleArgs { ApiGroups = { "", }, Resources = { "pods", "services", "services/finalizers", "endpoints", "persistentvolumeclaims", "events", "configmaps", "secrets", }, Verbs = { "create", "delete", "get", "list", "patch", "update", "watch", }, }, new Kubernetes.Types.Inputs.Rbac.V1.PolicyRuleArgs { ApiGroups = { "apps", }, Resources = { "deployments", "daemonsets", "replicasets", "statefulsets", }, Verbs = { "create", "delete", "get", "list", "patch", "update", "watch", }, }, new Kubernetes.Types.Inputs.Rbac.V1.PolicyRuleArgs { ApiGroups = { "monitoring.coreos.com", }, Resources = { "servicemonitors", }, Verbs = { "get", "create", }, }, new Kubernetes.Types.Inputs.Rbac.V1.PolicyRuleArgs { ApiGroups = { "apps", }, ResourceNames = { "pulumi-kubernetes-operator", }, Resources = { "deployments/finalizers", }, Verbs = { "update", }, }, new Kubernetes.Types.Inputs.Rbac.V1.PolicyRuleArgs { ApiGroups = { "", }, Resources = { "pods", }, Verbs = { "get", }, }, new Kubernetes.Types.Inputs.Rbac.V1.PolicyRuleArgs { ApiGroups = { "apps", }, Resources = { "replicasets", "deployments", }, Verbs = { "get", }, }, new Kubernetes.Types.Inputs.Rbac.V1.PolicyRuleArgs { ApiGroups = { "pulumi.com", }, Resources = { "*", }, Verbs = { "create", "delete", "get", "list", "patch", "update", "watch", }, }, }, }); var pulumi_kubernetes_operatorRoleBinding = new Kubernetes.Rbac.V1.RoleBinding("pulumi_kubernetes_operatorRoleBinding", new Kubernetes.Types.Inputs.Rbac.V1.RoleBindingArgs { Kind = "RoleBinding", ApiVersion = "rbac.authorization.k8s.io/v1", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Name = "pulumi-kubernetes-operator", }, Subjects = { new Kubernetes.Types.Inputs.Rbac.V1.SubjectArgs { Kind = "ServiceAccount", Name = "pulumi-kubernetes-operator", }, }, RoleRef = new Kubernetes.Types.Inputs.Rbac.V1.RoleRefArgs { Kind = "Role", Name = "pulumi-kubernetes-operator", ApiGroup = "rbac.authorization.k8s.io", }, }); var pulumi_kubernetes_operatorServiceAccount = new Kubernetes.Core.V1.ServiceAccount("pulumi_kubernetes_operatorServiceAccount", new Kubernetes.Types.Inputs.Core.V1.ServiceAccountArgs { ApiVersion = "v1", Kind = "ServiceAccount", Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs { Name = "pulumi-kubernetes-operator", }, }); }
public EksStack() { // Read back the default VPC and public subnets, which we will use. var vpc = Output.Create(Ec2.GetVpc.InvokeAsync(new Ec2.GetVpcArgs { Default = true })); var vpcId = vpc.Apply(vpc => vpc.Id); var subnet = vpcId.Apply(id => Ec2.GetSubnetIds.InvokeAsync(new Ec2.GetSubnetIdsArgs { VpcId = id })); var subnetIds = subnet.Apply(s => s.Ids); // Create an IAM role that can be used by our service's task. var eksRole = new Iam.Role("eks-iam-eksRole", new Iam.RoleArgs { AssumeRolePolicy = @"{ ""Version"": ""2008-10-17"", ""Statement"": [{ ""Sid"": """", ""Effect"": ""Allow"", ""Principal"": { ""Service"": ""eks.amazonaws.com"" }, ""Action"": ""sts:AssumeRole"" }] }" }); var eksPolicies = new Dictionary <string, string> { { "service-policy", "arn:aws:iam::aws:policy/AmazonEKSServicePolicy" }, { "cluster-policy", "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" } }; foreach (var(name, policy) in eksPolicies) { var taskExecAttach = new Iam.RolePolicyAttachment($"rpa-{name}", new Iam.RolePolicyAttachmentArgs { Role = eksRole.Name, PolicyArn = policy, }); } // Create an IAM role that can be used by our service's task. var nodeGroupRole = new Iam.Role("nodegroup-iam-role", new Iam.RoleArgs { AssumeRolePolicy = @"{ ""Version"": ""2008-10-17"", ""Statement"": [{ ""Sid"": """", ""Effect"": ""Allow"", ""Principal"": { ""Service"": ""ec2.amazonaws.com"" }, ""Action"": ""sts:AssumeRole"" }] }" }); var nodeGroupPolicies = new Dictionary <string, string> { { "worker", "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy" }, { "cni", "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" }, { "registry", "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" } }; foreach (var(name, policy) in nodeGroupPolicies) { var taskExecAttach = new Iam.RolePolicyAttachment($"ngpa-{name}", new Iam.RolePolicyAttachmentArgs { Role = nodeGroupRole.Name, PolicyArn = policy, }); } var clusterSg = new Ec2.SecurityGroup("cluster-sg", new Ec2.SecurityGroupArgs { VpcId = vpcId, Egress = { new Ec2.Inputs.SecurityGroupEgressArgs { Protocol = "-1", FromPort = 0, ToPort = 0, CidrBlocks ={ "0.0.0.0/0" } } }, Ingress = { new Ec2.Inputs.SecurityGroupIngressArgs { Protocol = "tcp", FromPort = 80, ToPort = 80, CidrBlocks ={ "0.0.0.0/0" } } } }); var cluster = new Eks.Cluster("eks-cluster", new Eks.ClusterArgs { RoleArn = eksRole.Arn, VpcConfig = new ClusterVpcConfigArgs { PublicAccessCidrs = { "0.0.0.0/0", }, SecurityGroupIds = { clusterSg.Id, }, SubnetIds = subnetIds, }, }); var nodeGroup = new Eks.NodeGroup("node-group", new Eks.NodeGroupArgs { ClusterName = cluster.Name, NodeGroupName = "demo-eks-nodegroup", NodeRoleArn = nodeGroupRole.Arn, SubnetIds = subnetIds, ScalingConfig = new NodeGroupScalingConfigArgs { DesiredSize = 2, MaxSize = 2, MinSize = 2 }, }); this.Kubeconfig = GenerateKubeconfig(cluster.Endpoint, cluster.CertificateAuthority.Apply(x => x.Data), cluster.Name); var k8sProvider = new K8s.Provider("k8s-provider", new K8s.ProviderArgs { KubeConfig = this.Kubeconfig }, new CustomResourceOptions { DependsOn = { nodeGroup }, }); var appNamespace = new CoreV1.Namespace("app-ns", new NamespaceArgs { Metadata = new ObjectMetaArgs { Name = "joe-duffy", }, }, new CustomResourceOptions { Provider = k8sProvider, }); var appLabels = new InputMap <string> { { "app", "iac-workshop" } }; var deployment = new AppsV1.Deployment("app-dep", new DeploymentArgs { Metadata = new ObjectMetaArgs { Namespace = appNamespace.Metadata.Apply(x => x.Name), }, Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = appLabels }, Replicas = 1, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = appLabels }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "iac-workshop", Image = "jocatalin/kubernetes-bootcamp:v2", } } } } }, }, new CustomResourceOptions { Provider = k8sProvider, }); var service = new CoreV1.Service("app-service", new ServiceArgs { Metadata = new ObjectMetaArgs { Namespace = appNamespace.Metadata.Apply(x => x.Name), Labels = deployment.Spec.Apply(spec => spec.Template.Metadata.Labels), }, Spec = new ServiceSpecArgs { Type = "LoadBalancer", Ports = { new ServicePortArgs { Port = 80, TargetPort = 8080 }, }, Selector = deployment.Spec.Apply(spec => spec.Template.Metadata.Labels) }, }, new CustomResourceOptions { Provider = k8sProvider, }); this.Url = service.Status.Apply(status => status.LoadBalancer.Ingress[0].Hostname); }
static Task <int> Main() => Deployment.RunAsync(async() => { // Create a private GCR registry. var registry = new Registry("my-registry"); var registryUrl = registry.Id.Apply(async _ => { return((await GetRegistryRepository.InvokeAsync()).RepositoryUrl); }); // Get registry info (creds and endpoint). var imageName = Output.Format($"{registryUrl}/myapp"); //var registryInfo = new ImageRegistry(); // use gcloud for authentication. // Build and publish the app image. var image = new Image("my-image", new ImageArgs { Build = new DockerBuild { Context = "app" }, ImageName = imageName, //Registry = registryInfo, }); // Create a load balanced Kubernetes service using this image, and export its IP. var appLabels = new InputMap <string> { { "app", "myapp" } }; var appDep = new Pulumi.Kubernetes.Apps.V1.Deployment("app-dep", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = appLabels }, Replicas = 3, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = appLabels, }, Spec = new PodSpecArgs { Containers = { new Pulumi.Kubernetes.Types.Inputs.Core.V1.ContainerArgs { Name = "myapp", Image = image.ImageName, } } } } } }); var appSvc = new Pulumi.Kubernetes.Core.V1.Service("app-svc", new Pulumi.Kubernetes.Types.Inputs.Core.V1.ServiceArgs { Metadata = new ObjectMetaArgs { Labels = appLabels }, Spec = new ServiceSpecArgs { Type = "LoadBalancer", Ports = { new ServicePortArgs { Port = 80, TargetPort = 80 } }, Selector = appLabels } }); // Export the resulting base name in addition to the specific version pushed. return(new Dictionary <string, object> { { "baseImageName", image.BaseImageName }, { "fullImageName", image.ImageName }, { "appIp", appSvc.Status.Apply(status => status.LoadBalancer.Ingress[0].Ip) }, }); });
public Guestbook() { // Minikube does not implement services of type `LoadBalancer`; require the user to // specify if we're running on minikube, and if so, create only services of type // ClusterIP. var config = new Config(); var isMiniKube = config.GetBoolean("isMiniKube") ?? false; // // REDIS MASTER. // var redisLeaderLabels = new InputMap <string> { { "app", "redis-leader" } }; var redisLeaderDeployment = new Pulumi.Kubernetes.Apps.V1.Deployment("redis-leader", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = redisLeaderLabels }, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = redisLeaderLabels }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "redis-leader", Image = "redis", Resources = new ResourceRequirementsArgs { Requests = { { "cpu", "100m" }, { "memory", "100Mi" } } }, Ports = { new ContainerPortArgs { ContainerPortValue = 6379 } } } } } } } }); var redisLeaderService = new Pulumi.Kubernetes.Core.V1.Service("redis-leader", new ServiceArgs { Metadata = new ObjectMetaArgs { Name = "redis-leader", Labels = redisLeaderDeployment.Metadata.Apply(metadata => metadata.Labels), }, Spec = new ServiceSpecArgs { Ports = { new ServicePortArgs { Port = 6379, TargetPort = 6379 }, }, Selector = redisLeaderDeployment.Spec.Apply(spec => spec.Template.Metadata.Labels) } }); // // REDIS REPLICA. // var redisReplicaLabels = new InputMap <string> { { "app", "redis-replica" } }; var redisReplicaDeployment = new Pulumi.Kubernetes.Apps.V1.Deployment("redis-replica", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = redisReplicaLabels }, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = redisReplicaLabels }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "redis-replica", Image = "pulumi/guestbook-redis-replica", Resources = new ResourceRequirementsArgs { Requests = { { "cpu", "100m" }, { "memory", "100Mi" } } }, // If your cluster config does not include a dns service, then to instead access an environment // variable to find the leader's host, change `value: "dns"` to read `value: "env"`. Env = { new EnvVarArgs { Name = "GET_HOSTS_FROM", Value = "dns" }, }, Ports = { new ContainerPortArgs { ContainerPortValue = 6379 } } } } } } } }); var redisReplicaService = new Pulumi.Kubernetes.Core.V1.Service("redis-replica", new ServiceArgs { Metadata = new ObjectMetaArgs { Name = "redis-replica", Labels = redisReplicaDeployment.Metadata.Apply(metadata => metadata.Labels) }, Spec = new ServiceSpecArgs { Ports = { new ServicePortArgs { Port = 6379, TargetPort = 6379 }, }, Selector = redisReplicaDeployment.Spec.Apply(spec => spec.Template.Metadata.Labels) } }); // // FRONTEND // var frontendLabels = new InputMap <string> { { "app", "frontend" }, }; var frontendDeployment = new Pulumi.Kubernetes.Apps.V1.Deployment("frontend", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = frontendLabels }, Replicas = 3, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = frontendLabels }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "php-redis", Image = "pulumi/guestbook-php-redis", Resources = new ResourceRequirementsArgs { Requests = { { "cpu", "100m" }, { "memory", "100Mi" }, }, }, // If your cluster config does not include a dns service, then to instead access an environment // variable to find the master service's host, change `value: "dns"` to read `value: "env"`. Env = { new EnvVarArgs { Name = "GET_HOSTS_FROM", Value = "dns", /* Value = "env"*/ } }, Ports = { new ContainerPortArgs { ContainerPortValue = 80 } } } } } } } }); var frontendService = new Pulumi.Kubernetes.Core.V1.Service("frontend", new ServiceArgs { Metadata = new ObjectMetaArgs { Name = "frontend", Labels = frontendDeployment.Metadata.Apply(metadata => metadata.Labels) }, Spec = new ServiceSpecArgs { Type = isMiniKube ? "ClusterIP" : "LoadBalancer", Ports = { new ServicePortArgs { Port = 80, TargetPort = 80 } }, Selector = frontendDeployment.Spec.Apply(spec => spec.Template.Metadata.Labels) } }); if (isMiniKube) { this.FrontendIp = frontendService.Spec.Apply(spec => spec.ClusterIP); } else { this.FrontendIp = frontendService.Status.Apply(status => status.LoadBalancer.Ingress[0].Ip ?? status.LoadBalancer.Ingress[0].Hostname); } }
public MyStack() { var ns = new K8s.Core.V1.Namespace("app-ns", new K8s.Types.Inputs.Core.V1.NamespaceArgs { Metadata = new K8s.Types.Inputs.Meta.V1.ObjectMetaArgs { Name = "my-name" } }); var appLabels = new InputMap <string> { { "app", "iac-workshop" } }; var deployment = new K8s.Apps.V1.Deployment("app-dep", new K8s.Types.Inputs.Apps.V1.DeploymentArgs { Metadata = new K8s.Types.Inputs.Meta.V1.ObjectMetaArgs { Namespace = ns.Metadata.Apply(m => m.Name) }, Spec = new K8s.Types.Inputs.Apps.V1.DeploymentSpecArgs { Selector = new K8s.Types.Inputs.Meta.V1.LabelSelectorArgs { MatchLabels = appLabels }, Replicas = 1, Template = new K8s.Types.Inputs.Core.V1.PodTemplateSpecArgs { Metadata = new K8s.Types.Inputs.Meta.V1.ObjectMetaArgs { Labels = appLabels }, Spec = new K8s.Types.Inputs.Core.V1.PodSpecArgs { Containers = { new K8s.Types.Inputs.Core.V1.ContainerArgs { Name = "iac-workshop", Image = "gcr.io/google-samples/kubernetes-bootcamp:v1" } } } } } }); var service = new K8s.Core.V1.Service("app-svc", new K8s.Types.Inputs.Core.V1.ServiceArgs { Metadata = new K8s.Types.Inputs.Meta.V1.ObjectMetaArgs { Namespace = ns.Metadata.Apply(m => m.Name) }, Spec = new K8s.Types.Inputs.Core.V1.ServiceSpecArgs { Selector = appLabels, Ports = { new K8s.Types.Inputs.Core.V1.ServicePortArgs { Port = 80, TargetPort = 8080 } }, Type = "LoadBalancer" } }); var address = service.Status .Apply(s => s.LoadBalancer) .Apply(lb => lb.Ingress) .GetAt(0) .Apply(i => i.Ip); this.Url = Output.Format($"http://{address}"); }
public ServiceDeployment(string name, ServiceDeploymentArgs args, ComponentResourceOptions?opts = null) : base(name, "k8sx:service:ServiceDeployment", opts) { var labels = new InputMap <string> { { "app", name }, }; var deploymentPorts = args.Ports.ToOutput().Apply(ports => from p in ports select new ContainerPortArgs { ContainerPortValue = 6379 } ); var container = new ContainerArgs { Name = name, Image = args.Image, Resources = args.Resources ?? new ResourceRequirementsArgs { Requests = { { "cpu", "100m" }, { "memory", "100Mi" }, }, }, Env = args.Env, Ports = deploymentPorts, }; this.Deployment = new Pulumi.Kubernetes.Apps.V1.Deployment(name, new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = labels, }, Replicas = args.Replicas ?? 1, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = labels, }, Spec = new PodSpecArgs { Containers = { container }, }, }, }, }, new CustomResourceOptions { Parent = this }); var servicePorts = args.Ports.ToOutput().Apply(ports => from p in ports select new ServicePortArgs { Port = p, TargetPort = p } ); this.Service = new Pulumi.Kubernetes.Core.V1.Service(name, new ServiceArgs { Metadata = new ObjectMetaArgs { Name = name, Labels = this.Deployment.Metadata.Apply(metadata => metadata.Labels), }, Spec = new ServiceSpecArgs { Type = args.AllocateIPAddress.Apply(hasIp => hasIp ? (args.ServiceType ?? "LoadBalancer") : null), Ports = servicePorts, Selector = this.Deployment.Spec.Apply(spec => spec.Template.Metadata.Labels), }, }, new CustomResourceOptions { Parent = this }); this.IpAddress = args.AllocateIPAddress.Apply(hasIp => { if (hasIp) { return(args.ServiceType.Apply(serviceType => serviceType == "ClusterIP" ? this.Service.Spec.Apply(s => s.ClusterIP) : this.Service.Status.Apply(status => { var ingress = status.LoadBalancer.Ingress[0]; // Return the ip address if populated or else the hostname return ingress.Ip ?? ingress.Hostname; }) )); } else { return(null); } }); }
static Task <int> Main(string[] args) { return(Deployment.RunAsync(() => { // Minikube does not implement services of type `LoadBalancer`; require the user to // specify if we're running on minikube, and if so, create only services of type // ClusterIP. var config = new Config(); var isMiniKube = config.GetBoolean("isMiniKube") ?? false; // // REDIS MASTER. // var redisMasterLabels = new InputMap <string> { { "app", "redis-master" }, }; var redisMasterDeployment = new Pulumi.Kubernetes.Apps.V1.Deployment("redis-master", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = redisMasterLabels, }, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = redisMasterLabels, }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "master", Image = "k8s.gcr.io/redis:e2e", Resources = new ResourceRequirementsArgs { Requests = { { "cpu", "100m" }, { "memory", "100Mi" }, }, }, Ports = { new ContainerPortArgs { ContainerPortValue = 6379 } }, }, }, }, }, }, }); var redisMasterService = new Pulumi.Kubernetes.Core.V1.Service("redis-master", new ServiceArgs { Metadata = new ObjectMetaArgs { Name = "redis-master", Labels = redisMasterDeployment.Metadata.Apply(metadata => metadata.Labels), }, Spec = new ServiceSpecArgs { Ports = { new ServicePortArgs { Port = 6379, TargetPort = 6379, }, }, Selector = redisMasterDeployment.Spec.Apply(spec => spec.Template.Metadata.Labels), } }); // // REDIS REPLICA. // var redisReplicaLabels = new InputMap <string> { { "app", "redis-replica" }, }; var redisReplicaDeployment = new Pulumi.Kubernetes.Apps.V1.Deployment("redis-replica", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = redisReplicaLabels, }, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = redisReplicaLabels, }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "replica", Image = "gcr.io/google_samples/gb-redisslave:v1", Resources = new ResourceRequirementsArgs { Requests = { { "cpu", "100m" }, { "memory", "100Mi" }, }, }, // If your cluster config does not include a dns service, then to instead access an environment // variable to find the master service's host, change `value: "dns"` to read `value: "env"`. Env = { new EnvVarArgs { Name = "GET_HOSTS_FROM", Value = "dns" }, }, Ports = { new ContainerPortArgs { ContainerPortValue = 6379 } }, }, }, }, }, }, }); var redisReplicaService = new Pulumi.Kubernetes.Core.V1.Service("redis-replica", new ServiceArgs { Metadata = new ObjectMetaArgs { Name = "redis-slave", Labels = redisReplicaDeployment.Metadata.Apply(metadata => metadata.Labels), }, Spec = new ServiceSpecArgs { Ports = { new ServicePortArgs { Port = 6379, TargetPort = 6379, }, }, Selector = redisReplicaDeployment.Spec.Apply(spec => spec.Template.Metadata.Labels), } }); // // FRONTEND // var frontendLabels = new InputMap <string> { { "app", "frontend" }, }; var frontendDeployment = new Pulumi.Kubernetes.Apps.V1.Deployment("frontend", new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = frontendLabels, }, Replicas = 3, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = frontendLabels, }, Spec = new PodSpecArgs { Containers = { new ContainerArgs { Name = "php-redis", Image = "gcr.io/google-samples/gb-frontend:v4", Resources = new ResourceRequirementsArgs { Requests = { { "cpu", "100m" }, { "memory", "100Mi" }, }, }, // If your cluster config does not include a dns service, then to instead access an environment // variable to find the master service's host, change `value: "dns"` to read `value: "env"`. Env = { new EnvVarArgs { Name = "GET_HOSTS_FROM", Value = "dns", /* Value = "env"*/ }, }, Ports = { new ContainerPortArgs { ContainerPortValue = 80 } }, }, }, }, }, }, }); var frontendService = new Pulumi.Kubernetes.Core.V1.Service("frontend", new ServiceArgs { Metadata = new ObjectMetaArgs { Name = "frontend", Labels = frontendDeployment.Metadata.Apply(metadata => metadata.Labels), }, Spec = new ServiceSpecArgs { Type = isMiniKube ? "ClusterIP" : "LoadBalancer", Ports = { new ServicePortArgs { Port = 80, TargetPort = 80, }, }, Selector = frontendDeployment.Spec.Apply(spec => spec.Template.Metadata.Labels), } }); Output <string> frontendIP; if (isMiniKube) { frontendIP = frontendService.Spec.Apply(spec => spec.ClusterIP); } else { frontendIP = frontendService.Status.Apply(status => status.LoadBalancer.Ingress[0].Hostname); } return new Dictionary <string, object> { { "frontendIp", frontendIP }, }; })); }
public AksStack() { var resourceGroup = new ResourceGroup("aks-rg"); var randomPassword = new RandomPassword("password", new RandomPasswordArgs { Length = 20, Special = true, }).Result; var sshPublicKey = new PrivateKey("ssh-key", new PrivateKeyArgs { Algorithm = "RSA", RsaBits = 4096, }).PublicKeyOpenssh; // Create the AD service principal for the K8s cluster. var adApp = new Application("aks"); var adSp = new ServicePrincipal("aksSp", new ServicePrincipalArgs { ApplicationId = adApp.ApplicationId }); var adSpPassword = new ServicePrincipalPassword("aksSpPassword", new ServicePrincipalPasswordArgs { ServicePrincipalId = adSp.Id, Value = randomPassword, EndDate = "2099-01-01T00:00:00Z", }); // Grant networking permissions to the SP (needed e.g. to provision Load Balancers). var assignment = new Assignment("role-assignment", new AssignmentArgs { PrincipalId = adSp.Id, Scope = resourceGroup.Id, RoleDefinitionName = "Network Contributor" }); // Create a Virtual Network for the cluster. var vnet = new VirtualNetwork("vnet", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, AddressSpaces = { "10.2.0.0/16" }, }); // Create a Subnet for the cluster. var subnet = new Subnet("subnet", new SubnetArgs { ResourceGroupName = resourceGroup.Name, VirtualNetworkName = vnet.Name, AddressPrefix = "10.2.1.0/24", }); // Now allocate an AKS cluster. var cluster = new KubernetesCluster("aksCluster", new KubernetesClusterArgs { ResourceGroupName = resourceGroup.Name, DefaultNodePool = new KubernetesClusterDefaultNodePoolArgs { Name = "aksagentpool", NodeCount = 3, VmSize = "Standard_B2s", OsDiskSizeGb = 30, VnetSubnetId = subnet.Id }, DnsPrefix = "sampleaks", LinuxProfile = new KubernetesClusterLinuxProfileArgs { AdminUsername = "******", SshKey = new KubernetesClusterLinuxProfileSshKeyArgs { KeyData = sshPublicKey, }, }, ServicePrincipal = new KubernetesClusterServicePrincipalArgs { ClientId = adApp.ApplicationId, ClientSecret = adSpPassword.Value, }, KubernetesVersion = "1.16.9", RoleBasedAccessControl = new KubernetesClusterRoleBasedAccessControlArgs { Enabled = true }, NetworkProfile = new KubernetesClusterNetworkProfileArgs { NetworkPlugin = "azure", DnsServiceIp = "10.2.2.254", ServiceCidr = "10.2.2.0/24", DockerBridgeCidr = "172.17.0.1/16", }, }); // Create a k8s provider pointing to the kubeconfig. var k8sProvider = new Pulumi.Kubernetes.Provider("k8s", new Pulumi.Kubernetes.ProviderArgs { KubeConfig = cluster.KubeConfigRaw }); var customResourceOptions = new CustomResourceOptions { Provider = k8sProvider }; // Create a Container Registry. var registry = new Registry("acregistry", new RegistryArgs { ResourceGroupName = resourceGroup.Name, Sku = "Basic", AdminEnabled = true }); // Build & push the sample application to the registry. var applicationName = "sample-application"; var imageName = registry.LoginServer.Apply(value => $"{value}/{applicationName}"); var image = new Image(applicationName, new ImageArgs { Build = "./SampleApplication", Registry = new ImageRegistry { Server = registry.LoginServer, Username = registry.AdminUsername, Password = registry.AdminPassword }, ImageName = imageName }, new ComponentResourceOptions { Provider = k8sProvider }); // Create a k8s secret for use when pulling images from the container registry when deploying the sample application. var dockerCfg = Output.All <string>(registry.LoginServer, registry.AdminUsername, registry.AdminPassword).Apply( values => { var r = new Dictionary <string, object>(); var server = values[0]; var username = values[1]; var password = values[2]; r[server] = new { email = "*****@*****.**", username, password }; return(r); }); var dockerCfgString = dockerCfg.Apply(x => Convert.ToBase64String(Encoding.UTF8.GetBytes(System.Text.Json.JsonSerializer.Serialize(x)))); var dockerCfgSecretName = "dockercfg-secret"; var dockerCfgSecret = new Pulumi.Kubernetes.Core.V1.Secret(dockerCfgSecretName, new SecretArgs { Data = { { ".dockercfg", dockerCfgString } }, Type = "kubernetes.io/dockercfg", Metadata = new ObjectMetaArgs { Name = dockerCfgSecretName, } }, customResourceOptions); // Deploy the sample application to the cluster. var labels = new InputMap <string> { { "app", $"app-{applicationName}" }, }; var deployment = new Pulumi.Kubernetes.Apps.V1.Deployment(applicationName, new DeploymentArgs { Spec = new DeploymentSpecArgs { Selector = new LabelSelectorArgs { MatchLabels = labels, }, Replicas = 1, Template = new PodTemplateSpecArgs { Metadata = new ObjectMetaArgs { Labels = labels, Name = applicationName }, Spec = new PodSpecArgs { Containers = new List <ContainerArgs> { new ContainerArgs { Name = applicationName, Image = image.ImageName, } }, ImagePullSecrets = new LocalObjectReferenceArgs { Name = dockerCfgSecretName } } } } }, customResourceOptions); // Create a new service. var service = new Pulumi.Kubernetes.Core.V1.Service(applicationName, new ServiceArgs { Metadata = new ObjectMetaArgs { Name = applicationName, Labels = labels }, Spec = new ServiceSpecArgs { Type = "LoadBalancer", Selector = deployment.Spec.Apply(x => x.Template.Metadata.Labels), Ports = new ServicePortArgs { Port = 80 } } }, customResourceOptions); this.KubeConfig = cluster.KubeConfigRaw; this.DockercfgSecretName = dockerCfgSecret.Metadata.Apply(x => x.Name); }