Esempio n. 1
0
    def __init__(self,
                 name: str,
                 replicas: int = 1,
                 image: str = None,
                 ports: [int] = None,
                 envvars: [dict] = None,
                 opts: ResourceOptions = None):

        super().__init__("my:modules:SimpleDeployment", name, {}, opts)

        labels = {"app": name}
        container = {
            "name": name,
            "image": image,
            "ports": [{
                "container_port": p
            } for p in ports] if ports else None,
            "env": envvars,
        }

        self.deployment = Deployment(name,
                                     spec={
                                         "selector": {
                                             "match_labels": labels
                                         },
                                         "replicas": replicas,
                                         "template": {
                                             "metadata": {
                                                 "labels": labels
                                             },
                                             "spec": {
                                                 "containers": [container]
                                             },
                                         },
                                     },
                                     opts=ResourceOptions(parent=self))

        self.service = Service(
            name,
            metadata={
                "name": name,
                "labels": self.deployment.metadata['labels'],
            },
            spec={
                "ports": [{
                    "port": p,
                    "targetPort": p
                } for p in ports] if ports else None,
                "selector":
                self.deployment.spec['template']['metadata']['labels'],
                "type":
                "LoadBalancer",
            },
            opts=ResourceOptions(parent=self))

        self.register_outputs({})
Esempio n. 2
0
    def __init__(self, name: str, image: str,
                 resources: ResourceRequirementsArgs = None, replicas: int = None,
                 ports: Sequence[int] = None, allocate_ip_address: bool = None,
                 is_minikube: bool = None, opts: ResourceOptions = None):
        super().__init__('k8sx:component:ServiceDeployment', name, {}, opts)

        labels = {"app": name}
        container = ContainerArgs(
            name=name,
            image=image,
            resources=resources or ResourceRequirementsArgs(
                requests={
                    "cpu": "100m",
                    "memory": "100Mi"
                },
            ),
            ports=[ContainerPortArgs(container_port=p) for p in ports] if ports else None,
        )
        self.deployment = Deployment(
            name,
            spec=DeploymentSpecArgs(
                selector=LabelSelectorArgs(match_labels=labels),
                replicas=replicas if replicas is not None else 1,
                template=PodTemplateSpecArgs(
                    metadata=ObjectMetaArgs(labels=labels),
                    spec=PodSpecArgs(containers=[container]),
                ),
            ),
            opts=pulumi.ResourceOptions(parent=self))
        self.service = Service(
            name,
            metadata=ObjectMetaArgs(
                name=name,
                labels=self.deployment.metadata.apply(lambda m: m.labels),
            ),
            spec=ServiceSpecArgs(
                ports=[ServicePortArgs(port=p, target_port=p) for p in ports] if ports else None,
                selector=self.deployment.spec.apply(lambda s: s.template.metadata.labels),
                type=("ClusterIP" if is_minikube else "LoadBalancer") if allocate_ip_address else None,
            ),
            opts=pulumi.ResourceOptions(parent=self))
        if allocate_ip_address:
            if is_minikube:
                self.ip_address = self.service.spec.apply(lambda s: s.cluster_ip)
            else:
                ingress=self.service.status.apply(lambda s: s.load_balancer.ingress[0])
                self.ip_address = ingress.apply(lambda i: ingress.ip or ingress.hostname or "")
        self.register_outputs({})
Esempio n. 3
0
    def __init__(self, name, args, opts=None):
        super().__init__("ServiceDeployment", name, {}, opts)
        self.name = name
        self.labels = {"app": name}
        self.deployment = Deployment(name,
                                     spec={
                                         "selector": {
                                             "match_labels": self.labels
                                         },
                                         "replicas": args.get("replicas", 1),
                                         "template": {
                                             "metadata": {
                                                 "labels": self.labels
                                             },
                                             "spec": {
                                                 "containers": [{
                                                     "name":
                                                     self.name,
                                                     "image":
                                                     args.get("image")
                                                 }]
                                             }
                                         }
                                     })

        self.service = Service(name,
                               spec={
                                   "type":
                                   args.get("serviceType", "ClusterIP"),
                                   "ports": [{
                                       "port":
                                       args.get("port"),
                                       "targetPort":
                                       args.get("port"),
                                       "protocol":
                                       args.get("protocol", "TCP")
                                   }],
                                   "selector":
                                   self.labels
                               })

        pulumi.export(
            "frontendIp",
            self.service.status["load_balancer"]["ingress"][0]["hostname"])
Esempio n. 4
0
app_labels = { "app": "app-nginx" }
app = Deployment(
    "do-app-dep",
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=app_labels),
        replicas=1,
        template=PodTemplateSpecArgs(
            metadata=ObjectMetaArgs(labels=app_labels),
            spec=PodSpecArgs(containers=[ContainerArgs(name='nginx', image='nginx')]),
        ),
    ), opts=ResourceOptions(provider=k8s_provider))

ingress = Service(
    'do-app-svc',
    spec=ServiceSpecArgs(
        type='LoadBalancer',
        selector=app_labels,
        ports=[ServicePortArgs(port=80)],
    ), opts=ResourceOptions(provider=k8s_provider, custom_timeouts=CustomTimeouts(create="15m", delete="15m")))

ingress_ip = ingress.status.apply(lambda s: s.load_balancer.ingress[0].ip)

export('ingress_ip', ingress_ip)

if domain_name:
    domain = do.Domain(
        "do-domain",
        name=domain_name,
        ip_address=ingress_ip)

    cname_record = do.DnsRecord(
Esempio n. 5
0
    def __init__(self, name, credentials, resources, image=None, opts=None):
        super().__init__("jenkins:jenkins:Instance", name, {
            "credentials": credentials,
            "resources": resources,
            "image": image
        }, opts)

        # The Secret will contain the root password for this instance.
        secret = Secret(
            name + "-secret",
            metadata=ObjectMetaArgs(name=name, ),
            type="Opaque",
            data={
                "jenkins-password":
                str(
                    base64.b64encode(bytes(credentials["password"], "utf-8"),
                                     None), "utf-8"),
            },
            opts=ResourceOptions(parent=self),
        )

        # The PVC provides persistent storage for Jenkins states.
        pvc = PersistentVolumeClaim(
            name + "-pvc",
            metadata=ObjectMetaArgs(name=name, ),
            spec=PersistentVolumeClaimSpecArgs(
                access_modes=["ReadWriteOnce"],
                resources=ResourceRequirementsArgs(requests={
                    "storage": "8Gi",
                }, ),
            ),
            opts=ResourceOptions(parent=self),
        )

        # The Deployment describes the desired state for our Jenkins setup.
        deploymentArgs = create_deployment_args(name, credentials, resources,
                                                image)
        deployment = Deployment(
            name + "-deploy",
            metadata=deploymentArgs.metadata,
            spec=deploymentArgs.spec,
            opts=ResourceOptions(parent=self),
        )

        # The Service exposes Jenkins to the external internet by providing load-balanced ingress for HTTP and HTTPS.
        service = Service(name + "-service",
                          metadata=ObjectMetaArgs(name=name, ),
                          spec=ServiceSpecArgs(
                              type="LoadBalancer",
                              ports=[
                                  ServicePortArgs(
                                      name="http",
                                      port=80,
                                      target_port="http",
                                  ),
                                  ServicePortArgs(
                                      name="https",
                                      port=443,
                                      target_port="https",
                                  ),
                              ],
                              selector={
                                  "app": name,
                              },
                          ),
                          opts=ResourceOptions(parent=self))

        ingress = service.status.apply(lambda s: s.load_balancer.ingress[0])
        self.external_ip = ingress.apply(lambda x: x.ip or x.hostname)
        self.register_outputs({"external_ip": self.external_ip})
Esempio n. 6
0
                                        "image": "nginx"
                                    }]
                                }
                            }
                        })

port = {"port": 80, "target_port": 80, "protocol": "TCP"}

if is_minikube:
    port.update(node_port=30000)

frontend = Service(app_name,
                   metadata={
                       "labels":
                       deployment.spec["template"]["metadata"]["labels"],
                   },
                   spec={
                       "type": "NodePort" if is_minikube else "LoadBalancer",
                       "ports": [port],
                       "selector": app_labels,
                   })

# When "done", this will print the public IP.
if is_minikube:
    pulumi.export(
        "ip",
        frontend.spec.apply(lambda v: v["cluster_ip"]
                            if "cluster_ip" in v else None))
else:
    pulumi.export(
        "ip",
        frontend.status.apply(lambda v: v["load_balancer"]["ingress"][0]["ip"]
Esempio n. 7
0
                             'containers': [{
                                 'name': 'nginx',
                                 'image': 'nginx'
                             }]
                         },
                     },
                 },
                 __opts__=ResourceOptions(provider=k8s_provider))

ingress = Service('do-app-svc',
                  spec={
                      'type': 'LoadBalancer',
                      'selector': app_labels,
                      'ports': [{
                          'port': 80
                      }],
                  },
                  __opts__=ResourceOptions(provider=k8s_provider,
                                           custom_timeouts={
                                               "create": "15m",
                                               "delete": "15m"
                                           }))

ingress_ip = ingress.status['load_balancer']['ingress'][0]['ip']

export('ingress_ip', ingress_ip)

if domain_name:
    domain = do.Domain("do-domain", name=domain_name, ip_address=ingress_ip)

    cname_record = do.DnsRecord("do-domain-name",
Esempio n. 8
0
            },
            "spec": {
                "containers": [{
                    "name": "iac-workshop",
                    "image": "gcr.io/google-samples/kubernetes-bootcamp:v1",
                }],
            },
        },
    },
    opts=ResourceOptions(provider=k8s_provider)
)

service = Service("app-service",
    metadata={
      "namespace": ns.metadata["name"],
      "labels": app_labels
    },
    spec={
      "ports": [{
          "port": 80,
          "target_port": 8080,
      }],
      "selector": app_labels,
      "type": "LoadBalancer",
    },
    opts=ResourceOptions(provider=k8s_provider)
)

export('url', Output.all(service.status['load_balancer']['ingress'][0]['hostname'], service.spec['ports'][0]['port']) \
       .apply(lambda args: f"http://{args[0]}:{round(args[1])}"))
Esempio n. 9
0
                    image="redis",
                    resources=ResourceRequirementsArgs(requests={
                        "cpu": "100m",
                        "memory": "100Mi",
                    }, ),
                    ports=[ContainerPortArgs(container_port=6379, )],
                )
            ], ),
        ),
    ))

redis_leader_service = Service(
    "redis-leader",
    metadata=ObjectMetaArgs(name="redis-leader", labels=redis_leader_labels),
    spec=ServiceSpecArgs(
        ports=[ServicePortArgs(
            port=6379,
            target_port=6379,
        )],
        selector=redis_leader_labels))

redis_replica_labels = {
    "app": "redis-replica",
}

redis_replica_deployment = Deployment(
    "redis-replica",
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=redis_replica_labels),
        replicas=1,
        template=PodTemplateSpecArgs(
Esempio n. 10
0
                                    }],
                                    "volumes": [{
                                        "name": "secret-volume",
                                        "secret": {
                                            "secretName":
                                            secret.metadata['name']
                                        }
                                    }]
                                }
                            }
                        })

service = Service("service",
                  spec={
                      "selector": app_labels,
                      "ports": [{
                          "port": 80,
                      }]
                  })

hostname = "{}.dev.renku.ch".format(k8s_config.require("namespace"))

ingress = Ingress("ingress",
                  spec={
                      "rules": [{
                          "host": hostname,
                          "http": {
                              "paths": [{
                                  "path": "/nginx-test",
                                  "backend": {
                                      "serviceName": service.metadata["name"],
                            "selector": {
                                "match_labels": app_labels
                            },
                            "replicas": 1,
                            "template": {
                                "metadata": {
                                    "labels": app_labels
                                },
                                "spec": spec
                            }
                        })

frontend = Service("flask",
                   metadata={
                       "labels":
                       deployment.spec["template"]["metadata"]["labels"],
                   },
                   spec={
                       "type":
                       "LoadBalancer",
                       "ports": [{
                           "port": 80,
                           "target_port": 80,
                           "protocol": "TCP"
                       }],
                       "selector":
                       app_labels,
                   })

pulumi.export("name", deployment.metadata["name"])
Esempio n. 12
0
k8s_provider = Provider('gke_k8s', kubeconfig=k8s_config)

# Create a canary deployment to test that this cluster works.
labels = {'app': 'canary-{0}-{1}'.format(get_project(), get_stack())}
canary = Deployment(
    'canary',
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=labels),
        replicas=1,
        template=PodTemplateSpecArgs(
            metadata=ObjectMetaArgs(labels=labels),
            spec=PodSpecArgs(
                containers=[ContainerArgs(name='nginx', image='nginx')]),
        ),
    ),
    opts=ResourceOptions(provider=k8s_provider))

ingress = Service('ingress',
                  spec=ServiceSpecArgs(
                      type='LoadBalancer',
                      selector=labels,
                      ports=[ServicePortArgs(port=80)],
                  ),
                  opts=ResourceOptions(provider=k8s_provider))

# Finally, export the kubeconfig so that the client can easily access the cluster.
export('kubeconfig', k8s_config)
# Export the k8s ingress IP to access the canary deployment
export('ingress_ip',
       ingress.status.apply(lambda status: status.load_balancer.ingress[0].ip))
Esempio n. 13
0
k8s_provider = Provider(
    "k8s",
    kubeconfig=aks.kube_config_raw,
)

labels = {"app": "nginx"}
nginx = Deployment(
    "k8s-nginx",
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=labels),
        replicas=1,
        template=PodTemplateSpecArgs(
            metadata=ObjectMetaArgs(labels=labels),
            spec=PodSpecArgs(
                containers=[ContainerArgs(name="nginx", image="nginx")]),
        ),
    ),
    opts=ResourceOptions(parent=k8s_provider, provider=k8s_provider),
)

ingress = Service(
    "k8s-nginx",
    spec=ServiceSpecArgs(type="LoadBalancer",
                         selector=labels,
                         ports=[ServicePortArgs(port=80)]),
    opts=ResourceOptions(parent=k8s_provider, provider=k8s_provider),
)

pulumi.export("kubeconfig", aks.kube_config_raw)
                                "match_labels": app_labels
                            },
                            "replicas": 1,
                            "template": {
                                "metadata": {
                                    "labels": app_labels
                                },
                                "spec": {
                                    "containers": [{
                                        "name": "nginx",
                                        "image": "nginx"
                                    }]
                                }
                            }
                        })

service = Service("nginx",
                  spec={
                      "type": "LoadBalancer",
                      "ports": [{
                          "port": 80,
                          "targetPort": 80,
                          "protocol": "TCP"
                      }],
                      "selector": app_labels
                  })

pulumi.export("name", deployment.metadata["name"])
pulumi.export("frontendIp",
              service.status["load_balancer"]["ingress"][0]["hostname"])
Esempio n. 15
0
                    image="k8s.gcr.io/redis:e2e",
                    resources=ResourceRequirementsArgs(requests={
                        "cpu": "100m",
                        "memory": "100Mi",
                    }, ),
                    ports=[ContainerPortArgs(container_port=6379, )],
                )
            ], ),
        ),
    ))

redis_leader_service = Service(
    "redis-leader",
    metadata=ObjectMetaArgs(namespace=namespace, labels=redis_leader_labels),
    spec=ServiceSpecArgs(
        ports=[ServicePortArgs(
            port=6379,
            target_port=6379,
        )],
        selector=redis_leader_labels))

redis_follower_labels = {"app": "redis", "tier": "backend", "role": "slave"}

redis_follower_deployment = Deployment(
    "redis-follower",
    metadata=ObjectMetaArgs(namespace=namespace),
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=redis_follower_labels),
        replicas=1,
        template=PodTemplateSpecArgs(
            metadata=ObjectMetaArgs(labels=redis_follower_labels, ),
Esempio n. 16
0
    def __init__(self,
                 name: str,
                 image: str,
                 resources: dict = None,
                 replicas: int = None,
                 ports: List[int] = None,
                 allocate_ip_address: bool = None,
                 is_minikube: bool = None,
                 opts: ResourceOptions = None):
        super().__init__('k8sx:component:ServiceDeployment', name, {}, opts)

        labels = {"app": name}
        container = {
            "name": name,
            "image": image,
            "resources": resources or {
                "requests": {
                    "cpu": "100m",
                    "memory": "100Mi"
                }
            },
            "ports": [{
                "container_port": p
            } for p in ports] if ports else None,
        }
        self.deployment = Deployment(name,
                                     spec={
                                         "selector": {
                                             "match_labels": labels
                                         },
                                         "replicas": 1,
                                         "template": {
                                             "metadata": {
                                                 "labels": labels
                                             },
                                             "spec": {
                                                 "containers": [container]
                                             },
                                         },
                                     },
                                     opts=pulumi.ResourceOptions(parent=self))
        self.service = Service(
            name,
            metadata={
                "name": name,
                "labels": self.deployment.metadata['labels'],
            },
            spec={
                "ports": [{
                    "port": p,
                    "targetPort": p
                } for p in ports] if ports else None,
                "selector":
                self.deployment.spec['template']['metadata']['labels'],
                "type": ("ClusterIP" if is_minikube else "LoadBalancer")
                if allocate_ip_address else None,
            },
            opts=pulumi.ResourceOptions(parent=self))
        if allocate_ip_address:
            if is_minikube:
                self.ip_address = self.service.spec['clusterIP']
            else:
                ingress = self.service.status['load_balancer']['ingress'][0]
                self.ip_address = ingress.apply(lambda i: ingress["ip"] if "ip"
                                                in i else ingress['hostname'])
        self.register_outputs({})
Esempio n. 17
0
                                            "name": "http",
                                            "containerPort": 80
                                        }]
                                    }]
                                }
                            }
                        },
                        __opts__=ResourceOptions(provider=custom_provider))

# Create nginx service
service = Service(name,
                  metadata={"labels": appLabels},
                  spec={
                      "ports": [{
                          "name": "http",
                          "port": 80
                      }],
                      "selector": appLabels,
                      "type": "LoadBalancer",
                  },
                  __opts__=ResourceOptions(provider=custom_provider))

# Export
pulumi.export('storage_connection_string', account.primary_connection_string)
pulumi.export('resource_group_id', rg.id)
pulumi.export('kubeconfig', aks.kube_config_raw)
pulumi.export('namespace_name',
              namespace.metadata.apply(lambda resource: resource['name']))
pulumi.export('deployment_name',
              deployment.metadata.apply(lambda resource: resource['name']))
pulumi.export('service_name',
Esempio n. 18
0
                        "value": cosmos_db_database.name
                    }, {
                        "name": "cosmosDbCollectionId",
                        "value": cosmos_db_container.name
                    }]
                }]
            },
        },
    },
    __opts__=ResourceOptions(parent=k8s_provider, provider=k8s_provider),
)

ingress = Service(
    "k8s-polaris-service",
    spec={
        "type": "LoadBalancer",
        "selector": labels,
        "ports": [{
            "port": 8080
        }]
    },
    __opts__=ResourceOptions(parent=k8s_provider, provider=k8s_provider),
)
pulumi.export("ingress_ip", ingress)
pulumi.export("kubeconfig", aks.kube_config_raw)
pulumi.export("cosmos_db_account_name", cosmos_db_account.name)
pulumi.export("cosmos_db_container_name", cosmos_db_container.name)
pulumi.export("acr_login_server", acr.login_server)
pulumi.export("acr_password", acr.admin_password)
pulumi.export("acr_username", acr.admin_username)
Esempio n. 19
0
def create():
    app_labels = {"app": "nginx"}

    serviceAccount = ServiceAccount("coredns",
                                    metadata={
                                        "name": "coredns",
                                        "namespace": "kube-system"
                                    })

    clusterRole = ClusterRole(
        "system:coredns",
        metadata={
            "name": "system:coredns",
            "labels": {
                "kubernetes.io/bootstrapping": "rbac-defaults"
            }
        },
        rules=[{
            "apiGroups": [""],
            "resources": ["endpoints", "services", "pods", "namespaces"],
            "verbs": ["list", "watch"]
        }])

    clusterRoleBinding = ClusterRoleBinding(
        "system:coredns",
        metadata={
            "name": "system:coredns",
            "labels": {
                "kubernetes.io/bootstrapping": "rbac-defaults"
            },
            "annotations": {
                "rbac.authorization.kubernetes.io/autoupdate": "true"
            }
        },
        role_ref={
            "apiGroup": "rbac.authorization.k8s.io",
            "kind": "ClusterRole",
            "name": "system:coredns"
        },
        subjects=[{
            "kind": "ServiceAccount",
            "name": "coredns",
            "namespace": "kube-system"
        }])

    configMap = ConfigMap("coredns",
                          metadata={
                              "name": "coredns",
                              "namespace": "kube-system"
                          },
                          data={
                              "Corefile":
                              """.:53 {
            errors
            health
            kubernetes cluster.local in-addr.arpa ip6.arpa {
                pods insecure
                upstream
                fallthrough in-addr.arpa ip6.arpa
            }
            prometheus :9153
            proxy . /etc/resolv.conf
            cache 30
            loop
            reload
            loadbalance
        }"""
                          })

    deployment = Deployment(
        "coredns",
        metadata={
            "name": "coredns",
            "namespace": "kube-system",
            "labels": {
                "k8s-app": "kube-dns",
                "kubernetes.io/name": "CoreDNS"
            }
        },
        spec={
            "selector": {
                "matchLabels": {
                    "k8s-app": "kube-dns"
                }
            },
            "replicas": 2,
            "strategy": {
                "type": "RollingUpdate",
                "rollingUpdate": {
                    "maxUnavailable": 1
                }
            },
            "template": {
                "metadata": {
                    "labels": {
                        "k8s-app": "kube-dns"
                    }
                },
                "spec": {
                    "serviceAccountName":
                    "coredns",
                    "tolerations": [
                        {
                            "key": "node-role.kubernetes.io/master",
                            "effect": "NoSchedule"
                        },
                        {
                            "key": "CriticalAddonsOnly",
                            "operator": "Exists"
                        },
                    ],
                    "volumes": [{
                        "name": "config-volume",
                        "configMap": {
                            "name": "coredns",
                            "items": [{
                                "key": "Corefile",
                                "path": "Corefile"
                            }]
                        }
                    }],
                    "dnsPolicy":
                    "Default",
                    "containers": [{
                        "name":
                        "coredns",
                        "image":
                        "coredns/coredns:1.2.2",
                        "imagePullPolicy":
                        "IfNotPresent",
                        "resources": {
                            "limits": {
                                "memory": "170Mi"
                            },
                            "requests": {
                                "cpu": "100m",
                                "memory": "70Mi"
                            }
                        },
                        "args": ["-conf", "/etc/coredns/Corefile"],
                        "volumeMounts": [{
                            "name": "config-volume",
                            "mountPath": "/etc/coredns",
                            "readOnly": True
                        }],
                        "ports": [{
                            "containerPort": 53,
                            "name": "dns",
                            "protocol": "UDP"
                        }, {
                            "containerPort": 53,
                            "name": "dns-tcp",
                            "protocol": "TCP"
                        }, {
                            "containerPort": 9153,
                            "name": "metrics",
                            "protocol": "TCP"
                        }],
                        "securityContext": {
                            "allowPrivilegeEscalation": False,
                            "capabilities": {
                                "add": ["NET_BIND_SERVICE"],
                                "drop": ["all"]
                            }
                        },
                        "livenessProbe": {
                            "httpGet": {
                                "path": "/health",
                                "port": 8080,
                                "scheme": "HTTP"
                            },
                            "initialDelaySeconds": 60,
                            "timeoutSeconds": 5,
                            "successThreshold": 1,
                            "failureThreshold": 5
                        }
                    }]
                }
            }
        })

    service = Service("kube-dns",
                      metadata={
                          "name": "kube-dns",
                          "namespace": "kube-system",
                          "labels": {
                              "k8s-app": "kube-dns",
                              "kubernetes.io/name": "CoreDNS",
                              "kubernetes.io/cluster-service": "true"
                          },
                          "annotations": {
                              "prometheus.io/port": "9153",
                              "prometheus.io/scrape": "true"
                          }
                      },
                      spec={
                          "selector": {
                              "k8s-app": "kube-dns"
                          },
                          "clusterIP":
                          "10.32.0.10",
                          "ports": [{
                              "port": 53,
                              "name": "dns",
                              "protocol": "UDP"
                          }, {
                              "port": 53,
                              "name": "dns-tcp",
                              "protocol": "TCP"
                          }]
                      })


#pulumi.export("name", deployment.metadata["name"])
Esempio n. 20
0
                                      EnvVarArgs(name='mongodb_username',
                                                 value=mongodb_username),
                                      EnvVarArgs(name='mongodb_password',
                                                 value=mongodb_password),
                                      EnvVarArgs(name='mongodb_database',
                                                 value=mongodb_database)
                                  ])
                ],
                image_pull_secrets=[
                    LocalObjectReferenceArgs(name=image_pull_secret)
                ]))))

demo_service = Service("demo",
                       metadata=ObjectMetaArgs(name="demo",
                                               namespace=namespace_name),
                       spec=ServiceSpecArgs(
                           selector={"app": "demo"},
                           ports=[ServicePortArgs(port=int(demo_port))],
                           type="ClusterIP"))

ingress = Ingress(
    "ingress",
    metadata=ObjectMetaArgs(namespace=namespace_name,
                            annotations={
                                "kubernetes.io/ingress.class": "nginx",
                                "nginx.ingress.kubernetes.io/ssl-redirect":
                                "false",
                                "nginx.ingress.kubernetes.io/use-regex":
                                "true",
                                "nginx.ingress.kubernetes.io/rewrite-target":
                                "/$1"
Esempio n. 21
0
                        'replicas': 1,
                        'template': {
                            'metadata': {
                                'labels': labels
                            },
                            'spec': {
                                'containers': [{
                                    'name': 'nginx',
                                    'image': 'nginx'
                                }]
                            },
                        },
                    },
                    __opts__=ResourceOptions(provider=k8s_provider))

ingress = Service('ingress',
                  spec={
                      'type': 'LoadBalancer',
                      'selector': labels,
                      'ports': [{
                          'port': 80
                      }],
                  },
                  __opts__=ResourceOptions(provider=k8s_provider))

# Finally, export the kubeconfig so that the client can easily access the cluster.
export('kubeconfig', k8s_config)
# Export the k8s ingress IP to access the canary deployment
export('ingress_ip',
       Output.all(ingress.status['load_balancer']['ingress'][0]['ip']))
Esempio n. 22
0
)

# Deploy a load-balanced service that uses this image.
labels = { 'app': 'my-app' }
dep = Deployment('my-app-dep', spec={
    'selector': { 'matchLabels': labels },
    'replicas': 1,
    'template': {
        'metadata': { 'labels': labels },
        'spec': {
            'containers': [{
                'name': labels['app'],
                'image': image.image_name,
            }],
            'image_pull_secrets': [{
                'name': pull_secret.metadata['name'],
            }],
        },
    },
})
svc = Service('my-app-svc', spec={
    'selector': labels,
    'type': 'LoadBalancer',
    'ports': [{ 'port': 80 }],
})

# Export the resulting image name.
pulumi.export('imageName', image.image_name)
# Export the k8s ingress IP to access the service.
pulumi.export('serviceIp', svc.status['load_balancer']['ingress'][0]['ip'])
Esempio n. 23
0
    def __init__(self, name, credentials, resources, image=None, opts=None):
        super(Instance, self).__init__("jenkins:jenkins:Instance", name, {
            "credentials": credentials,
            "resources": resources,
            "image": image
        }, opts)

        # The Secret will contain the root password for this instance.
        secret = Secret(
            name + "-secret",
            metadata={
                "name": name,
            },
            type="Opaque",
            data={
                "jenkins-password":
                str(
                    base64.b64encode(bytes(credentials["password"], "utf-8"),
                                     None), "utf-8"),
            },
            opts=ResourceOptions(parent=self),
        )

        # The PVC provides persistent storage for Jenkins states.
        pvc = PersistentVolumeClaim(
            name + "-pvc",
            metadata={
                "name": name,
            },
            spec={
                "accessModes": ["ReadWriteOnce"],
                "resources": {
                    "requests": {
                        "storage": "8Gi",
                    },
                },
            },
            opts=ResourceOptions(parent=self),
        )

        # The Deployment describes the desired state for our Jenkins setup.
        deploymentArgs = createDeploymentArgs(name, credentials, resources,
                                              image)
        deployment = Deployment(
            name + "-deploy",
            metadata=deploymentArgs["metadata"],
            spec=deploymentArgs["spec"],
            opts=ResourceOptions(parent=self),
        )

        # The Service exposes Jenkins to the external internet by providing load-balanced ingress for HTTP and HTTPS.
        service = Service(name + "-service",
                          metadata={
                              "name": name,
                          },
                          spec={
                              "type":
                              "LoadBalancer",
                              "ports": [
                                  {
                                      "name": "http",
                                      "port": 80,
                                      "targetPort": "http",
                                  },
                                  {
                                      "name": "https",
                                      "port": 443,
                                      "targetPort": "https",
                                  },
                              ],
                              "selector": {
                                  "app": name,
                              },
                          },
                          opts=ResourceOptions(parent=self))

        # This component resource has no outputs.
        self.register_outputs({})
Esempio n. 24
0
                    docker_image,
                    'ports': [{
                        'name': 'port-5000',
                        'container_port': 5000
                    }]
                }]
            }
        }
    },
    __opts__=ResourceOptions(provider=cluster_provider))

deploy_name = gke_deployment

gke_service = Service(app_name,
                      metadata={
                          'namespace': ns,
                          'labels': app_label,
                      },
                      spec={
                          'type': "LoadBalancer",
                          'ports': [{
                              'port': 80,
                              'target_port': 5000
                          }],
                          'selector': app_label,
                      },
                      __opts__=ResourceOptions(provider=cluster_provider))

pulumi.export("kubeconfig", k8s_config)
pulumi.export("app_endpoint_ip",
              gke_service.status['load_balancer']['ingress'][0]['ip'])
Esempio n. 25
0
                                                         },
                                                     },
                                                     "ports": [{
                                                         "container_port":
                                                         6379,
                                                     }],
                                                 }],
                                             },
                                         },
                                     })

redis_leader_service = Service("redis-leader",
                               metadata={"labels": redis_leader_labels},
                               spec={
                                   "ports": [{
                                       "port": 6379,
                                       "target_port": 6379,
                                   }],
                                   "selector": redis_leader_labels
                               })

redis_follower_labels = {"app": "redis", "tier": "backend", "role": "slave"}

redis_follower_deployment = Deployment(
    "redis-follower",
    spec={
        "selector": {
            "match_labels": redis_follower_labels
        },
        "replicas": 1,
        "template": {
Esempio n. 26
0
    app_name,
    spec={
        "selector": { "match_labels": app_labels },
        "replicas": 1,
        "template": {
            "metadata": { "labels": app_labels },
            "spec": { "containers": [{ "name": app_name, "image": "nginx" }] }
        }
    })

# Allocate an IP to the Deployment.
frontend = Service(
    app_name,
    metadata={
        "labels": deployment.spec["template"]["metadata"]["labels"],
    },
    spec={
        "type": "ClusterIP" if is_minikube else "LoadBalancer",
        "ports": [{ "port": 80, "target_port": 80, "protocol": "TCP" }],
        "selector": app_labels,
    })

# When "done", this will print the public IP.
result = None
if is_minikube:
    result = frontend.spec.apply(lambda v: v["cluster_ip"] if "cluster_ip" in v else None)
else:
    ingress = frontend.status.apply(lambda v: v["load_balancer"]["ingress"][0] if "load_balancer" in v else None)
    if ingress is not None:
        result = ingress.apply(lambda v: v["ip"] if "ip" in v else v["hostname"])

pulumi.export("ip", result)
Esempio n. 27
0
                "labels": labels
            },
            "spec": {
                "containers": [{
                    "name": "nginx",
                    "image": "nginx"
                }]
            },
        },
    },
    __opts__=ResourceOptions(provider=k8s_provider),
)

ingress = Service(
    "ingress",
    spec={
        "type": "LoadBalancer",
        "selector": labels,
        "ports": [{
            "port": 80
        }]
    },
    __opts__=ResourceOptions(provider=k8s_provider),
)

# Finally, export the kubeconfig so that the client can easily access the cluster.
export("kubeconfig", k8s_config)
# Export the k8s ingress IP to access the canary deployment
export("ingress_ip",
       Output.all(ingress.status["load_balancer"]["ingress"][0]["ip"]))
Esempio n. 28
0
                                                     },
                                                     "ports": [{
                                                         "container_port":
                                                         6379,
                                                     }],
                                                 }],
                                             },
                                         },
                                     })

redis_leader_service = Service("redis-leader",
                               metadata={
                                   "namespace": namespace,
                                   "labels": redis_leader_labels
                               },
                               spec={
                                   "ports": [{
                                       "port": 6379,
                                       "target_port": 6379,
                                   }],
                                   "selector": redis_leader_labels
                               })

redis_follower_labels = {"app": "redis", "tier": "backend", "role": "slave"}

redis_follower_deployment = Deployment(
    "redis-follower",
    metadata={"namespace": namespace},
    spec={
        "selector": {
            "match_labels": redis_follower_labels
        },