39

I've created Hyper-V machine and tried to deploy Sawtooth on Minikube using Sawtooth YAML file : https://sawtooth.hyperledger.org/docs/core/nightly/master/app_developers_guide/sawtooth-kubernetes-default.yaml

I changed the apiVersion i.e. apiVersion: extensions/v1beta1 to apiVersion: apps/v1, though I have launched Minikube in Kubernetes v1.17.0 using this command

minikube start --kubernetes-version v1.17.0

After that I can't deploy the server. Command is

kubectl apply -f sawtooth-kubernetes-default.yaml --validate=false

It shows an error with "sawtooth-0" is invalid.

enter image description here

---
apiVersion: v1
kind: List

items:

- apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: sawtooth-0
  spec:
    replicas: 1
    selector:
      matchLabels:
        name: sawtooth-0
    template:
      metadata:
        labels:
          name: sawtooth-0
      spec:
        containers:
          - name: sawtooth-devmode-engine
            image: hyperledger/sawtooth-devmode-engine-rust:chime
            command:
              - bash
            args:
              - -c
              - "devmode-engine-rust -C tcp://$HOSTNAME:5050"

          - name: sawtooth-settings-tp
            image: hyperledger/sawtooth-settings-tp:chime
            command:
              - bash
            args:
              - -c
              - "settings-tp -vv -C tcp://$HOSTNAME:4004"

          - name: sawtooth-intkey-tp-python
            image: hyperledger/sawtooth-intkey-tp-python:chime
            command:
              - bash
            args:
              - -c
              - "intkey-tp-python -vv -C tcp://$HOSTNAME:4004"

          - name: sawtooth-xo-tp-python
            image: hyperledger/sawtooth-xo-tp-python:chime
            command:
              - bash
            args:
              - -c
              - "xo-tp-python -vv -C tcp://$HOSTNAME:4004"

          - name: sawtooth-validator
            image: hyperledger/sawtooth-validator:chime
            ports:
              - name: tp
                containerPort: 4004
              - name: consensus
                containerPort: 5050
              - name: validators
                containerPort: 8800
            command:
              - bash
            args:
              - -c
              - "sawadm keygen \
              && sawtooth keygen my_key \
              && sawset genesis -k /root/.sawtooth/keys/my_key.priv \
              && sawset proposal create \
                -k /root/.sawtooth/keys/my_key.priv \
                sawtooth.consensus.algorithm.name=Devmode \
                sawtooth.consensus.algorithm.version=0.1 \
                -o config.batch \
              && sawadm genesis config-genesis.batch config.batch \
              && sawtooth-validator -vv \
                  --endpoint tcp://$SAWTOOTH_0_SERVICE_HOST:8800 \
                  --bind component:tcp://eth0:4004 \
                  --bind consensus:tcp://eth0:5050 \
                  --bind network:tcp://eth0:8800"

          - name: sawtooth-rest-api
            image: hyperledger/sawtooth-rest-api:chime
            ports:
              - name: api
                containerPort: 8008
            command:
              - bash
            args:
              - -c
              - "sawtooth-rest-api -C tcp://$HOSTNAME:4004"

          - name: sawtooth-shell
            image: hyperledger/sawtooth-shell:chime
            command:
              - bash
            args:
              - -c
              - "sawtooth keygen && tail -f /dev/null"

- apiVersion: apps/v1
  kind: Service
  metadata:
    name: sawtooth-0
  spec:
    type: ClusterIP
    selector:
      name: sawtooth-0
    ports:
      - name: "4004"
        protocol: TCP
        port: 4004
        targetPort: 4004
      - name: "5050"
        protocol: TCP
        port: 5050
        targetPort: 5050
      - name: "8008"
        protocol: TCP
        port: 8008
        targetPort: 8008
      - name: "8800"
        protocol: TCP
        port: 8800
        targetPort: 8800
davnicwil
  • 28,487
  • 16
  • 107
  • 123
debo karmakar
  • 543
  • 2
  • 6
  • 10
  • What's behind that "enter image description here" link? Usually I'd expect to see some sort of textual error message; can you replace the link with the actual text of the error you're getting (not an image), and can you include enough of the actual YAML file (not a link) to demonstrate the error? – David Maze Dec 25 '19 at 17:08

3 Answers3

71

You need to fix your deployment yaml file. As you can see from your error message, the Deployment.spec.selector field can't be empty.

Update the yaml (i.e. add spec.selector) as shown in below:

  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: sawtooth-0
    template:
      metadata:
        labels:
          app.kubernetes.io/name: sawtooth-0
  • Why selector field is important?

The selector field defines how the Deployment finds which Pods to manage. In this case, you simply select a label that is defined in the Pod template (app.kubernetes.io/name: sawtooth-0). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.

Update:

The apiVersion for k8s service is v1:

- apiVersion: v1 # Update here
  kind: Service
  metadata:
    app.kubernetes.io/name: sawtooth-0
  spec:
    type: ClusterIP
    selector:
      app.kubernetes.io/name: sawtooth-0
    ... ... ...
Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
  • I did added selector in deployement and started the minikube machine, now the error is in service. this is the message I'm getting..................... ``` C:\Users\Debo>minikube status host: Running kubelet: Running apiserver: Running kubeconfig: Configured C:\Users\Debo>kubectl apply -f sawtooth-kubernetes-default.yaml --validate=false deployment.apps/sawtooth-0 created unable to recognize no matches for kind "Service" in version "apps/v1" ``` – debo karmakar Dec 26 '19 at 06:11
  • @debokarmakar Can you add the updated yaml to the question body, and the result of `kubectl version --short` command after starting minikube? – Kamol Hasan Dec 26 '19 at 07:05
  • C:\Users\Debo>kubectl version --short Client Version: v1.17.0 Server Version: v1.17.0 and yaml file I've updated in the question – debo karmakar Dec 26 '19 at 11:03
  • @debokarmakar, I've updated my answer, take a look. – Kamol Hasan Dec 26 '19 at 11:58
  • @debokarmakar WC, Accept the answer, this will be more appreciable – Kamol Hasan Dec 26 '19 at 20:29
  • About "app.kubernetes.io/name" does it means different vendors support different names? – Zufar Muhamadeev Dec 11 '20 at 09:39
  • 1
    @ZufarMuhamadeev see the [recommended](https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels) labels, but it can be anything. – Kamol Hasan Dec 11 '20 at 09:41
  • as for now (2021-04), the official tutorial about k8s part is outdated, current k8s version is v1.20.2, I runs it with docker driver on my Arch Linux. My usable yaml file can be found here, it made for u'all. Be sure to modify the volume path for persistent storage path and run `minikube mount src:dest` first if you runs with docker driver. https://gist.github.com/kmahyyg/6b5eb6554e3dc15cc751a668ef62f4ec – PotatoChips Apr 02 '21 at 16:53
2

For api version v1 (and also for apps/v1) you need to use app: <your lable>

apiVersion: v1
kind: Service
metadata:
  name: sawtooth-0
spec:
  selector:
    app: sawtooth-0

See : https://kubernetes.io/docs/concepts/services-networking/service/

Eylon
  • 701
  • 1
  • 5
  • 8
1

The answer for this is already covered by @Kamol


Some general possible reasons if you are still getting the error :

missing required field “XXX” in YYY
  1. Check apiVersion at the top of file (for Deployment, version is: apps/v1 & for service it's v1
  2. Check the spelling of "XXX"(unknown field) and check if syntax is incorrect.
  3. Check kind: ... once again.

If you find some other reason, please comment and let other's know :)

Ashutosh Tiwari
  • 1,496
  • 11
  • 20