Automation own job through Jenkins And publish over Kubernetes through HTTPD or NGINX

6/27/2019

I have my some files which is in react lng. I am doing build from npm.I am doing locally this build.I have the build path. I want to deploy this build to pods of the kubernetes. how to write the deployment.yaml? how to configure my nginx or httpd root folder which can publish my codes? If first i have to make the docker image of that project file , then how?

-- AKASH PREET
httpd.conf
jenkins
kubernetes
kubernetes-deployment
nginx

1 Answer

6/28/2019

First you have to create Dockerfile:

Egg. Dockerfile:

FROM golang
WORKDIR /go/src/github.com/habibridho/simple-go
ADD . ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix .
EXPOSE 8888
ENTRYPOINT ./simple-go

Build your image and try to run it.

$ docker build -t simple-go .

$ docker run -d -p 8888:8888 simple-go

Next step is transferring image to the server. You can use Docker Hub. You can push image to the repository and pull it from the server.

-- on local machine

$ docker tag simple-go habibridho/simple-go

$ docker push habibridho/simple-go

-- on server

$ docker pull habibridho/simple-go

You have to note that the default docker repository visibility is public, so if your project is private, you need to change the project visibility from the Docker Hub website.

Useful information about that process you can find here: docker-images

Once we have the image in our server, we can run the app just like what we have done in our local machine by creating deployment.

The following is an example of a Deployment. It creates a ReplicaSet to bring up three your app Pods:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: your-app
  template:
    metadata:
      labels:
        app: your-app
    spec:
      containers:
      - name: your-app
        image: your-app:version
        ports:
        - containerPort: port

In this example:

A Deployment named your-deployment is created, indicated by the .metadata.name field.

  • The Deployment creates three replicated Pods, indicated by the replicas field.

  • 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: your-app).

However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.

To create Deployment, run the following command:

$ kubectl create -f your_deployment_file_name.yaml

More information you can find here: kubernetes-deployment.

-- MaggieO
Source: StackOverflow