Exemplo n.º 1
0
    def __init__(self, scope: Construct, ns: str):
        super().__init__(scope, ns)

        label = {"app": "hello-k8s"}

        k8s.Service(self,
                    'service',
                    spec=k8s.ServiceSpec(
                        type='LoadBalancer',
                        ports=[
                            k8s.ServicePort(
                                port=80,
                                target_port=k8s.IntOrString.from_number(8080))
                        ],
                        selector=label))

        k8s.Deployment(
            self,
            'deployment',
            spec=k8s.DeploymentSpec(
                replicas=2,
                selector=k8s.LabelSelector(match_labels=label),
                template=k8s.PodTemplateSpec(
                    metadata=k8s.ObjectMeta(labels=label),
                    spec=k8s.PodSpec(containers=[
                        k8s.Container(
                            name='hello-kubernetes',
                            image='paulbouwer/hello-kubernetes:1.7',
                            ports=[k8s.ContainerPort(container_port=8080)])
                    ]))))
Exemplo n.º 2
0
    def __init__(self, scope: Construct, ns: str):
        super().__init__(scope, ns)

        label = {"app": "guestbook-ui"}

        k8s.Service(self,
                    'service',
                    spec=k8s.ServiceSpec(
                        type='LoadBalancer',
                        ports=[
                            k8s.ServicePort(
                                port=80,
                                target_port=k8s.IntOrString.from_number(80))
                        ],
                        selector=label))

        k8s.Deployment(
            self,
            'deployment',
            spec=k8s.DeploymentSpec(
                replicas=1,
                selector=k8s.LabelSelector(match_labels=label),
                template=k8s.PodTemplateSpec(
                    metadata=k8s.ObjectMeta(labels=label),
                    spec=k8s.PodSpec(containers=[
                        k8s.Container(
                            name='guestbook-ui',
                            image='gcr.io/heptio-images/ks-guestbook-demo:0.2',
                            ports=[k8s.ContainerPort(container_port=80)])
                    ]))))
Exemplo n.º 3
0
    def __init__(self, scope: Construct, ns: str, *,
                 image: str,
                 replicas: typing.Optional[int] = 1,
                 port: typing.Optional[int] = 80,
                 container_port: typing.Optional[int] = 8000):
        super().__init__(scope, ns)

        label = {'app': Node.of(self).unique_id}

        k8s.Service(self, 'service',
                    spec=k8s.ServiceSpec(
                        type='NodePort',
                        ports=[k8s.ServicePort(port=port, target_port=k8s.IntOrString.from_number(container_port))],
                        selector=label))

        k8s.Deployment(self, 'deployment',
                       spec=k8s.DeploymentSpec(
                           replicas=replicas,
                           selector=k8s.LabelSelector(match_labels=label),
                           template=k8s.PodTemplateSpec(
                               metadata=k8s.ObjectMeta(labels=label),
                               spec=k8s.PodSpec(
                                   containers=[
                                       k8s.Container(
                                           name='app',
                                           image=image,
                                            ports=[k8s.ContainerPort(container_port=container_port)])]))))
Exemplo n.º 4
0
 def render_k8s_resource(self, chart: Chart) -> k8s.Service:
     service_ports = ServicePort.render_port_list(self.ports)
     svc_spec = k8s.ServiceSpec(type=self.service_type.k8s_name(),
                                ports=service_ports,
                                selector=self.selector)
     object_meta = k8s.ObjectMeta(name=self.name, labels=self.labels)
     return k8s.Service(scope=chart,
                        name=self.name,
                        metadata=object_meta,
                        spec=svc_spec)
Exemplo n.º 5
0
    def __init__(self,
                 scope: Construct,
                 ns: str,
                 *,
                 image: str,
                 replicas: int = 1,
                 port: int = 80,
                 container_port: int = 8080):
        super().__init__(scope, ns)

        label = {"app": Node.of(self).unique_id}

        k8s.Service(
            self,
            "service",
            spec=k8s.ServiceSpec(
                type="LoadBalancer",
                ports=[
                    k8s.ServicePort(
                        port=port,
                        target_port=k8s.IntOrString.from_number(
                            container_port),
                    )
                ],
                selector=label,
            ),
        )

        k8s.Deployment(
            self,
            "deployment",
            spec=k8s.DeploymentSpec(
                replicas=replicas,
                selector=k8s.LabelSelector(match_labels=label),
                template=k8s.PodTemplateSpec(
                    metadata=k8s.ObjectMeta(labels=label),
                    spec=k8s.PodSpec(containers=[
                        k8s.Container(
                            name="app",
                            image=image,
                            ports=[
                                k8s.ContainerPort(
                                    container_port=container_port)
                            ],
                        )
                    ]),
                ),
            ),
        )
Exemplo n.º 6
0
    def __init__(self, scope: Construct, ns: str):
        super().__init__(scope, ns)

        labels = {"app": "cdk8s-python"}

        k8s.Service(
            self,
            'service',
            spec=k8s.ServiceSpec(
                type='LoadBalancer',
                ports=[
                    k8s.ServicePort(
                        port=80,
                        target_port=k8s.IntOrString.from_number(80)
                    ),
                ],
                selector=labels,
            ),
        )

        k8s.Deployment(
            self,
            'deployment',
            spec=k8s.DeploymentSpec(
                replicas=2,
                selector=k8s.LabelSelector(match_labels=labels),
                template=k8s.PodTemplateSpec(
                    metadata=k8s.ObjectMeta(labels=labels),
                    spec=k8s.PodSpec(
                        containers=[
                            k8s.Container(
                                name=ns,
                                image='nginxdemos/hello',
                                ports=[
                                    k8s.ContainerPort(container_port=80),
                                ],
                            ),
                        ],
                    ),
                ),
            ),
        )