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({})
# Copyright 2016-2020, Pulumi Corporation. All rights reserved. import pulumi from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs from pulumi_kubernetes.core.v1 import ContainerArgs, ContainerPortArgs, PodSpecArgs, PodTemplateSpecArgs from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs config = pulumi.Config() nginxLabels = {"app": "nginx"} nginxDeployment = Deployment( "nginx-deployment", spec=DeploymentSpecArgs( selector=LabelSelectorArgs(match_labels=nginxLabels), replicas=2 if config.get_int("replicas") is None else config.get_int("replicas"), template=PodTemplateSpecArgs( metadata=ObjectMetaArgs(labels=nginxLabels), spec=PodSpecArgs(containers=[ ContainerArgs( name="nginx", image="nginx:1.7.9", ports=[ContainerPortArgs(container_port=80)], ) ], ), ), )) pulumi.export("nginx", nginxDeployment.metadata.apply(lambda m: m.name))
"app": "redis-leader", } redis_leader_deployment = Deployment( "redis-leader", spec=DeploymentSpecArgs( selector=LabelSelectorArgs(match_labels=redis_leader_labels, ), replicas=1, template=PodTemplateSpecArgs( metadata=ObjectMetaArgs(labels=redis_leader_labels, ), spec=PodSpecArgs(containers=[ ContainerArgs( name="redis-leader", 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,
# Copyright 2016-2020, Pulumi Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import pulumi from pulumi_kubernetes.core.v1 import Pod, Namespace, PodSpecArgs, ContainerArgs from pulumi_kubernetes.meta.v1 import ObjectMetaArgs namespace = Namespace("ns") pod = Pod("smoke-test", metadata=ObjectMetaArgs(namespace=namespace, ), spec=PodSpecArgs(containers=[ ContainerArgs(name="nginx", image="nginx"), ])) pulumi.export("ip", pod.status.apply(lambda s: s.pod_ip))
name="default", size="s-2vcpu-2gb", node_count=node_count )) k8s_provider = Provider("do-k8s", kubeconfig=cluster.kube_configs.apply(lambda c: c[0].raw_config)) 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)
"demo", metadata=ObjectMetaArgs(name="demo", namespace=namespace_name), spec=DeploymentSpecArgs( selector=LabelSelectorArgs(match_labels={"app": "demo"}), replicas=1, template=PodTemplateSpecArgs( metadata=ObjectMetaArgs(labels={"app": "demo"}), spec=PodSpecArgs( containers=[ ContainerArgs(name="demo", image=docker_registry_repository + ':latest', env=[ EnvVarArgs(name='mongodb_host', value=mongodb_host), EnvVarArgs(name='mongodb_port', value=mongodb_port), 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(
"""A Kubernetes Python Pulumi program""" import pulumi from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs from pulumi_kubernetes.core.v1 import ContainerArgs, PodSpecArgs, PodTemplateSpecArgs app_labels = {"app": "nginx"} deployment = Deployment( "nginx", 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")])), )) pulumi.export("name", deployment.metadata["name"])
project, zone, info[0]))) # Make a Kubernetes provider instance that uses our cluster from above. 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
redis_leader_labels = {"app": "redis", "tier": "backend", "role": "master"} redis_leader_deployment = Deployment( "redis-leader", metadata=ObjectMetaArgs(namespace=namespace), spec=DeploymentSpecArgs( selector=LabelSelectorArgs(match_labels=redis_leader_labels, ), replicas=1, template=PodTemplateSpecArgs( metadata=ObjectMetaArgs(labels=redis_leader_labels, ), spec=PodSpecArgs(containers=[ ContainerArgs( name="master", 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,
def create_deployment_args(name, credentials, resources, image=None) -> DeploymentArgs: image = image if image is not None else { "registry": "docker.io", "repository": "bitnami/jenkins", "tag": "2.121.2", "pullPolicy": "IfNotPresent", } # This object is a projection of the Kubernetes object model into the Pulumi object model. # Its structure is derived from the Deployment object in the Kubernetes API. return DeploymentArgs( ObjectMetaArgs(name=name), DeploymentSpecArgs( replicas=1, selector=LabelSelectorArgs(match_labels={ "app": name, }, ), template=PodTemplateSpecArgs( metadata=ObjectMetaArgs(labels={ "app": name, }, ), spec=PodSpecArgs( volumes=[ VolumeArgs( name="jenkins-data", persistent_volume_claim= PersistentVolumeClaimVolumeSourceArgs( claim_name=name, ), ), ], containers=[ ContainerArgs( name=name, image=image["registry"] + "/" + image["repository"] + ":" + image["tag"], image_pull_policy=image["pullPolicy"], env=[ EnvVarArgs( name="JENKINS_USERNAME", value=credentials["username"], ), EnvVarArgs( name="JENKINS_PASSWORD", value_from=EnvVarSourceArgs( secret_key_ref=SecretKeySelectorArgs( name=name, key="jenkins-password", ), ), ), ], ports=[ ContainerPortArgs( name="http", container_port=8080, ), ContainerPortArgs( name="https", container_port=8443, ), ], liveness_probe=ProbeArgs( http_get=HTTPGetActionArgs( path="/login", port="http", ), initial_delay_seconds=180, timeout_seconds=5, failure_threshold=6, ), readiness_probe=ProbeArgs( http_get=HTTPGetActionArgs( path="/login", port="http", ), initial_delay_seconds=90, timeout_seconds=5, period_seconds=6, ), volume_mounts=[ VolumeMountArgs( name="jenkins-data", mount_path="/bitnami/jenkins", ), ], resources=ResourceRequirementsArgs(requests={ "memory": resources["memory"], "cpu": resources["cpu"], }, ), ), ], ), ), ))