Service fails to run on Kubernetes due to authentication issue with NPM

11/19/2019

I'm attempting to deploy a service to the google cloud kubernetes platform. All other services are running fine, but this one fails to load up due to an authentication error. I'm not sure what the issue is.

This is the error:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

I've assured of the following:

  • .npmrc file with the correct registry.
  • Cloudbuild.yaml present.

  • Dockerfile present.

The configuration is pretty much the same as the other services that do work.

Edit: Also, there is an authentication token associated with this build from a base Docker image that's linked in the dockerfile.

-- BURGERFLIPPER101
google-cloud-platform
kubernetes
npm

1 Answer

11/19/2019

Fixed the issue:

FROM gcr.io/xxxxx

# Copy in the project files
COPY . .

# Clean
USER root
RUN rm -fr node_modules

USER pptruser

ENV NODE_ENV=production

RUN npm install && \
    npm cache clean --force

EXPOSE 4000

# Running the app
CMD [ "npm", "start" ]

The "pptruser" was not present but after comparing some other dockerfiles from other services I realized its use was essential.

-- BURGERFLIPPER101
Source: StackOverflow