Adding deployment file
This commit is contained in:
parent
4077efcca6
commit
e1375565e0
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@ -0,0 +1,23 @@
|
||||
# specify the base image to be used for the application
|
||||
FROM golang:1.21.4-alpine
|
||||
|
||||
# create the working directory in the image
|
||||
WORKDIR /app
|
||||
|
||||
# copy Go modules and dependencies to image
|
||||
COPY go.mod ./
|
||||
|
||||
# download Go modules and dependencies
|
||||
RUN go mod download
|
||||
|
||||
# copy all the Go files ending with .go extension
|
||||
COPY *.go ./
|
||||
|
||||
# compile application
|
||||
RUN go build -o /golang-http-header
|
||||
|
||||
# network port at runtime
|
||||
EXPOSE 8000
|
||||
|
||||
# execute when the container starts
|
||||
CMD [ "/golang-http-header" ]
|
34
deployment.yaml
Normal file
34
deployment.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: http-header
|
||||
labels:
|
||||
app: golang
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: golang
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: golang
|
||||
spec:
|
||||
containers:
|
||||
- name: http-header
|
||||
image: git.10bit.link/kcrawford/golang-http-header:0.0.4
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: go-frontend
|
||||
spec:
|
||||
selector:
|
||||
app: golang
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 8000
|
8
main.go
8
main.go
@ -18,16 +18,16 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Server-Hostname", hostname)
|
||||
|
||||
// Send a response
|
||||
fmt.Fprintf(w, "Hello! This is server: %s\n", hostname)
|
||||
fmt.Fprintf(w, "This is server: %s\n", hostname)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Define the handler function for incoming requests
|
||||
http.HandleFunc("/", handler)
|
||||
|
||||
// Start the HTTP server on port 8080
|
||||
fmt.Println("Server listening on :8080...")
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
// Start the HTTP server on port 8000
|
||||
fmt.Println("Server listening on :8000...")
|
||||
err := http.ListenAndServe(":8000", nil)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user