<p>This is a bit tricky,I have a K8s cluster up and running and i am able to execute a docker image inside that cluster and i can see contents of command “kubectl get pods -o wide” .Now i have Gitlab setted up with this K8 cluster</p>

<p>I have set up variables $KUBE_URL $KUBE_USER and $KUBE_PASSWORD respectively in Gitlab with above K8 cluster</p>

<p>Here Gitlab runner console displays all these information as shown in console log below,at the end it fails for</p>

<pre><code>$ kubeconfig=cluster1-config kubectl get pods -o wide
error: the server doesn’t have a resource type “pods”
ERROR: Job failed: exit code 1
</code></pre>

<p>Here is full console log:</p>

<hr>

<pre><code>Running with gitlab-runner 11.4.2 (cf91d5e1)    
on WotC-Docker-ip-10-102-0-70 d457d50a
Using Docker executor with image docker:latest …
Pulling docker image docker:latest …
Using docker image sha256:062267097b77e3ecf374b437e93fefe2bbb2897da989f930e4750752ddfc822a for docker:latest …
Running on runner-d457d50a-project-185-concurrent-0 via ip-10-102-0-70…
Fetching changes…
Removing cluster1-config
HEAD is now at 25846c4 Initial commit
From https://git.com/core-systems/gatling
25846c4…bcaa89b master -&gt; origin/master
Checking out bcaa89bf as master…
Skipping Git submodules setup
$ uname -a
Linux runner-d457d50a-project-185-concurrent-0 4.14.67-66.56.amzn1.x86_64 #1 SMP Tue Sep 4 22:03:21 UTC 2018 x86_64 Linux
$ apk add --no-cache curl
fetch htt p://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch ht tp://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/4) Installing nghttp2-libs (1.32.0-r0)
(2/4) Installing libssh2 (1.8.0-r3)
(3/4) Installing libcurl (7.61.1-r1)
(4/4) Installing curl (7.61.1-r1)
Executing busybox-1.28.4-r1.trigger
OK: 6 MiB in 18 packages
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s ht tps : //storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload  Upload   Total   Spent    Left  Speed
0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
95 37.3M 95 35.8M 0 0 37.8M 0 --:–:-- --:–:-- --:–:-- 37.7M
100 37.3M 100 37.3M 0 0 38.3M 0 --:–:-- --:–:-- --:–:-- 38.3M
$ chmod +x ./kubectl
$ mv ./kubectl /usr/local/bin/kubectl
$ kubectl config set-cluster nosebit --server="$KUBE_URL" --insecure-skip-tls-verify=true
Cluster “nosebit” set.
$ kubectl config set-credentials admin --username="$KUBE_USER" --password="$KUBE_PASSWORD"
User “admin” set.
$ kubectl config set-context default --cluster=nosebit --user=admin
Context “default” created.
$ kubectl config use-context default
Switched to context “default”.
$ cat $HOME/.kube/config
apiVersion: v1
clusters:
  cluster:
    insecure-skip-tls-verify: true
    server: https://18.216.8.240:443
    name: nosebit    
contexts:    
  context:    
    cluster: nosebit    
    user: admin    
    name: default    
current-context: default    
kind: Config    
preferences: {}    
users:    
  name: admin    
  user:    
  password: |-    
    MIIDOzCCAiOgAwIBAgIJALOrUrxmhgpHMA0GCSqGSIb3DQEBCwUAMBgxFjAUBgNV    
    BAMMDTEzLjU4LjE3OC4yNDEwHhcNMTgxMTI1MjIwNzE1WhcNMjgxMTIyMjIwNzE1    
    WjAYMRYwFAYDVQQDDA0xMy41OC4xNzguMjQxMIIBIjANBgkqhkiG9w0BAQEFAAOC    
    AQ8AMIIBCgKCAQEA4jmyesjEiy6T2meCdnzzLfSE1VtbY//0MprL9Iwsksa4xssf    
    PXrwq97I/aNNE2hWZhZkpPd0We/hNKh2rxwNjgozQTNcXqjC01ZVjfvpvwHzYDqj    
    4cz6y469rbuKqmXHKsy/1docA0IdyRKS1JKWz9Iy9Wi2knjZor6/kgvzGKdH96sl    
    ltwG7hNnIOrfNQ6Bzg1H6LEmFP+HyZoylWRsscAIxD8I/cmSz7YGM1L1HWqvUkRw    
    GE23TXSG4uNYDkFaqX46r4nwLlQp8p7heHeCV/mGPLd0QCUaCewqSR+gFkQz4nYX    
    l6BA3M0Bo4GH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DCSkH8YckBeck-EIdvOnTKBmUACXVixPfUp9gAmUnit5qIPvvFnav-C-orfYt552NQ5GTLOA3yR5-jmxoYJwCJBfvPRb1GqqgiiJE2pBsu5Arm30MOi2wbt5uCNfKMAqcWiyJQF98M2PFc__jH6C1QWPXgJokyk7i8O6s3TD69KrrXNj_W4reDXourLl7HwHWoWwNKF0dgldanug-_zjvE06b6VZBI-YWpm9bpe_ArIOrMEjl0JRGerWahcQFVJsmhc4vgw-9-jUsfKPUYEfDItJdQKyV9dgdwShgzMINuuHlU7w7WBxmJT6cqMIvHRnDHuno3qMKTJTuh-g    
$ kubectl config view --minify &gt; cluster1-config    
$ export KUBECONFIG=$HOME/.kube/config    
$ kubectl --kubeconfig=cluster1-config config get-contexts    
CURRENT NAME CLUSTER AUTHINFO NAMESPACE    
    default   nosebit   admin     
$ kubeconfig=cluster1-config kubectl get pods -o wide    
error: the server doesn’t have a resource type “pods”    
ERROR: Job failed: exit code 1    
==================================================================================================
</code></pre>

<p>Here is my .gitlab-ci.yml content, could you suggest why kubectl get pods not displaying pods of the remote cluster even when KUBECONFIG set up is done successfully?</p>

<pre><code>image : docker:latest    
variables:    
CONTAINER_DEV_IMAGE: https://hub.docker.com/r/tarunkumard/gatling/:$CI_COMMIT_SHA    
stages:    
deploy
deploy:    
stage: deploy    
tags:    
- docker
script:    
  ‘uname -a’    
  ‘apk add --no-cache curl’    
  ‘curl -LO http s://storage.go ogleapis.com/kubernetes-release/release/$(curl -s htt ps:// storage.googlea pis .com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl’    
  ‘chmod +x ./kubectl’    
  ‘mv ./kubectl /usr/local/bin/kubectl’    
  ‘kubectl config set-cluster nosebit --server="$KUBE_URL" --insecure-skip-tls-verify=true’    
  ‘kubectl config set-credentials admin --username=" " --password="$KUBE_PASSWORD"’    
  ‘kubectl config set-context default --cluster=nosebit --user=admin’    
  ‘kubectl config use-context default’    
  ‘cat $HOME/.kube/config’    
  ‘kubectl config view --minify &gt; cluster1-config’    
  ‘export KUBECONFIG=$HOME/.kube/config’    
  ‘kubectl --kubeconfig=cluster1-config config get-contexts’    
  'kubeconfig=cluster1-config kubectl get pods -o wide ’
</code></pre>

<p>Why gitlab runner failing to get pods from Kubernetes cluster(Note This cluster is up and running using and I am able to see pods using kubectl get pods command )</p>

Margaret real
<p>Basically,</p>

<pre><code>kubectl config view --minify &gt; cluster1-config
</code></pre>

<p>Won't do it, because the output will be something like this with no actual credentials/certs:</p>

<pre><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://&lt;kube-apiserver&gt;:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    namespace: default
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
</code></pre>

<p>You need:</p>

<pre><code>kubectl config view --raw &gt; cluster1-config
</code></pre>

<p>If that's not the issue. It could be that your credentials don't have the right <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/" rel="nofollow noreferrer">RBAC</a> permissions. I would try to find the <code>ClusterRoleBinding</code> or <code>RoleBinding</code> that is bound for that admin user. Something like:</p>

<pre><code>$ kubectl get clusterrolebinding -o=jsonpath='{range .items[*]}{.metadata.name} {.roleRef.name} {.subjects}{"\n"}{end}' | grep admin
$ kubectl get rolebinding -o=jsonpath='{range .items[*]}{.metadata.name} {.roleRef.name} {.subjects}{"\n"}{end}' | grep admin
</code></pre>

<p>Once you find the role, you can see if it has the right permissions to view <code>pods</code>. For example:</p>

<pre><code>$ kubectl get clusterrole cluster-admin -o=yaml
</code></pre>
