-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 65d0787
Showing
9 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:alpine | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
|
||
ENV BG_COLOR=pink | ||
ENV HEADING_COLOR=steelblue | ||
ENV HEADING_TEXT='Docker Golang HTTP Server' | ||
|
||
RUN go install | ||
|
||
CMD ["/go/bin/go-k8s-http-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Prerequisites | ||
|
||
Install minikube and kubectl. | ||
|
||
# Note | ||
|
||
Building and running the docker image locally instead of pushing to docker hub. | ||
|
||
# Run in Docker | ||
|
||
`docker build -t philyawj/go-k8s-http-server .` | ||
|
||
`docker run --rm -p 8080:8080 philyawj/go-k8s-http-server` | ||
|
||
 | ||
|
||
http://localhost:8080 | ||
|
||
# Run in Kubernetes | ||
|
||
`docker build -t philyawj/go-k8s-http-server .` | ||
|
||
`minikube image load philyawj/go-k8s-http-server` | ||
|
||
`minikube image ls` | ||
|
||
`kubectl apply -f service.yaml` | ||
|
||
`minikube service mywebapp` | ||
|
||
 | ||
|
||
 | ||
|
||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/philyawj/go-k8s-http-server | ||
|
||
go 1.20 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func main() { | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
server := &http.Server{Addr: ":8080"} | ||
server.SetKeepAlivesEnabled(false) | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte("<body style='background-color:" + os.Getenv("BG_COLOR") + ";'>" + | ||
"<h1 style='color:" + os.Getenv("HEADING_COLOR") + ";'>" + os.Getenv("HEADING_TEXT") + "</h1>" + | ||
"<h3>served from " + hostname + "</h3>" + | ||
"</body>")) | ||
}) | ||
|
||
server.ListenAndServe() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: mywebapp | ||
labels: | ||
app: mywebapp | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
protocol: TCP | ||
name: gohttp | ||
selector: | ||
app: mywebapp | ||
tier: http | ||
type: LoadBalancer | ||
--- | ||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
name: myconfigmapv1.0 | ||
data: | ||
BG_COLOR: 'steelblue' | ||
HEADING_COLOR: 'white' | ||
HEADING_TEXT: 'Kubernetes Golang HTTP Server - refresh to see updated served from' | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: mydeployment | ||
labels: | ||
app: mywebapp | ||
spec: | ||
replicas: 5 | ||
selector: | ||
matchLabels: | ||
app: mywebapp | ||
tier: http | ||
template: | ||
metadata: | ||
labels: | ||
app: mywebapp | ||
tier: http | ||
spec: | ||
containers: | ||
- name: mycontainer | ||
image: philyawj/go-k8s-http-server | ||
imagePullPolicy: Never | ||
ports: | ||
- containerPort: 80 | ||
envFrom: | ||
- configMapRef: | ||
name: myconfigmapv1.0 |