-1

假设我想从docker hub 的图像中运行一个容器,假设我要执行mosquitto docker run -it -p 1883:1883 -p 9001:9001 eclipse-mosquitto

我试图从 gcr.io ( deployment.yaml) 中提取图像,就像这里所做的那样:

apiVersion: v1
kind: Service
metadata:
  name: mqtt-broker
  labels:
    app: mqtt-broker
spec:
  type: NodePort
  ports:
    - targetPort: 1883
      port: 1883
  selector:
    app: mqtt-broker
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mqtt-broker
  labels:
    app: mqtt-broker
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mqtt-broker
  template:
    metadata:
      labels:
        app: mqtt-broker
    spec:
      containers:
      - name: mqtt-broker
        image: gcr.io/vu-james-celli/eclipse-mosquitto  # https://hub.docker.com/_/eclipse-mosquitto
        ports:
        - containerPort: 1883

skaffold.yaml

apiVersion: skaffold/v2beta10
kind: Config
build:
  artifacts:
  - <other image builds>
deploy:
  kubectl:
    manifests:
      - mqtt-broker/*
portForward:
  - resourceType: deployment
    resourceName: mqtt-broker
    port: 1883
    localPort: 1883
  <other port forwardings>
...

但是,当我运行时skaffold --dev --port-forward,输出中出现错误:

- deployment/mqtt-broker: container mqtt-broker is waiting to start: gcr.io/vu-james-celli/eclipse-mosquitto can't be pulled

在部署中运行 mosquitto 容器时,我必须如何配置skaffold.yaml架构版本 v2beta10) ?kubectl

4

2 回答 2

1

您可以创建一个带有单个容器引用的 pod eclipse-mosquitto,然后确保从您的skaffold.yaml.

apiVersion: v1
kind: Pod
metadata:
  name: mqtt
spec:
  containers:
  - name: mqtt
    image: eclipse-mosquitto
    ports:
    - containerPort: 1883
      name: mqtt
    - containerPort: 9001
      name: websockets

您可以将其转换为具有服务等的部署或副本集。

于 2020-12-17T21:47:48.453 回答
0

首先,从 docker hub 拉取镜像到本地机器:docker pull eclipse-mosquitto

其次,参考mqtt-broker/deployment.yaml例如中的图像:

apiVersion: v1
kind: Service
metadata:
  name: mqtt-broker
  labels:
    app: mqtt-broker
spec:
  type: NodePort
  ports:
    - targetPort: 1883
      port: 1883
  selector:
    app: mqtt-broker
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mqtt-broker
  labels:
    app: mqtt-broker
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mqtt-broker
  template:
    metadata:
      labels:
        app: mqtt-broker
    spec:
      containers:
      - name: mqtt-broker
        image: eclipse-mosquitto
        ports:
        - containerPort: 1883

第三,引用deploment.yaml in skaffold.yaml` 例如:

apiVersion: skaffold/v2beta10
kind: Config
build:
  artifacts:
  - <services-under-development>
deploy:
  kubectl:
    manifests:
      - mqtt-broker/deployment.yaml
portForward:
  - resourceType: deployment
    resourceName: mqtt-broker
    port: 1883
    localPort: 1883
  - <port-forwarding-for-services-under-development>
于 2020-12-18T14:16:32.913 回答