Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aws-eks] reference a value returned through "kubectl get" #8394

Closed
2 tasks
zxkane opened this issue Jun 5, 2020 · 6 comments · Fixed by #9535
Closed
2 tasks

[aws-eks] reference a value returned through "kubectl get" #8394

zxkane opened this issue Jun 5, 2020 · 6 comments · Fixed by #9535
Assignees
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@zxkane
Copy link
Contributor

zxkane commented Jun 5, 2020

Provide a capability to reference values returned through kubectl get, then the value could be used by other parts of application later.

Example:

const hostname = new KubernetesGet(this, 'HostName', {
  kind: 'ingress',
  query: '$.items[0].status.loadBalancer.ingress.[0].hostname',
  wait: true // retry until the value becomes available
});

// then you can just reference the value like this:
hostname.valueAsString

Use Case

When orchestrating an application, the EKS cluster and resources created by k8s resource/helm chart are parts of the entire application.

For example, we deploy a helm chart with internal NLB/ALB ingress controller of a service. And the service exposed by EKS just is part of entire application(other services are be provided by ECS or EC2 auto scaling group).

We need the resource arn created by NLB/ALB ingress controller for entire application orchestration.

Proposed Solution

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@zxkane zxkane added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 5, 2020
@SomayaB SomayaB added the @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service label Jun 5, 2020
@eladb
Copy link
Contributor

eladb commented Jun 22, 2020

We would need a more concrete example. Can you share some code?

@zxkane
Copy link
Contributor Author

zxkane commented Jun 22, 2020

There is an example to deploy Sonatype Nexus OSS on EKS.

I need the arn of the ALB created in the EKS in that stack if putting CloudFront in front of the alb.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Jun 22, 2020
@eladb eladb added effort/small Small work item – less than a day of effort p2 labels Jun 24, 2020
@eladb
Copy link
Contributor

eladb commented Jun 24, 2020

There is an example to deploy Sonatype Nexus OSS on EKS.

I need the arn of the ALB created in the EKS in that stack if putting CloudFront in front of the alb.

Can you please be more specific? Can you point me to the line of code where this is created and where you would expect to be able to obtain the ARN?

@zxkane
Copy link
Contributor Author

zxkane commented Jun 24, 2020

I'm using cluster.addChart to deploy the Helm chart sonatype-nexus, which deploys Nexus OSS with ingress using ALB. So an ALB will be created after the chart is deployed successfully.

It would be useful to add optional query parameters for addChart and addResource, the query parameters indicating the types of resource, names of resource, output format of kubectl get. And the output of kubectl get is treated as output of custom resource.

Also it would be more flexible if adding new method cluster.getResources via kubectl get. User can use the dependency of CFN resources to get the runtime value of K8S resources.

For example, I would like to get hostname of ingress after deploying it,

kubectl get ingress -n default -o yaml
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    annotations:
      alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig":
        { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
      alb.ingress.kubernetes.io/auth-type: none
      alb.ingress.kubernetes.io/backend-protocol: HTTP
      alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-southeast-1:account-id:certificate/5dfad8d6-bec9-4353-9ce5-ed4723e56607
      alb.ingress.kubernetes.io/healthcheck-path: /
      alb.ingress.kubernetes.io/healthcheck-port: "8081"
      alb.ingress.kubernetes.io/inbound-cidrs: 0.0.0.0/0
      alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
      alb.ingress.kubernetes.io/scheme: internet-facing
      alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
      alb.ingress.kubernetes.io/tags: app=nexus3
      alb.ingress.kubernetes.io/target-type: ip
      kubernetes.io/ingress.class: alb
    creationTimestamp: "2020-06-08T13:59:11Z"
    generation: 5
    labels:
      app: sonatype-nexus
      chart: sonatype-nexus-2.1.0
      fullname: nexus3-sonatype-nexus
      heritage: Helm
      release: nexus3
    name: nexus3-sonatype-nexus
    namespace: default
    resourceVersion: "17144"
    selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/nexus3-sonatype-nexus
    uid: 67e53bf6-082f-4d3a-adf0-291ab3e5bc23
  spec:
    rules:
    - host: nexus.mydomain.com
      http:
        paths:
        - backend:
            serviceName: ssl-redirect
            servicePort: use-annotation
          path: /*
        - backend:
            serviceName: nexus3-sonatype-nexus
            servicePort: 8081
          path: /*
  status:
    loadBalancer:
      ingress:
      - hostname: alb-id.ap-southeast-1.elb.amazonaws.com
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

@eladb
Copy link
Contributor

eladb commented Jun 24, 2020

Okay, I think I understand the use case. Basically what you are looking for is a way to reference values returned from a kubectl get in your CDK app.

I think the main problem with this, in k8s, is that most of the apply operations are asynchronous. This means that you would need to "wait" for the resource to stabilize before we can issue the query, but I guess this query operation can also have some sort of retry support.

So perhaps something like this:

const hostname = new KubernetesGet(this, 'HostName', {
  kind: 'ingress',
  query: '$.items[0].status.loadBalancer.ingress.[0].hostname'
});

// then you can just reference the value like this:
hostname.valueAsString

@eladb eladb changed the title eks: get resource arn created by KubernetesResource or HelmChart [EKS Feature] reference a value returned through "kubectl get" Jun 24, 2020
@zxkane
Copy link
Contributor Author

zxkane commented Jun 24, 2020

Okay, I think I understand the use case. Basically what you are looking for is a way to reference values returned from a kubectl get in your CDK app.

I think the main problem with this, in k8s, is that most of the apply operations are asynchronous. This means that you would need to "wait" for the resource to stabilize before we can issue the query, but I guess this query operation can also have some sort of retry support.

So perhaps something like this:

const hostname = new KubernetesGet(this, 'HostName', {
  kind: 'ingress',
  query: '$.items[0].status.loadBalancer.ingress.[0].hostname'
});

// then you can just reference the value like this:
hostname.valueAsString

It's exactly what this feature requests. It could be a feature to verify the status of resources deployed via CDK.

@eladb eladb added p1 and removed p2 labels Jun 24, 2020
@eladb eladb modified the milestone: EKS Dev Preview Jul 22, 2020
@eladb eladb assigned iliapolo and unassigned eladb Aug 4, 2020
@iliapolo iliapolo added this to the EKS Dev Preview milestone Aug 10, 2020
@iliapolo iliapolo added the in-progress This issue is being actively worked on. label Aug 10, 2020
@mergify mergify bot closed this as completed in #9535 Aug 14, 2020
mergify bot pushed a commit that referenced this issue Aug 14, 2020
Introduce a `KubernetesResourceAttribute` construct that executes `kubectl get` commands to fetch runtime information on kubernetes resources.

Resolves #8394 

BREAKING CHANGE: `cluster.addResource` was renamed to `cluster.addManifest` and `KubernetesResource` was renamed to `KubernetesManifest`

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@iliapolo iliapolo removed the in-progress This issue is being actively worked on. label Aug 16, 2020
@iliapolo iliapolo changed the title [EKS Feature] reference a value returned through "kubectl get" [aws-eks] reference a value returned through "kubectl get" Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants