Welcome to the Linux Foundation Forum!

Lab Exercises 4.1

mmaussner
mmaussner Posts: 5
edited August 2022 in LFS258 Class Forum

kinda stuck here .. maybe somebody know whats wrong

if i try the example from the course :

`
kubectl -n kube-system exec -it etcd-k8s-test.panday.local -- sh -c "ETCDCTL_API=3 \

ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt \

ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt \

ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key \

etcdctl endpoint health"

sh: : command not found

Error: KeyFile and CertFile must both be present[key: /etc/kubernetes/pki/etcd/server.key, cert: ]
command terminated with exit code 128

markus@k8s-test:~$
`

doesnt work.. BUT

if i exec into the contaner it works just fine:

`
kubectl -n kube-system exec -it etcd-k8s-test.panday.local -- sh

sh-5.0# cd /etc/kubernetes/pki/etcd/

sh-5.0# echo *

ca.crt ca.key healthcheck-client.crt healthcheck-client.key peer.crt peer.key server.crt server.key

sh-5.0# export ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt

sh-5.0# export ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt

sh-5.0# export ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key

sh-5.0# etcdctl endpoint health

127.0.0.1:2379 is healthy: successfully committed proposal: took = 78.42549ms

`

why is that? i also found out if i write everything into ONE line it works too:

markus@k8s-test:~$ kubectl -n kube-system exec -it etcd-k8s-test.panday.local -- sh -c "ETCDCTL_API=3 ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key etcdctl endpoint health" 127.0.0.1:2379 is healthy: successfully committed proposal: took = 24.602875ms markus@k8s-test:~$

so why does the example from the "course" doesnt work ?

same with the next example from the "course" :

kubectl -n kube-system exec -it etcd-k8s-test.panday.local -- sh -c "ETCDCTL_API=3 --cert=./peer.crt --key=./peer.key --cacert=./ca.crt etcdctl --endpoints=https://127.0.0.1:2379 member list" sh: --cert=./peer.crt: No such file or directory command terminated with exit code 127

what i am curious. "-c" menas execute the command.. but you start with --cert ... what command is that? should not the the etcdcctl first? and if you just execute into the container it would end up in / i guess ... so when i change your example to

markus@k8s-test:~$ kubectl -n kube-system exec -it etcd-k8s-test.panday.local -- sh -c "ETCDCTL_API=3 cd /etc/kubernetes/pki/etcd/ && etcdctl --cert=./peer.crt --key=./peer.key --cacert=./ca.crt --endpoints=https://127.0.0.1:2379 member list" 28ef24cc2b5672b, started, k8s-test.panday.local, https://192.168.89.45:2380, https://192.168.89.45:2379, false markus@k8s-test:~$

so is this just on my side that i encounter things like that?

Best Answer

  • oleksazhel
    oleksazhel Posts: 57
    Answer ✓

    @mmaussner It simply doesn't see your cert like as if it is not in your command. In other words it sees your command as:

    kubectl -n kube-system exec -it etcd-k8s-test.panday.local -- sh -c "ETCDCTL_API=3 \
    ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt \
    ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key \
    etcdctl endpoint health"
    

    And for the second part of your questions -- yes, this is mistake in training course, but seems nobody cares of fixing these mistakes) That's why I stopped posting info about them at all)

Answers

  • @oleksazhel thanks for your answer. and a pitty if known mistakes arent fixed. :(

  • chrispokorni
    chrispokorni Posts: 2,349

    Hi @mmaussner,

    There are CLI tools that do not like back-slashes part of multi-line commands, or while copying from the PDF lab guide may introduce invisible characters that cause these CLI issues. In these cases, removing the back-slashes and converting multi-line commands into single liners should work instead.

    The ./peer.crt ./peer.key and ./ca.crt assume a relative path, achieved by cd-ing into /etc/kubernetes/pki/etcd/. This can also be achieved by replacing the relative with the absolute paths such as /etc/kubernetes/pki/etcd/peer.crt...

    In addition, the etcdctl command should be provided immediately after the API version 3 declaration, and not at the end :smile:

    Regards,
    -Chris

  • aware74
    aware74 Posts: 1

    I agree that the second example in the training materials need to be corrected.

    Why would you use the peer cert instead of the original cert?

    How could relative paths work if we're not cd'ing into any directory as part of the command?

    And how could the second command ever work if --cert=... precedes etcdctl itself?

  • This was posted in August 2022, March 23 I still got the same error

    doing the instructions on the pdf DOESN"T work....

    got the same problems...
    Udemy training that cost 12uds has fewer problems/errors than training 300usd... really?

    I guess this will me my first and last purchase on LF

  • chrispokorni
    chrispokorni Posts: 2,349

    Hi @andressasso84,

    Can you provide the commands that do not work and the error outputs generated as a result?

    Regards,
    -Chris

  • PDF:

    student@cp: ̃$ kubectl -n kube-system exec -it etcd-cp -- sh \ #Same as before
    -c "ETCDCTL_API=3 \ #Version to use
    ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt \ #Pass the certificate authority
    ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt \ #Pass the peer cert and key
    ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key \
    etcdctl endpoint health" #The command to test the endpoint

    andres@kubecp1:~$ kubectl -n kube-system exec -it etcd-kubecp1 -- sh
    sh-5.1# -c "ETCDCTL_API=3 \

    ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt \
    ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt \
    ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key \
    etcdctl endpoint health"

    sh: -c: command not found

    so that -c is causing troubles..

    fixed by using mmaussner recommendation..


    after fixing that I was able to continue with the lab updated CP to version v1.26.3
    followed the steps on the working ...
    checking from CP

    andres@kubecp1:~$ kubectl get node
    NAME STATUS ROLES AGE VERSION
    kubecp1 Ready control-plane 3d2h v1.26.3
    worker1 Ready 2d23h v1.26.3
    andres@kubecp1:~$

    but if want to do the same for the worker..

    andres@worker1:~$ kubectl get node
    E0323 04:04:03.498604 1390985 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
    E0323 04:04:03.499267 1390985 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
    E0323 04:04:03.501176 1390985 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
    E0323 04:04:03.502679 1390985 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
    E0323 04:04:03.504033 1390985 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
    The connection to the server localhost:8080 was refused - did you specify the right host or port?

    no clue way is doing that... but again.. lab fail, now I have to waste time and troubleshoot... a good way on learning... but I would hope that the lab works ...

  • chrispokorni
    chrispokorni Posts: 2,349

    Hi @andressasso84,

    As a result of how the Kubernetes environment is configured for this lab, the kubectl command is expected to fail from the worker node. The .kube/config file is not set on the worker, and I do not believe there is a step in the lab guide presenting a successful run from the worker node either.

    Regards,
    -Chris

Categories

Upcoming Training