Skip to content

Commit

Permalink
fix(aws-load-balancer-controller): change service to type NodePort
Browse files Browse the repository at this point in the history
  • Loading branch information
briancaffey committed Jun 7, 2021
1 parent 9e1947d commit b963855
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
41 changes: 20 additions & 21 deletions src/django-eks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { RdsPostgresInstance } from './database';
// k8s manifests
// import { nginxDeployment, nginxService } from './nginx';
import { MigrateJob } from './eks/resources/migrate';
// import { WebResources } from './eks/resources/web';
// import { appIngress } from './ingress';
import { WebResources } from './eks/resources/web';
import { appIngress } from './ingress';
import { ApplicationVpc } from './vpc';


Expand Down Expand Up @@ -327,33 +327,32 @@ export class DjangoEks extends cdk.Construct {
this.cluster.addManifest('migrate-job', migrateJob.manifest);

// web service and deployment
// const webResources = new WebResources(scope, 'web-resources', {
// env,
// cluster: this.cluster,
// webCommand: props.webCommand ?? ['./scripts/start_prod.sh'],
// backendImage,
// namespace: 'app',
// });
const webResources = new WebResources(scope, 'web-resources', {
env,
cluster: this.cluster,
webCommand: props.webCommand ?? ['./scripts/start_prod.sh'],
backendImage,
namespace: 'app',
});

/**
* Add deployment and service manifests for web to the cluster
*/
// this.cluster.addManifest('app-ingresss', appIngress);
// this.cluster.addManifest('web-deployment', webResources.deploymentManifest);
// this.cluster.addManifest('web-service', webResources.serviceManifest);

this.cluster.addManifest('app-ingresss', appIngress);
this.cluster.addManifest('web-deployment', webResources.deploymentManifest);
this.cluster.addManifest('web-service', webResources.serviceManifest);

/**
* Get the ALB address using KubernetesObjectValue as a String
*/

// const albAddress = new eks.KubernetesObjectValue(scope, 'AlbAddress', {
// cluster: this.cluster,
// objectType: 'ingress',
// objectNamespace: 'app',
// objectName: 'app-ingress',
// jsonPath: '.items[0].status.loadBalancer.ingress[0].hostname',
// });
const albAddress = new eks.KubernetesObjectValue(scope, 'AlbAddress', {
cluster: this.cluster,
objectType: 'ingress',
objectNamespace: 'app',
objectName: 'app-ingress',
jsonPath: '.items[0].status.loadBalancer.ingress[0].hostname',
});

/**
* Route53 A Record pointing to ALB that is created by AWS Application Load Balancer Controller
Expand All @@ -363,7 +362,7 @@ export class DjangoEks extends cdk.Construct {
/**
* Output the Load Balancer URL as a CfnOutput
*/
// new cdk.CfnOutput(this, 'apiUrl', { value: albAddress.value });
new cdk.CfnOutput(this, 'apiUrl', { value: albAddress.value });

}
}
2 changes: 2 additions & 0 deletions src/eks/resources/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class WebResources extends cdk.Construct {
labels: selector,
},
spec: {
serviceAccountName: 'pod-service-account',
containers: [
{
name,
Expand Down Expand Up @@ -76,6 +77,7 @@ export class WebResources extends cdk.Construct {
},
spec: {
selector,
type: 'NodePort',
ports: [
{
port: 80,
Expand Down
11 changes: 4 additions & 7 deletions src/ingress/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const appIngress = {
apiVersion: 'networking.k8s.io/v1',
// TODO: update this after upgrading to kubernetes version 1.22
apiVersion: 'networking.k8s.io/v1beta1',
kind: 'Ingress',
metadata: {
name: 'app-ingress',
Expand All @@ -19,12 +20,8 @@ export const appIngress = {
path: '/',
pathType: 'Prefix',
backend: {
service: {
name: 'api-http',
port: {
number: 80,
},
},
serviceName: 'api-http',
servicePort: 80,
},
},
],
Expand Down

0 comments on commit b963855

Please sign in to comment.