Skip to content

Commit

Permalink
Merge pull request #50 from GMH233/dev
Browse files Browse the repository at this point in the history
完成验收答辩
  • Loading branch information
sjtuzc954 authored Jun 7, 2024
2 parents 1248713 + f811458 commit 0c26895
Show file tree
Hide file tree
Showing 119 changed files with 13,673 additions and 7 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main", "dev"]
pull_request:
branches: [ "main", "dev" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.x'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
Empty file removed cmd/_your_app_/.keep
Empty file.
33 changes: 33 additions & 0 deletions cmd/envoy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 使用官方的 Golang 镜像作为基础镜像
FROM golang:bullseye AS builder

# 设置工作目录
WORKDIR /app

# 复制源代码到工作目录
COPY . .

WORKDIR /app/cmd/envoy
# 编译 Go 程序
RUN go build -o /envoy

# 使用官方的 Debian 镜像作为基础镜像
FROM debian:bullseye

# 设置工作目录
WORKDIR /app

# 从构建阶段复制编译后的 Go 程序
COPY --from=builder /envoy .

# 创建用户和组,并设置 UID 为 1337
RUN groupadd -g 1337 envoy_proxy_group && useradd -u 1337 -g envoy_proxy_group -m envoy_proxy

# 更改文件所有者为新创建的用户和组
RUN chown -R envoy_proxy:envoy_proxy_group /app

# 切换到非特权用户
USER envoy_proxy

# 设置默认命令
CMD ["/app/envoy"]
14 changes: 14 additions & 0 deletions cmd/envoy/envoy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"log"
"minikubernetes/pkg/microservice/envoy"
)

func main() {
e, err := envoy.NewEnvoy("10.119.12.123")
if err != nil {
log.Fatalf("Failed to create envoy: %v", err)
}
e.Run()
}
38 changes: 38 additions & 0 deletions cmd/envoyinit/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 使用官方的 Golang 镜像作为基础镜像
FROM golang:bullseye AS builder

# 设置工作目录
WORKDIR /app

# 复制源代码到工作目录
COPY . .

WORKDIR /app/cmd/envoyinit
# 编译 Go 程序
RUN go build -o /envoy-init

# 使用官方的 Debian 镜像作为基础镜像
FROM debian:bullseye

USER root

# 安装 iptables
RUN apt-get update && apt-get install -y iptables && rm -rf /var/lib/apt/lists/*

# 设置工作目录
WORKDIR /app

# 从构建阶段复制编译后的 Go 程序
COPY --from=builder /envoy-init .

## 创建用户和组,并设置 UID 为 1337
#RUN groupadd -g 1337 envoy_proxy_group && useradd -u 1337 -g envoy_proxy_group -m envoy_proxy
#
## 更改文件所有者为新创建的用户和组
#RUN chown -R envoy_proxy:envoy_proxy_group /app
#
## 切换到非特权用户
#USER envoy_proxy

# 设置默认命令
CMD ["/app/envoy-init"]
18 changes: 18 additions & 0 deletions cmd/envoyinit/envoy_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"log"
envoyinit "minikubernetes/pkg/microservice/envoy/init"
)

func main() {
e, err := envoyinit.NewEnvoyInit()
if err != nil {
log.Fatalf("Failed to create envoy: %v", err)
}
err = e.Init()
if err != nil {
log.Fatalf("Failed to init envoy: %v", err)
}
log.Println("Envoy init success.")
}
13 changes: 13 additions & 0 deletions cmd/kube-apiserver/apiserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import "minikubernetes/pkg/kubeapiserver/app"

/* This is the starting interface of apiserver in main */

func main() {
kubeApiServer, err := app.NewKubeApiServer()
if err != nil {
return
}
kubeApiServer.Run()
}
10 changes: 10 additions & 0 deletions cmd/kube-controller-manager/controllerManager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"minikubernetes/pkg/controller"
)

func main() {
cm := controller.NewControllerManager("192.168.1.10")
cm.Run()
}
7 changes: 7 additions & 0 deletions cmd/kubectl/kubectl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "minikubernetes/pkg/kubectl/cmd"

func main() {
cmd.Execute()
}
18 changes: 18 additions & 0 deletions cmd/kubectl/testyaml/dns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: DNS
metadata:
name: nginx-dns
spec:
rules:
- host: myservice.com
paths:
- path: /service1
backend:
service:
name: nginx-service
port: 801
- path: /service2
backend:
service:
name: nginx-service-2
port: 802
28 changes: 28 additions & 0 deletions cmd/kubectl/testyaml/hpa-cpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
kind: HorizontalPodAutoscaler
apiVersion: v1
metadata:
name: test-hpa
spec:
scaleTargetRef:
kind: ReplicaSet
name: nginx-replicaset
namespace: default
minReplicas: 1
maxReplicas: 3
scaleWindowSeconds: 20
metrics:
- name: cpu
target:
type: Utilization
averageUtilization: 50
upperThreshold: 80
lowerThreshold: 20
behavior:
scaleUp:
type: Pods
value: 1
periodSeconds: 60
scaleDown:
type: Pods
value: 1
periodSeconds: 60
26 changes: 26 additions & 0 deletions cmd/kubectl/testyaml/hpa-memory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
kind: HorizontalPodAutoscaler
apiVersion: v1
metadata:
name: test-hpa
spec:
scaleTargetRef:
kind: ReplicaSet
name: nginx-replicaset
namespace: default
minReplicas: 1
maxReplicas: 3
scaleWindowSeconds: 20
metrics:
- name: memory
target:
type: AverageValue
AverageValue: 100
behavior:
scaleUp:
type: Pods
value: 1
periodSeconds: 60
scaleDown:
type: Pods
value: 1
periodSeconds: 60
14 changes: 14 additions & 0 deletions cmd/kubectl/testyaml/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: Pod
apiVersion: v1
metadata:
name: nginx-pod-1
namespace: default
labels:
app: nginx
spec:
containers:
- name: container
image: python:latest
ports:
- containerPort: 1024
protocol: tcp
23 changes: 23 additions & 0 deletions cmd/kubectl/testyaml/replicaset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
kind: ReplicaSet
apiVersion: v1
metadata:
name: nginx-replicaset
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
name: nginx-pod
namespace: default
labels:
app: nginx
spec:
containers:
- name: container
image: python:latest
ports:
- containerPort: 1024
protocol: tcp
25 changes: 25 additions & 0 deletions cmd/kubectl/testyaml/rolling-update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: RollingUpdate
metadata:
name: my-ru
spec:
serviceRef: reviews
port: 9080
minimumAlive: 1
interval: 20
newPodSpec:
containers:
- name: reviews
image: istio/examples-bookinfo-reviews-v3:1.19.1
ports:
- containerPort: 9080
protocol: tcp
- name: envoy-proxy
image: sjtuzc/envoy:1.1
securityContext:
runAsUser: 1337
initContainers:
- name: proxy-init
image: sjtuzc/envoy-init:latest
securityContext:
privileged: true
13 changes: 13 additions & 0 deletions cmd/kubectl/testyaml/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: Service
apiVersion: v1
metadata:
name: nginx-service

spec:
type: NodePort
ports:
- port: 801
targetPort: 1024
nodePort: 30081
selector:
app: nginx
9 changes: 9 additions & 0 deletions cmd/kubectl/testyaml/subset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Subset
metadata:
name: nginx-v1
namespace: default
spec:
pods:
- nginx-pod-1
- nginx-pod-2
11 changes: 11 additions & 0 deletions cmd/kubectl/testyaml/virtual-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: VirtualService
metadata:
name: nginx-vs
namespace: default
spec:
serviceRef: nginx-service
port: 802
subsets:
- name: nginx-v1
weight: 1
Loading

0 comments on commit 0c26895

Please sign in to comment.