-1

Let's say I want to run a container from an image from docker hub, let's say mosquitto I'd execute docker run -it -p 1883:1883 -p 9001:9001 eclipse-mosquitto.

I tried to pull the image from gcr.io (deployment.yaml) like done here:

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>
...

However when I run skaffold --dev --port-forward I get an error in the output:

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

How do I have to configure skaffold.yaml (schema version v2beta10) when using kubectl to run the mosquitto container as part of a deployment?

thinwybk
  • 4,193
  • 2
  • 40
  • 76

2 Answers2

1

You could create a pod with a single container referencing eclipse-mosquitto, and then ensure that pod is referenced from your 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

You could turn this into a deployment or replicaset with services, etc.

Brian de Alwis
  • 2,814
  • 2
  • 18
  • 32
  • It's not clear to me how `skaffold` knows about that an `image` needs to be pulled from docker hub. – thinwybk Dec 18 '20 at 11:29
  • @brian-de-silva I added my cunnrent config and error output to the question. – thinwybk Dec 18 '20 at 12:45
  • Skaffold submits the pod definition, as specified in a kubernetes manifest referenced from your `skaffold.yaml`, to your Kubernetes cluster and the cluster pulls the image. – Brian de Alwis Dec 19 '20 at 03:05
0

First, pull the image from docker hub onto the local machine: docker pull eclipse-mosquitto

Second, refer the image in the mqtt-broker/deployment.yaml e.g.:

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

Third, reference the deploment.yaml in skaffold.yaml` e.g.:

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>
thinwybk
  • 4,193
  • 2
  • 40
  • 76