我有一个 minikube 设置,其中容器在启动时需要访问 npm 注册表。但是 pod 无法连接到 npm 注册表。我的印象是所有传出连接都是从 K8s 打开的。
从 pod 记录
kubectl logs <pod_name>
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/sequelize-cli failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-04-14T12_16_23_892Z-debug.log
Install for [ 'sequelize-cli@latest' ] failed with code 1
Dockerfile
FROM node:14.15.4-alpine
WORKDIR /app
COPY package.json .
RUN yarn install && yarn global add npx
COPY . .
EXPOSE 3000
ENTRYPOINT ["./entrypoint.sh"]
CMD [ "npm", "run", "start" ]
入口点.sh
#!/bin/sh
set -e # Stop on any error
npx sequelize-cli db:migrate:all # Run migrations
npx sequelize-cli db:seed:all # Preload initial data
exec "$@" # Run the command as the main container process
部署.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: service-auth-deployment
spec:
replicas: 1
selector:
matchLabels:
component: service-auth
template:
metadata:
labels:
component: service-auth
spec:
containers:
- name: service-auth
image: REMOVED:1.0.0
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 3000
env:
- name: SESSION_SECRET
value: REMOVED
- name: DB_USER
value: auth
- name: DB_PASS
value: secret
- name: DB_NAME
value: users
- name: DB_HOST
value: mysql
imagePullSecrets:
- name: dockerhub-secret
服务集群 Ip.yml
apiVersion: v1
kind: Service
metadata:
name: service-auth-cluster-ip-service
spec:
type: ClusterIP
selector:
component: service-auth
ports:
- port: 3000
targetPort: 3000
如果需要更多信息,请告诉我。我是k8s的新手。