kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

Error trying to create deployment

Open pankajkumar229 opened this issue 6 years ago • 1 comments

I am trying to create a deployment using the following code snippet:

   return client.apis.apps.v1.namespaces(namespace).deployments.post({ body: doc })                                                                                                                        
        .then(function(res){                                                                                                                                                                                
            console.log(res)                                                                                                                                                                                
        }).catch(function(e){                                                                                                                                                                               
           console.log(e)                                                                                                                                                                                   
           if (e.code !== 409) return Promise.reject(e);                                                                                                                                                    
           return client.apis.apps.v1.namespaces(namespace).deployments("dc-notebook-{{id}}").put({ body: doc})                                                                                            
        });

I am getting this error:

Error: Failed to run cmd.                     
    at /app/node_modules/kubernetes-client/backends/request/auth-providers/cmd.js:54:23
    at new Promise (<anonymous>)              
    at Object.refresh (/app/node_modules/kubernetes-client/backends/request/auth-providers/cmd.js:30:12)
    at /app/node_modules/kubernetes-client/backends/request/client.js:21:14
    at new Promise (<anonymous>)
    at refreshAuth (/app/node_modules/kubernetes-client/backends/request/client.js:19:10)
    at Request._callback (/app/node_modules/kubernetes-client/backends/request/client.js:150:16)
    at Request.self.callback (/app/node_modules/request/request.js:185:22)                                                                                                                                 
    at Request.emit (events.js:203:13)                                      
    at Request.<anonymous> (/app/node_modules/request/request.js:1161:10)  

The kubernetes server version is 1.13 and the client is 8.3.3

pankajkumar229 avatar Aug 13 '19 02:08 pankajkumar229

I was able to solve this issue. From what I understand it wasn't able to authorize via the AWS creds as AWS CLI was missing on the image, thus the above error was popping up.

Below are the steps are did for it:

  1. Created a New User on AWS, Dev User
  2. Via eksctl I added an IAM mapping for the above new user created and gave the required group permission. In my case admin.
  3. Installed AWS CLI on the image as step one
  4. Copied my ${HOME}/.aws to /root/.aws
  5. Copied my /.kube/config for my cluster to /root/.kube
  6. Now when I run my server, it was able to perform post/patch/delete

Hope this helps

If you are using node:10-alpine, the below is the snippet from of Dockefile i made:

FROM node:10-alpine

RUN apk add --no-cache \
        python3 \
        py3-pip \
    && pip3 install --upgrade pip \
    && pip3 install \
        awscli \
    && rm -rf /var/cache/apk/*

WORKDIR /root/.kube

COPY ./.kube/ /root/.kube/

WORKDIR /root/.aws

COPY ./.aws/ /root/.aws/

ENV NODE_ENV=production \
    PORT=3000
    
EXPOSE 3000

WORKDIR /home/app

COPY . .

RUN npm install --only=development \
    && npm cache clean --force

CMD ["node", "server.js"]

farhanJR avatar Jan 29 '21 02:01 farhanJR