-
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.
Merge pull request #1 from mailsonpeixe/LCD-25023
LCD-25023 - Day 5 Rotation Infra
- Loading branch information
Showing
11 changed files
with
214 additions
and
1 deletion.
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:1.20 AS builder | ||
WORKDIR /app | ||
COPY . . | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main main.go | ||
|
||
|
||
FROM alpine:latest | ||
WORKDIR /app | ||
COPY --from=builder /app/main ./ | ||
COPY --from=builder /app/static ./static | ||
EXPOSE 3000 | ||
CMD ["./main"] |
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 |
---|---|---|
@@ -1 +1,48 @@ | ||
# app-go | ||
# Project to learn kubernetes objects. | ||
|
||
Based in Go language show an index page in endpoint http | ||
|
||
### Prerequisite for Linux users | ||
|
||
Docker, Kind(or K3d), GO | ||
|
||
|
||
### Versions that you pay attention: | ||
|
||
GO Version: **1.20** | ||
|
||
Kubernetes Version: > **1.22** | ||
|
||
|
||
|
||
#### For localdev run: | ||
|
||
`./localbuild.sh` | ||
|
||
#### To build and push: | ||
|
||
if necessary, adjust url repository and run `./buildpush.sh` | ||
|
||
_Note: you have need permissions to upload the image Docker to repository._ | ||
|
||
|
||
### Deploy kubernetes local | ||
|
||
Run script `./start.sh` | ||
|
||
NOTE: in this case, we create a namespace called `lcd-25023` to app, check the script start.sh | ||
|
||
Check service NodePort `kubectl get services` | ||
|
||
### Stop app in kubernetes local | ||
|
||
Run script `./stop.sh` | ||
|
||
### Deploy Cloud Kubernetes | ||
NOTE: Check the context that you are connected, `kubectx` and `kubens` are useful commands | ||
NOTE 2: in this case, we create a namespace called `lcd-25023` and create a Ingress to app, check the script start.sh | ||
|
||
Run script `./startcloud.sh` | ||
|
||
and to stop and clear objects created, run `./stop.sh` | ||
|
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,6 @@ | ||
#!/bin/bash | ||
IMAGE=mailsonpeixe/app-go | ||
echo "Build and push image ${IMAGE}" | ||
|
||
docker build --push -t ${IMAGE}:1.0 . | ||
|
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,55 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: app-go | ||
labels: | ||
app: app-go | ||
spec: | ||
replicas: 2 | ||
strategy: | ||
type: RollingUpdate | ||
selector: | ||
matchLabels: | ||
app: app-go | ||
template: | ||
metadata: | ||
labels: | ||
app: app-go | ||
spec: | ||
terminationGracePeriodSeconds: 120 | ||
topologySpreadConstraints: #rule for spread pods in different zones | ||
- maxSkew: 1 | ||
topologyKey: topology.kubernetes.io/zone | ||
whenUnsatisfiable: ScheduleAnyway | ||
labelSelector: | ||
matchLabels: | ||
app: app-go | ||
containers: | ||
- name: app-go | ||
image: mailsonpeixe/app-go:1.0 | ||
imagePullPolicy: Always | ||
resources: | ||
requests: | ||
memory: "64Mi" | ||
cpu: "50m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "150m" | ||
ports: | ||
- containerPort: 3000 | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz/ready | ||
port: 3000 | ||
initialDelaySeconds: 5 | ||
failureThreshold: 3 | ||
successThreshold: 1 | ||
periodSeconds: 5 | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz/live | ||
port: 3000 | ||
initialDelaySeconds: 5 | ||
failureThreshold: 3 | ||
successThreshold: 1 | ||
periodSeconds: 5 |
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,18 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: my-ingress | ||
annotations: | ||
# If the class annotation is not specified it defaults to "gce". | ||
kubernetes.io/ingress.class: "gce" | ||
spec: | ||
rules: | ||
- http: | ||
paths: | ||
- path: /* | ||
pathType: ImplementationSpecific | ||
backend: | ||
service: | ||
name: app-go-serivce | ||
port: | ||
number: 3000 |
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,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: app-go-serivce | ||
labels: | ||
app: app-go | ||
spec: | ||
type: NodePort | ||
selector: | ||
app: app-go | ||
ports: | ||
- protocol: TCP | ||
port: 3000 | ||
targetPort: 3000 |
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,7 @@ | ||
#!/bin/bash | ||
|
||
docker build -t app-go . | ||
|
||
docker run -p 3000:3000 app-go | ||
|
||
#URL access http://localhost:3000 |
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 |
---|---|---|
@@ -1,10 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
fmt.Printf("Starting the app.\n") | ||
//Handlers to readiness and liveness | ||
http.HandleFunc("/healthz/ready", readinessHandler) | ||
http.HandleFunc("/healthz/live", livenessHandler) | ||
|
||
http.Handle("/", http.FileServer(http.Dir("./static"))) | ||
http.ListenAndServe(":3000", nil) | ||
} | ||
|
||
func readinessHandler(w http.ResponseWriter, r *http.Request) { | ||
// Check if the app is ready to serve requests | ||
// and return a 200 OK response if so | ||
// If not, return a 500 Internal Server Error response | ||
if isReady() { | ||
w.WriteHeader(http.StatusOK) | ||
} else { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
} | ||
|
||
func livenessHandler(w http.ResponseWriter, r *http.Request) { | ||
// Return a 200 OK response to indicate that the app is running | ||
w.WriteHeader(http.StatusOK) | ||
} | ||
|
||
func isReady() bool { | ||
// Implement your own readiness check here | ||
// For example, you might check if the app has successfully connected to a database | ||
return true | ||
} |
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,10 @@ | ||
#!/bin/bash | ||
|
||
NAMESPACE=lcd-25023 | ||
kubectl create namespace ${NAMESPACE} | ||
|
||
echo "Create deployment" | ||
kubectl apply -f kubernetes/deployment.yaml -n ${NAMESPACE} | ||
echo "Create service" | ||
kubectl apply -f kubernetes/service.yaml -n ${NAMESPACE} | ||
|
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 @@ | ||
#!/bin/bash | ||
|
||
NAMESPACE=lcd-25023 | ||
kubectl create namespace ${NAMESPACE} | ||
|
||
echo "Create deployment" | ||
kubectl apply -f kubernetes/deployment.yaml -n ${NAMESPACE} | ||
echo "Create service" | ||
kubectl apply -f kubernetes/service.yaml -n ${NAMESPACE} | ||
echo "Create ingress" | ||
kubectl apply -f kubernetes/ingress.yaml -n ${NAMESPACE} | ||
|
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,4 @@ | ||
#!/bin/bash | ||
|
||
echo "Removing app-go" | ||
kubectl delete namespace lcd-25023 |