Hi I am trying to deploy app on kubernetes, every ...
# general
r
Hi I am trying to deploy app on kubernetes, every thing is successful execpt ingress. I am getting this error:
Copy code
Diagnostics:
  pulumi:pulumi:Stack (strapi-strapi-kubernetes):
    error: Program failed with an unhandled exception:
    error: Traceback (most recent call last):
      File "/home/dishant/.pulumi/bin/pulumi-language-python-exec", line 92, in <module>
        loop.run_until_complete(coro)
      File "/usr/lib64/python3.9/asyncio/base_events.py", line 642, in run_until_complete
        return future.result()
      File "/home/dishant/Projects/cloud-poc/infrastructure/stacks/strapi/venv/lib64/python3.9/site-packages/pulumi/runtime/stack.py", line 110, in run_in_stack
        await run_pulumi_func(lambda: Stack(func))
      File "/home/dishant/Projects/cloud-poc/infrastructure/stacks/strapi/venv/lib64/python3.9/site-packages/pulumi/runtime/stack.py", line 43, in run_pulumi_func
        func()
      File "/home/dishant/Projects/cloud-poc/infrastructure/stacks/strapi/venv/lib64/python3.9/site-packages/pulumi/runtime/stack.py", line 110, in <lambda>
        await run_pulumi_func(lambda: Stack(func))
      File "/home/dishant/Projects/cloud-poc/infrastructure/stacks/strapi/venv/lib64/python3.9/site-packages/pulumi/runtime/stack.py", line 133, in __init__
        func()
      File "/home/dishant/.pulumi/bin/pulumi-language-python-exec", line 91, in <lambda>
        coro = pulumi.runtime.run_in_stack(lambda: runpy.run_path(args.PROGRAM, run_name='__main__'))
      File "/usr/lib64/python3.9/runpy.py", line 285, in run_path
        return _run_code(code, mod_globals, init_globals,
      File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/home/dishant/Projects/cloud-poc/infrastructure/stacks/strapi/./__main__.py", line 41, in <module>
        ingress = Ingress(
    TypeError: __init__() takes 1 positional argument but 2 positional arguments (and 2 keyword-only arguments) were given
    error: an unhandled error occurred: Program exited with non-zero exit code: 1
This is my pulumi code:
Copy code
"""A Kubernetes Python Pulumi program"""

import http
from importlib.resources import path
import pulumi
from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs
from pulumi_kubernetes.networking.v1 import *
from pulumi_kubernetes.networking.v1.outputs import *
from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs
from pulumi_kubernetes.core.v1 import *
app_labels = { "app": "strapi" }

deployment = Deployment(
    "strapi",
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=app_labels),
        replicas=2,
        template=PodTemplateSpecArgs(
            metadata=ObjectMetaArgs(labels=app_labels),
            spec=PodSpecArgs(containers=[ContainerArgs(name="nginx", image="strapi/strapi")])
        ),
    ))

pulumi.export("name", deployment.metadata["name"])

strapiService = Service("strapiService",
    api_version="v1",
    kind="Service",
    metadata=ObjectMetaArgs(
        name="strapi",
    ),
    spec=ServiceSpecArgs(
        selector=app_labels,
        ports=[ServicePortArgs(
            protocol="TCP",
            port=80,
            target_port=1337,
        )],
    ))

ingress = Ingress(
    "strapi",
    metadata=ObjectMetaArgs(
        name="strapi",
    ),
    spec=IngressSpecArgs(
        ingress_class_name="nginx",
        rules=IngressRuleArgs(
            host="strapi.test.cluster",
            http=HTTPIngressRuleValueArgs(
                paths=HTTPIngressPathArgs(
                    backend=IngressBackendArgs(
                        service=IngressServiceBackendArgs(
                            name="strapi",
                            port=ServiceBackendPortArgs(
                                name="http",
                                number="80"
                            ),
                        )
                    ),
                    path_type="Prefix",
                    path="/"
                )
            )
        ))
    )
p
I’d need to check that but I guess there might be another Ingress class in from
pulumi_kubernetes.networking.v1.outputs
basically, the error looks pretty self-explaining:
Copy code
TypeError: __init__() takes 1 positional argument but 2 positional arguments (and 2 keyword-only arguments) were given
However, your Ingress object creation looks pretty good to me (without looking at the docs/source code) so I’m guessing it’s not the Ingress you are looking for 😄
Copy code
import pulumi
from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs
from pulumi_kubernetes.core.v1 import (
    ContainerArgs,
    PodSpecArgs,
    PodTemplateSpecArgs,
    Service,
    ServicePortArgs,
    ServiceSpecArgs,
)
from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs
from pulumi_kubernetes.networking.v1 import (
    HTTPIngressPathArgs,
    HTTPIngressRuleValueArgs,
    Ingress,
    IngressBackendArgs,
    IngressRuleArgs,
    IngressServiceBackendArgs,
    IngressSpecArgs,
    ServiceBackendPortArgs,
)

app_labels = {"app": "strapi"}

deployment = Deployment(
    "strapi",
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=app_labels),
        replicas=2,
        template=PodTemplateSpecArgs(
            metadata=ObjectMetaArgs(labels=app_labels),
            spec=PodSpecArgs(
                containers=[ContainerArgs(name="nginx", image="strapi/strapi")]
            ),
        ),
    ),
)

pulumi.export("name", deployment.metadata["name"])

strapiService = Service(
    "strapiService",
    api_version="v1",
    kind="Service",
    metadata=ObjectMetaArgs(
        name="strapi",
    ),
    spec=ServiceSpecArgs(
        selector=app_labels,
        ports=[
            ServicePortArgs(
                protocol="TCP",
                port=80,
                target_port=1337,
            )
        ],
    ),
)

ingress = Ingress(
    "strapi",
    metadata=ObjectMetaArgs(
        name="strapi",
    ),
    spec=IngressSpecArgs(
        ingress_class_name="nginx",
        rules=[
            IngressRuleArgs(
                host="strapi.test.cluster",
                http=HTTPIngressRuleValueArgs(
                    paths=[
                        HTTPIngressPathArgs(
                            backend=IngressBackendArgs(
                                service=IngressServiceBackendArgs(
                                    name="strapi",
                                    port=ServiceBackendPortArgs(
                                        name="http", number="80"
                                    ),
                                )
                            ),
                            path_type="Prefix",
                            path="/",
                        )
                    ]
                ),
            )
        ],
    ),
)
try the above
to sum up: • try not to use
from X import *
, it might be evil as you’ve already checked • you had 2 small extra issues: ◦
rules
definition; it’s supposed to be a list, not a single object ◦ same for
paths
b
I'm totally with Jakub on not using the
from X import *
syntax, I prefer to use the more canonical imports, see here: https://github.com/jaxxstorm/pulumi-nginx-demo/blob/main/nginx-ingress/app.py
👍 2
p
@billowy-army-68599 it looks like copy’n’paste from my pulumi files 😄
even the alias is the same:
Copy code
import pulumi_kubernetes as k8s
b
great minds thank alike 😄
p
could not agree more 😄
b
I submitted a talk to PyCon about the python type system based entirely on these lessons learned, hope it gets accepted 😄
p
nice 🙂
@red-kangaroo-44125 the fixed code above tries to create some k8s resources. I haven’t run it against the real cluster but I guess it should be fine.
r
Thanks @prehistoric-activity-61023 I'll try that for my cluster and see if that works.