DickChesterwood / k8s-fleetman

MIT License
341 stars 811 forks source link

Multi arch images needed #40

Closed DickChesterwood closed 1 year ago

DickChesterwood commented 2 years ago

We've assumed that the amd64 images would work on the new M1 platform, albeit slowly under emualtion. However we've had a report that the webapp doesn't run:

k8 io_setup() failed (38: Function not implemented)

To work around this, I've made a trial version of a multi arch image:

docker buildx create --use --name build --node build --driver-opt network=host
docker buildx build --platform linux/arm64,linux/amd64 --push -t richardchesterwood/trial-webapp:2 .

I'm waiting on the customer to report back if this works. I'm not at all clear if the other images need similar treatment.

DickChesterwood commented 2 years ago

The above did work, but of course there are multiple images used on this course. At present we assume that only the webapp images are affected, so as a start point we will work through all the webapps, tagging with -m1 or something.

DickChesterwood commented 2 years ago

Tags affected:

There is a securewss tag too, I'm not sure if that one is currently in use. 0 and 0-5 are untagged, I'm not sure how to recover them but I think they were just release 1 with altered headers.

DickChesterwood commented 2 years ago

Annonuced to the customers and waiting for feedback.

If this works, then we need to make the nervous step of switching the images so they become the default. We can of course delete the old ones then.

adityamenon commented 2 years ago

Hi @DickChesterwood - how do I run these M1 images, at this time? I've tried building on my M1 machine, but there's some missing env variables and such that prevent the containers from running. Ideally I'd like to simply docker run ImageName:release0-5-m1 to be able to run the M1 variant of a specific version tag.

RichardKnowles commented 2 years ago

Hi, the details of environment variables etc are on the course. Or you can checkout the github repository under the "_course files" folder, choose one of the chapters (such as the persistence chapter, that's quite late in the course) and you can inspect the kubernetes yaml files - they contain all the environment variables etc that are needed to run the image.

adityamenon commented 2 years ago

Hey Richard, I'm still in the first few videos of the course and would prefer not to debug the code / builds / commands myself just yet (definitely a delicious exercise for later) - just want to follow along for the moment as I'm doing this on 'down-time mode'. Lessons as early as 'Running Containers from DockerHub' have instructions that don't work on M1 Macs. Would be eager to come back to this course after the issues are resolved properly.

RichardKnowles commented 2 years ago

You should be able to continue with the course no problem - is this the early part of the course when you run the a docker container without kubernetes? There's no need for any environment variables there.

I'm a bit confused about where you are and what you're doing exactly - maybe if you give me the full command you're running and the timestamp in the video where you are?

adityamenon commented 2 years ago

is this the early part of the course when you run the a docker container without kubernetes? There's no need for any environment variables there.

Yes correct. I'm trying to debug a failing run of the container at the start of the course.

Course: Kubernetes Microservices (Manning Pub, Video) on O'Reilly. Lesson: 'Running Containers from DockerHub' under 'Docker Quickstart' section. It's the 10th video from start. Timestamp: 05:57 Commands: docker image pull richardchesterwood/k8s-fleetman-webapp-angular:release0-5 at timestamp 05:57 docker container run richardchesterwood/k8s-fleetman-webapp-angular:release0-5 at timestamp 07:05

Failure because the image is not built for the M1 platform:

% docker container run richardchesterwood/k8s-fleetman-webapp-angular:release0-5
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
2022/02/01 02:15:09 [emerg] 8#8: io_setup() failed (38: Function not implemented)

So, I cloned this repository, checked-out to release0-5 tag, cd into the fleetman-webapp-angular repo, installed npm, ran npm build to get the dist directory, then finally docker build . -t fleetman-test. This compiles the image for M1. However, the container fails to run:

% docker run fleetman-test
Traceback (most recent call last):
  File "/usr/bin/j2", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/j2cli/cli.py", line 206, in main
    sys.argv[1:]
  File "/usr/lib/python2.7/site-packages/j2cli/cli.py", line 186, in render_command
    result = renderer.render(args.template, context)
  File "/usr/lib/python2.7/site-packages/j2cli/cli.py", line 87, in render
    .render(context) \
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/templates/nginx.conf.j2", line 22, in top-level template code
    {% if SPRING_PROFILES_ACTIVE == 'local-microservice' %}
jinja2.exceptions.UndefinedError: 'SPRING_PROFILES_ACTIVE' is undefined

The error seems to be a missing spring profile env variable.

zeddee commented 2 years ago

@adityamenon i can replicate what you found (i'm running Darwin 20.6.0 Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:05 PST 2021; root:xnu-7195.141.14~1/RELEASE_ARM64_T8101 arm64 arm)

You can use the richardchesterwood/k8s-fleetman-webapp-angular:release0-5-multi container instead. Remember to forward port 80 to see the web app (e.g. docker run --rm -p 8080:80 richardchesterwood/k8s-fleetman-webapp-angular:release0-5-multi to access the web app at localhost:8080).

You can also check OP's dockerhub to find image builds that support arm64

RichardKnowles commented 2 years ago

Thanks both, I had totally forgotten about Manning and O'Reilly - I'm unable to post updates to the course (or at least, not easily), so the M1 issue hasn't been addressed there. I'll copy and paste a text lecture which has been added to the Udemy version below, which should solve the problem.

I really should switch the default images so that they are all multi arch, and now I've been reminded about the other providers the course is with, I will do just that. But in the meantime, here's the udemy text update:


As I mentioned at the start, the course should work for Apple M1 machines. The problem is that the images were built to target the linux/amd64 platform (that means x86 processors built by Intel and AMD). Until Apple released their new architecture (based on ARM),  linux/amd64 was almost always the target for a docker image for desktops and servers.

Most of the images used on this course will actually run on both architectures (there is an emulation mode), but some images will break when run on the "wrong" platform.

Sadly our "webapp" is one of those that breaks. So, we've recently rebuilt this image to be "multi architecture" which means the new image contains both an amd64 AND an arm64 image. The correct one to run will be automatically chosen for you.

To use it, all you need to do is to append "-mutli" to the end of the image tag. You only need to do this for the web application!

So, in the next video, when everybody else is using the image called "richardchesterwood/k8s-fleetman-webapp-angular:release0-5", you need to use the following:

richardchesterwood/k8s-fleetman-webapp-angular:release0-5-multi

And you will need to remember to add the -multi to all future fleetman-webapp images that we use.

Once I've had feedback that this is working, I'll make all the images multi architecture and switch them so that we're all using the same.

Sorry for this slight niggle - that's the price you pay for being on the cutting edge ;-)

RichardKnowles commented 2 years ago

Friday is the first free day, I will make multi arch versions of all images and make them the default versions for all.

RichardKnowles commented 2 years ago

Plan:

RichardKnowles commented 2 years ago

API Gateway

(there is a :resources and :performance tag which are both still used. :resources is a tuned java variant from the requests section, not sure about performance.)

k8s-fleetman-position-simulator

(:resources again, and :configmapsdemo. The latter is minor and I'll ignore for now.)

k8s-fleetman-position-tracker

queue

Now run test suite

RichardKnowles commented 2 years ago

Hi all, I've pushed the new multi images but for now I'm keeping them separate from the default images used on the course - in case I break something.

Just append "-multi" to any image tag (eg richardchesterwood/k8s-fleetman-queue:release1-multi) and your correct image should download.

I've tested the images on amd but not arm so let me know whether these work or not - then I can make the standard tags point to these so all the manning and o'reilly customers will start picking them up.

RichardKnowles commented 2 years ago

Stop press - argh, sorry I HAVE broken something. Java version mismatch in at least one of the images. Please hold off trying this, I'm going to need to re-do the work tomorrow. I'll update here when they have been repushed, many apologies.

RichardKnowles commented 2 years ago

Ok everyone! -multi images now available for all. Let me know if any problems, next week I'll switch them so that they become the defaults for all. Many thanks for your help here.

DickChesterwood commented 1 year ago

Superceded by events: all images now have separate arm64 images, to keep this simpler for the course (not for me though).