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({})
) from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs # 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. config = pulumi.Config() isMinikube = config.get_bool("isMinikube") redis_leader_labels = { "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, )], ) ], ), ),
# 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))
"do-cluster", region="nyc3", version="latest", node_pool=do.KubernetesClusterNodePoolArgs( 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")))
namespace_name = os.getenv('namespace_name') docker_registry_repository = os.getenv('docker_registry_repository') image_pull_secret = os.getenv('image_pull_secret') demo_port = os.getenv('demo_port') mongodb_host = os.getenv('mongodb_host') mongodb_port = os.getenv('mongodb_port') mongodb_username = os.getenv('mongodb_username') mongodb_password = os.getenv('mongodb_password') mongodb_database = os.getenv('mongodb_database') deployment_demo = Deployment( "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',
ResourceRequirementsArgs, ServiceSpecArgs, ServicePortArgs, EnvVarArgs, ) from pulumi_kubernetes.meta.v1 import ObjectMetaArgs, LabelSelectorArgs namespace = Namespace("test") 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, )], ) ], ), ),
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"], }, ), ), ], ), ), ))