DEV Community

Cover image for Deploying an Application on Kubernetes: A Complete Guide!

Deploying an Application on Kubernetes: A Complete Guide!

Pavan Belagatti on February 13, 2023

Kubernetes is an open-source platform for automating the deployment, scaling, and management of containerized applications. It is a popular tool fo...
Collapse
 
derlin profile image
Lucy Linder • Edited

Nice one! Just one comment: syntax highlighting for code blocks would improve readability. You can do it by specifying the language after the opening three backticks, for example (replace the single quotes with backticks in your head):

'''yaml
key: value #comment
'''
Enter fullscreen mode Exit fullscreen mode

You can use bash, javascript, yaml, etc.

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

Thanks for the suggestion. That's really valuable. Yes, I will add it.

Collapse
 
star_trooper profile image
Atharva Shirdhankar

Awesome Write up Pavan✨

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

Glad you liked it!

Collapse
 
taradevops profile image
TaraDevOps

Hi Pavan, Very nice hands-on content... But I have a quick question. I have set up the GKE cluster for the Hands-on. After installing the Nodejs, when when I run the command "npm install", I got this error. Please suggest me.

ganeshbhanda@cloudshell:~ (central-insight-3791)$ cd notes-app-cicd/
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ npm install
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/ganeshbhanda/notes-app-cicd/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/home/ganeshbhanda/notes-app-cicd/node_modules'
npm ERR! [Error: EACCES: permission denied, mkdir '/home/ganeshbhanda/notes-app-cicd/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/home/ganeshbhanda/notes-app-cicd/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/ganeshbhanda/.npm/_logs/2023-02-28T16_17_08_511Z-debug-0.log
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ sudo npm install
sudo: npm: command not found
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ sudo install npm
install: missing destination file operand after 'npm'
Try 'install --help' for more information.

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

Are you on the right path and running the command?
Have you installed the Node.js and npm properly?

I see the error that says 'sudo: npm: command not found'. So you have not installed npm I believe.

use this command
npm install -g npm

Check the version of Node.js and npm with the following commands (verify you have installed properly)

node -v
npm -v

Try and let me know

Collapse
 
taradevops profile image
TaraDevOps

I just checked it. Here are the outputs.

ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ npm install -g npm

changed 25 packages in 10s

16 packages are looking for funding
run npm fund for details
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ node -v
v18.12.1
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ npm -v
9.5.1
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ npm install
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/ganeshbhanda/notes-app-cicd/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/home/ganeshbhanda/notes-app-cicd/node_modules'
npm ERR! [Error: EACCES: permission denied, mkdir '/home/ganeshbhanda/notes-app-cicd/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/home/ganeshbhanda/notes-app-cicd/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/ganeshbhanda/.npm/_logs/2023-02-28T17_28_26_878Z-debug-0.log
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$

Thread Thread
 
taradevops profile image
TaraDevOps

Hi Pavan,

Can you please help me on this issue?

Thread Thread
 
pavanbelagatti profile image
Pavan Belagatti

Please check this link - stackoverflow.com/questions/252909...

Thread Thread
 
taradevops profile image
TaraDevOps

Thank you Pavan, this link helped me to move forward but when I ran the below command,
docker buildx create --use unix:///var/run/docker.sock --platform=linux/arm64 --platform=linux/arm64 -t docker.io/dockerisimage/node:14-alpine --push -f ./Dockerfile .

IT GAVE ME THE ERROR. Please help me on this.
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$ docker buildx create --use unix:///var/run/docker.sock --platform=linux/arm64 --platform=linux/arm64 -t docker.io/mydockerisimages/node:14-alpine --push -f ./Dockerfile .
unknown shorthand flag: 't' in -t
See 'docker buildx create --help'.
ganeshbhanda@cloudshell:~/notes-app-cicd (central-insight-3791)$

Thread Thread
 
pavanbelagatti profile image
Pavan Belagatti

The command you used is for Mac M1, use the below commands to build and push your image.

docker build -t $your docker hub user name/$image name .
Enter fullscreen mode Exit fullscreen mode
docker push $your docker hub user name/$image name .
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
taradevops profile image
TaraDevOps

Thank you for your help Pavan. But when I am authorizing GitHub (Using GitHub username and GitHub token) with Harness, I encountered this error:

Illegal character in path at index 50: github.com/TaraGithub/notes-app-ci... app cicd/info/refs?service=git-upload-pack

Please help me on this.

Collapse
 
richard_knowlden_df9a501a profile image
Richard Knowlden

Thank you and a clean implementation. Kudos to you

2 missing steps for completion. Hope you could add them for any future readers:

The below line is needed so that the browser works

kubectl port-forward service/node-service 32729:8000
Enter fullscreen mode Exit fullscreen mode

_* 32729 is the default assigned by KIND when you wont provide one. Otherwise you can provide one in the service.yaml _

apiVersion: v1
kind: Service
metadata:
  name: node-service
  namespace: default
spec:
  type: LoadBalancer
  selector:
    app: node-app
  ports:
  - port: 80
    targetPort: 8000
    nodePort: 30252
Enter fullscreen mode Exit fullscreen mode

Another thing missing in the dockerfile to expose the port 8000. Also, you code is pointing to port 8004

apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-app
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: node-app
  template:
    metadata:
      labels:
        app: node-app
    spec:
      containers:
      - name: node-app
        image: <DOCKER_REPO_USER_NAME_HERE>/node-image
        imagePullPolicy: Always
        ports:
        - containerPort: 8000

Enter fullscreen mode Exit fullscreen mode
Collapse
 
stumbinocodes profile image
stumbinocodes • Edited

Roughly how much is it to run a basic kubernetes stack in google cloud? Need to know for creating a basic blog post site.