Skip to content

Conversation

@leonamvasquez
Copy link

This PR improves the Dockerfile used to build the K9s binary:

  • Removes unnecessary dependencies such as vim
  • Adds OCI-compliant labels for image metadata
  • Disables CGO and applies -trimpath for reproducible builds
  • Cleans up build dependencies to reduce final image size
  • Replaces redundant platform flag based on Docker BuildKit warning

These improvements make the image more production-ready, smaller, and secure.

&& curl -fsSL https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${TARGET_ARCH}/kubectl -o /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl \
&& apk del --purge deps
&& apk del curl
Copy link

@BryanDollery BryanDollery Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it simpler/more-efficient to just import the kubectl binary from another image? If you do this:

FROM bitnami/kubectl:1.29 as kubectl_image

before line 23, the final FROM statement, then you can add:

COPY --chmod=0755 --from=kubectl_image /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/kubectl

Which seems cleaner than install and uninstalling curl just so that you can download kubectl.

Alternatively, you could use the ADD command:

ADD --chmod=0755 "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl" /usr/local/bin/kubectl

Which is closer to your original intent, but the target arch is taken care of automatically with the FROM version, I believe, but the version is a little more abstracted.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or use wget which is there anyway.

@derailed derailed added the needs-tlc Pr needs additional updates label Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-tlc Pr needs additional updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants