https://pulumi.com logo
Title
c

cool-lawyer-24254

01/05/2023, 7:42 AM
Hi, could you please someone explain why this code doesn't start the docker container after deployment?
import * as awsx from "@pulumi/awsx/classic";
import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";
import * as aws from "@pulumi/aws";
const cluster = new eks.Cluster("cluster", {
});
// Deploy a serice
const appName = "my-app";
const appLabels = { appClass: appName };
`const deployment = new k8s.apps.v1.Deployment(
${appName}-dep
, {`
metadata: { labels: appLabels },
spec: {
replicas: 2,
selector: { matchLabels: appLabels },
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: appName,
image: awsx.ecr.buildAndPushImage("my-custom-nginx-service", "./app").image(),
ports: [{ name: "http", containerPort: 80 }],
}],
}
}
},
}, { provider: cluster.provider });
`const service = new k8s.core.v1.Service(
${appName}-svc
, {`
metadata: { labels: appLabels },
spec: {
type: "LoadBalancer",
ports: [{ port: 80, targetPort: 80 }],
selector: appLabels,
},
}, { provider: cluster.provider });
// Export the cluster's kubeconfig.
export const kubeconfig = cluster.kubeconfig;
// Publish the URL for the load balanced service.
export const appURL = service.status.loadBalancer.ingress[0].hostname;
Docker file
FROM nginx:latest
q

quaint-eye-38036

01/05/2023, 9:12 AM
From the last messages, it appears that the nodes aren't ready yet. What's the state of the pod?
c

cool-lawyer-24254

01/05/2023, 9:14 AM
Status is
Running
q

quaint-eye-38036

01/05/2023, 9:14 AM
So, no issues?
c

cool-lawyer-24254

01/05/2023, 9:14 AM
Yeah
q

quaint-eye-38036

01/05/2023, 9:14 AM
Cool!
c

cool-lawyer-24254

01/05/2023, 9:15 AM
and the endpoint is unreachable.
q

quaint-eye-38036

01/05/2023, 9:15 AM
Which endpoints?
c

cool-lawyer-24254

01/05/2023, 9:16 AM
interesting point is that if I replace
image: awsx.ecr.buildAndPushImage("my-custom-nginx-service", "./app").image()
by
image: "nginx"
it works then.
endpoints? that one
service.status.loadBalancer.ingress[0].hostname
q

quaint-eye-38036

01/05/2023, 9:19 AM
How was it checked? Ping, curl or some other way?
c

cool-lawyer-24254

01/05/2023, 9:21 AM
Yeah, as you see it's nginx service, if you just use web browser and check the url it should show default index.html page of the nginx
q

quaint-eye-38036

01/05/2023, 9:22 AM
Which version of EKS?
c

cool-lawyer-24254

01/05/2023, 9:23 AM
the cluster is deployed under
1.23
version
I tried to update to
1.24
version too
q

quaint-eye-38036

01/05/2023, 9:24 AM
Hmm..ok. But I think you mentioned that if the custom image in the deployment is replaced with your custom image, it works, rit?
c

cool-lawyer-24254

01/05/2023, 9:25 AM
Yes.
q

quaint-eye-38036

01/05/2023, 9:27 AM
To rule out that it's an issue with Pulumi, have you tried deploying it using the native yaml?
c

cool-lawyer-24254

01/05/2023, 9:29 AM
Do you mean not to use typescript and try yaml file?
q

quaint-eye-38036

01/05/2023, 9:30 AM
To rule of issues with the custom image
If the endpoints are reachable with the custom image deployed the native way then we are sure there nothing wrong with the image and focus on pulumi then
c

cool-lawyer-24254

01/05/2023, 9:33 AM
Yeah, I'm sure container is ok itself here is another example which I deployed and checked locally, then I pushed it to DockerHub, but the result is the same, containers not starting
FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

# RUN npm install
RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 80
CMD [ "node", "server.js" ]
q

quaint-eye-38036

01/05/2023, 9:36 AM
Is this the Dockerfile of the custome image?
c

cool-lawyer-24254

01/05/2023, 9:36 AM
Yes
server.js is just simple express app
q

quaint-eye-38036

01/05/2023, 9:38 AM
After you deployed it locally, how did you access and test that it's accepting HTTP request?
c

cool-lawyer-24254

01/05/2023, 9:38 AM
const express = require('express');

const PORT = 80;

// App
const app = express();
app.get('/', (req, res) => {
  res.send('Hello!');
});

app.listen(PORT, () => {
  console.log(`Running on ${PORT}`);
});
Just checked by Postman
q

quaint-eye-38036

01/05/2023, 9:40 AM
By deployed locally, what was it? Minikube, kind or something else?
c

cool-lawyer-24254

01/05/2023, 9:44 AM
To ensure that the container works properly I just made a custom image and checked run th e container locally, then I pushed it to DockerHubs private repo, then I used the container in Pulumi code, to exclude that in the first example where I try to pull it from ECR there are no issues related to EKS ECR connectivity.
The issue has been resolved. It was found that the issue was caused by building dockers locally on a Mac M1 chip. Adding the
FROM --platform=linux/amd64
flag into the Dockerfile solved the issue.