Adding deployment file

This commit is contained in:
Kris Crawford 2023-11-22 10:45:57 -05:00
parent 4077efcca6
commit e1375565e0
4 changed files with 64 additions and 4 deletions

23
Dockerfile Normal file
View 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
View 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

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module golang-http-header
go 1.21.4

View File

@ -18,16 +18,16 @@ func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Server-Hostname", hostname) w.Header().Set("Server-Hostname", hostname)
// Send a response // Send a response
fmt.Fprintf(w, "Hello! This is server: %s\n", hostname) fmt.Fprintf(w, "This is server: %s\n", hostname)
} }
func main() { func main() {
// Define the handler function for incoming requests // Define the handler function for incoming requests
http.HandleFunc("/", handler) http.HandleFunc("/", handler)
// Start the HTTP server on port 8080 // Start the HTTP server on port 8000
fmt.Println("Server listening on :8080...") fmt.Println("Server listening on :8000...")
err := http.ListenAndServe(":8080", nil) err := http.ListenAndServe(":8000", nil)
if err != nil { if err != nil {
fmt.Println("Error:", err) fmt.Println("Error:", err)
} }