Skip to content

Commit 190cb46

Browse files
committed
chore: code clean
docs: add reademe
1 parent 86bcd97 commit 190cb46

39 files changed

+964
-208
lines changed

Directory.Packages.props

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageVersion Include="Blazored.LocalStorage" Version="4.3.0" />
7+
<PackageVersion Include="Blazored.SessionStorage" Version="2.3.0" />
78
<PackageVersion Include="IconPark.Blazor" Version="1.3.0.3" />
89
<PackageVersion Include="Jil" Version="2.17.0" />
910
<PackageVersion Include="JsonPatch.Net" Version="2.0.6" />
10-
<PackageVersion Include="KubeClient" Version="2.4.10" />
11-
<PackageVersion Include="KubeClient.Extensions.DependencyInjection" Version="2.4.10" />
12-
<PackageVersion Include="KubeClient.Extensions.WebSockets" Version="2.4.10" />
1311
<PackageVersion Include="KubernetesClient" Version="10.1.4" />
1412
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.15" />
1513
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.15" />
@@ -23,8 +21,8 @@
2321
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
2422
</ItemGroup>
2523
<ItemGroup>
26-
<PackageVersion Include="AntDesign" Version="0.13.3" />
27-
<PackageVersion Include="BcdLib.BcdForm" Version="0.6.0" />
24+
<PackageVersion Include="AntDesign" Version="0.14.4" />
25+
<PackageVersion Include="BcdLib.BcdForm" Version="0.7.0" />
2826
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.12" />
2927
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.12" PrivateAssets="all" />
3028
<PackageVersion Include="Microsoft.Extensions.Http" Version="6.0.0" />

README-ZH-CN.md

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# BasicKube
2+
3+
一个面向业务开发的k8s基础UI系统,非开箱即用,不适用于对K8s集群进行管理操作。
4+
5+
# 功能
6+
7+
## 环境和组
8+
9+
支持对资源进行环境划分:开发环境、测试环境、预发布环境、线上环境。不同环境的同一个服务或资源形成“组”。
10+
11+
![image-20230330001432516](assets/README/image-20230330001432516.png)
12+
13+
## K8s 基础功能支持
14+
15+
支持对以下 K8s 资源增删改查的**基本**操作。
16+
17+
1. - [x] Deployment
18+
- - [x] 主容器镜像发布
19+
![image-20230330001651823](assets/README/image-20230330001651823.png)
20+
- - [x] 伸缩
21+
2. - [x] Service
22+
![image-20230330001734647](assets/README/image-20230330001734647.png)
23+
3. - [x] Ingress
24+
![image-20230330001751219](assets/README/image-20230330001751219.png)
25+
4. - [x] DaemonSet
26+
5. - [x] Job
27+
28+
> **注意**
29+
> 在 BasicKube 中,Deployment 组又被称为应用组。应用广义上包含 Deployment、DaemonSet 等,在 BasicKube 中,在没有明确说明下,应用仅代指 Deployment。
30+
31+
## Pod 终端
32+
33+
BasicKube 提供一个 Web 终端,可以用来连接容器,对 Pod 进行操作。
34+
35+
![image-20230330000903519](assets/README/image-20230330000903519.png)
36+
37+
## Pod 事件查看
38+
39+
![image-20230330001509325](assets/README/image-20230330001509325.png)
40+
41+
# 配置
42+
43+
## IAM
44+
45+
IAM(身份验证和访问管理)受 AWS IAM 启发,用于在 k8s 集群上控制用户的命名空间权限。
46+
47+
### 设计理念
48+
49+
1. 通过关联一个 IAM 节点,可以将一个项目与一个 k8s 命名空间相关联。
50+
2. 一个项目可以有多个用户,一个用户也可在在多个项目下。
51+
52+
![](assets/README/iam.png)
53+
54+
### 配置IAM和命名空间的映射
55+
56+
1. 打开 `appsettings.json` 文件
57+
2. 添加 `K8s:NameSpaceMap` 选项:
58+
59+
```json
60+
{
61+
"Logging": {
62+
...
63+
},
64+
"K8s": {
65+
+ "NameSpaceMap": {
66+
"1": "default"
67+
}
68+
}
69+
}
70+
```
71+
72+
`K8s:NameSpaceMapg` 中,key 是 IAM 节点, 值是 k8s 的命名空间。
73+
74+
## K8s集群配置
75+
76+
1.`BasicKube.Api/configs` 目录下添加K8s的配置文件
77+
2. 添加 `K8s:ClusterConfig` 配置项:
78+
79+
```json
80+
{
81+
"K8s": {
82+
"NameSpaceMap": {
83+
...
84+
},
85+
+ "ClusterConfig": {
86+
"dev": "./configs/k8s-cluster-config-dev",
87+
"test": "./configs/k8s-cluster-config-default",
88+
"staging": "./configs/k8s-cluster-config-default",
89+
"prod": "./configs/k8s-cluster-config-default"
90+
}
91+
}
92+
}
93+
```
94+
95+
`K8s:ClusterConfig ` 配置项中,key 是环境名,value 是k8s集群的配置文件。
96+
97+
## 外部账号系统集成
98+
99+
BasicKube 中不涉及账号系统,需要通过 `AccountController` 和现有的账号体系进行集成。`AccountController` 位于`BasicKube.Api/Controllers/Account` 目录下。
100+
101+
# 协议
102+
103+
禁止商业使用,对个人学习或其他使用,参考MIT协议。
104+
105+
# OS
106+
107+
1. ASP.NET Core full-stack
108+
2. Ant Design Blazor
109+
3. KubernetesClient
110+
4. Blazored.*
111+
5. Serilog.*
112+
6. ...
113+

README.md

+113-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
1-
# BasicKube
1+
# BasicKube
2+
3+
A non-out-of-the-box basic k8s UI for business developers, not suitable for managing K8s clusters.
4+
5+
# Features
6+
7+
## Environment and Group
8+
9+
Support for environment-based resource partitioning: development environment, testing environment, staging environment, and production environment.
10+
11+
The same service or resource in different environments forms a "**group**".
12+
13+
![image-20230330001432516](assets/README/image-20230330001432516.png)
14+
15+
## Basic operations in Kubernetes:
16+
17+
Support basic CRUD (create, read, update, delete) operations for the following K8s resources:
18+
19+
1. - [x] Deployment
20+
- - [x] Publishing the main container image of a Pod![image-20230330001651823](assets/README/image-20230330001651823.png)
21+
- - [x] Scaling
22+
2. - [x] Service
23+
![image-20230330001734647](assets/README/image-20230330001734647.png)
24+
3. - [x] Ingress
25+
![image-20230330001751219](assets/README/image-20230330001751219.png)
26+
4. - [x] DaemonSet
27+
5. - [x] Job
28+
29+
> **note**
30+
> In BasicKube, the Deployment group is also referred to as the Application group. In a broad sense, an application includes Deployment, DaemonSet, and so on. However, in BasicKube, when not explicitly stated, the term "application" refers only to Deployment.
31+
32+
## Pod Container Terminal
33+
34+
BasicKube provides a web terminal that can be used to connect to containers and perform operations on Pods.
35+
36+
![image-20230330000903519](assets/README/image-20230330000903519.png)
37+
38+
## Viewing Pod events.
39+
40+
![image-20230330001509325](assets/README/image-20230330001509325.png)
41+
42+
# Configuration
43+
44+
## IAM
45+
46+
Identity and Access Management(IAM) inspired by AWS IAM, used to control user permissions on the k8s namespace.
47+
48+
### Design concept
49+
50+
1. One project is associated with a namespace by associating an IAM node.
51+
2. A project can contain multiple users, and a user can also be under multiple projects.
52+
53+
![](assets/README/iam.png)
54+
55+
### Configure the mapping of IAM node and namespace
56+
57+
1. Open `appsettings.json` file
58+
2. Add `K8s:NameSpaceMap` configuration:
59+
60+
```json
61+
{
62+
"Logging": {
63+
...
64+
},
65+
"K8s": {
66+
+ "NameSpaceMap": {
67+
"1": "default"
68+
}
69+
}
70+
}
71+
```
72+
73+
In the section `K8s:NameSpaceMapg`,key is the IAM node, and the value is k8s namespace.
74+
75+
## K8s cluster configuration
76+
77+
1. Add the configuration file for the k8s cluster under directory `BasicKube.Api/configs`
78+
2. Set the **mapping between the environment and the k8s cluster** in the `appsettings.json` file. The section is `K8s:ClusterConfig`:
79+
80+
```json
81+
{
82+
"K8s": {
83+
"NameSpaceMap": {
84+
...
85+
},
86+
+ "ClusterConfig": {
87+
"dev": "./configs/k8s-cluster-config-dev",
88+
"test": "./configs/k8s-cluster-config-default",
89+
"staging": "./configs/k8s-cluster-config-default",
90+
"prod": "./configs/k8s-cluster-config-default"
91+
}
92+
}
93+
}
94+
```
95+
96+
In the section `K8s:ClusterConfig`,key is the environment name, and the value is the configuration file for the k8s cluster .
97+
98+
## External account system integration
99+
100+
There is no account system function in BasicKube, it needs to be integrated with the existing account system in `AccountController`, which is under `BasicKube.Api/Controllers/Account`.
101+
102+
# License
103+
104+
Prohibition of commercial use, with reference to the MIT license for personal learning or other uses.
105+
106+
# OS Reference
107+
108+
1. ASP.NET Core full-stack
109+
2. Ant Design Blazor
110+
3. KubernetesClient
111+
4. Blazored.*
112+
5. Serilog.*
113+
6. ...

assets/README/iam.png

114 KB
Loading
26 KB
Loading
85.4 KB
Loading
85.4 KB
Loading
7.45 KB
Loading
58.8 KB
Loading
55.3 KB
Loading

assets/basic-kube.drawio

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2023-03-29T05:13:12.626Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/16.5.1 Chrome/96.0.4664.110 Electron/16.0.7 Safari/537.36" etag="hMGf2Mh31hmNzUv80xqW" version="16.5.1" type="device"><diagram id="AzPtRsoyrg-ZZ3mYgEX7" name="IAM">7VpbV+IwEP41PLqnbXrzEfCy7lkv57h7vLx4Co1ttTScNAj46zehKb1MQHRBiiIPJtNkaOb7ZiaT0ELdweSUesPwnPg4bhmaP2mho5Zh6Bpy+T8hmWYSWzvMBAGNfDmoEFxHrzifKaWjyMdpZSAjJGbRsCrskyTBfVaReZSScXXYI4mr3zr0AgwE130vhtKbyGdhJnUNp5D/xFEQ5t+s23J9Ay8fLFeShp5PxiUROm6hLiWEZa3BpItjYbzcLtm8kwVP5y9GccJWmXB7HvUukuuLE/eh7T/cdP4aQ/tAl2pevHgkV3zWPpcvzKa5FSgZJT4WirQW6ozDiOHrodcXT8ccdy4L2SDmPZ03U0bJ89xafJ0d30vD2Wzx+DGK4y6JCZ2pRscn4iPkJGESf92U/dI4x3HmunNxQhI+vAMtka8KU4YnJZG0zCkmA8zolA+ZVOkmWerK7riA3NGkLCzBjZAUepJmwVxzgQRvSDDeA4wGgAGoYJ9TVXYJZSEJSOLFx4W0U8WtGPObkKGE4wkzNpV290aMVLHEid8WXlQYm0tOIrGWmUqI9UIwUjKiffnm6ejg4MXoXV6evfauzL52ObgPDnL39miA2ZJxZjZOrH4ptBTHHoteqo78P0Ate+sSTqMUUx2AxYnIVH5S43LZO6TIi6Mg4d0+tyjm8o6gdcRDVFs+GES+P4Nb5ZhVCpSdzF6P65hV19FNC/iOrXKdNXiOEhBDCQj0nu8CiHEIg9mnAoKUgKBvC8g8aXwCIMrcAj1kG6kFpo63ks3HU4sJU4s66zYqtZgApyElT3yXC7NLgYb+9gatTvF3JPF37KicWl5QsF43FLS3N0V7aM6vvqOyVqQ9ahTtrUW0h3g1n/bGIdwObYz2SnPawJzPbtoSr2DHIt/2KG8FopV4A5wK8+1CfLGsLcYXpaGd9xt6FxhdN/T2Ge2uEMhBlC2ZbfmGD08idpsHa96+E+N+WLJ3NJHTZp1p3kn4um7LndIs0S2mzXr5vG2Uz9aKwb4Er6VAN5etnBPkN1yRiK9s0cGLjqyqhmzZclL5dKumx67qcWtqMqsANTP6zdf8cUYe7hm5uBLfNUbWKGnoH6RkndtA0YZJudIR4vdjJfoSrETrYiWqR9z1sVJZa8DdPSTlzlZhyw4V3iScvSLh1l6FLXvr+sWQlhB/J+oD5Dbt/AEWYl+d+auGWqdRzIfn1QXzd6FgqzP/Uwu2Xr9L0V373n349cfBpjm+PespYkmT78dKl87a7K8FL6cXYKJAbnFdjWqJWDMBTCqUjE2hZOxRgijNb8+aghKMTnuUgC/pJkz2n4oSvGvYo8RLoYahBGuRPUoGshuGEtw371ECeWnrKMFD+T1KIOJtffcAD6r3KIGIt0GUeLf4xW92pFb8bhod/wM=</diagram></mxfile>

src/BasicKube.Models/IamNodeInfo.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+

2+
using System.ComponentModel;
3+
4+
namespace BasicKube.Models;
5+
public class IamNodeInfo
6+
{
7+
[DisplayName("项目")]
8+
public string Project { get; set; } = "";
9+
10+
[DisplayName("IamId")]
11+
public int IamId { get; set; }
12+
}

src/BasicKube.Web/App.razor

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
@inject AuthenticationStateProvider _authStateProvider
2-
@inject NavigationManager _navigationManager
1+
@inject NavigationManager _navigationManager
32
@inject AccountHttp _accountHttp
43
@inject AuthService _authService
54

@@ -23,15 +22,14 @@
2322
@code {
2423
private async Task OnNavigateAsync(NavigationContext args)
2524
{
25+
Console.WriteLine("OnNavigateAsync");
2626
var isAuthed = await _authService.GetIsAuthed();
27-
28-
var user = (await (_authStateProvider as IamAuthStateProvider)!.GetAuthenticationStateAsync()).User;
29-
if (isAuthed && !user!.Identity!.IsAuthenticated)
27+
if (isAuthed && !(await _authService.IsAuthenticated()))
3028
{
3129
var userProfile = await _accountHttp.GetUserProfile();
3230
if (userProfile != null)
3331
{
34-
(_authStateProvider as IamAuthStateProvider)!.SetAuthInfo(userProfile);
32+
_authService.SetUserProfile(userProfile);
3533
}
3634
else
3735
{

src/BasicKube.Web/BasicKube.Web.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageReference Include="AntDesign" />
1717
<PackageReference Include="BcdLib.BcdForm" />
1818
<PackageReference Include="Blazored.LocalStorage" />
19+
<PackageReference Include="Blazored.SessionStorage" />
1920
<PackageReference Include="IconPark.Blazor" />
2021
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
2122
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />

src/BasicKube.Web/Client/Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using BasicKube.Web.Services.Http;
44
using BasicKube.Web.Services.JsIntertop;
55
using Blazored.LocalStorage;
6+
using Blazored.SessionStorage;
67
using Microsoft.AspNetCore.Components.Authorization;
78
using Microsoft.AspNetCore.Components.Web;
89
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
@@ -34,6 +35,7 @@ public static async Task Main(string[] args)
3435
builder.Services.AddAuthorizationCore();
3536
builder.Services.AddScoped<AuthenticationStateProvider, IamAuthStateProvider>();
3637
builder.Services.AddBlazoredLocalStorage();
38+
builder.Services.AddBlazoredSessionStorage();
3739

3840
var host = builder.Build();
3941
host.Services.UseBcdForm();

src/BasicKube.Web/Components/App/Common/PodDetailsItem.razor

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
OnExpand="OnRowExpand"
99
HidePagination
1010
Size=@TableSize.Middle>
11-
<RowTemplate>
11+
<ColumnDefinitions>
1212
<PropertyColumn Property="@(c=>c!.Name)" />
1313
<PropertyColumn Property="@(c=>c!.GetStartTimeStr())" Title="StartTime" />
1414
<PropertyColumn Property="@(c=>c!.HostIp)" />
@@ -46,7 +46,7 @@
4646
</SpaceItem>
4747
</Space>
4848
</ActionColumn>
49-
</RowTemplate>
49+
</ColumnDefinitions>
5050
<ExpandTemplate Context="rowData">
5151
<Table DataSource="rowData.Data.ContainerDetails.Values.ToList()"
5252
Loading="@(rowData.Data.ContainerDetails==null)"
@@ -74,20 +74,20 @@
7474
</ExpandTemplate>
7575
</Table>
7676

77-
<Drawer Width="800" Closable="true" Visible="visible" Placement="right" Title='("Basic Drawer")' OnClose="_=>close()">
77+
<Drawer Width="800" Closable="true" Visible="visible" Placement="right" Title='("Events")' OnClose="_=>close()">
7878
<Table Class="pods-events"
7979
DataSource="@_events"
8080
TItem="EventInfo"
8181
HidePagination
8282
Size=@TableSize.Middle
8383
Loading=@(_events.Count == 0)>
84-
<RowTemplate>
84+
<ColumnDefinitions>
8585
<PropertyColumn Property="@(c=>c!.GetDateTimeStr())" Title="EventTime"/>
8686
<PropertyColumn Property="@(c=>c!.Type)" />
8787
<PropertyColumn Property="@(c=>c!.Reason)" />
8888
<PropertyColumn Property="@(c=>c!.Source)" />
8989
<PropertyColumn Property="@(c=>c!.Message)" />
90-
</RowTemplate>
90+
</ColumnDefinitions>
9191
</Table>
9292
</Drawer>
9393

src/BasicKube.Web/Components/Base/IamPage.cs

-21
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,6 @@ namespace BasicKube;
66

77
public class IamPage : ComponentBase
88
{
9-
[Inject]
10-
public AuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!;
11-
129
[Parameter]
1310
public int IamId { get; set; }
14-
15-
protected override async Task OnParametersSetAsync()
16-
{
17-
var authState = await AuthenticationStateProvider
18-
.GetAuthenticationStateAsync();
19-
var user = authState.User;
20-
21-
//if (user.Identity is not null && user.Identity.IsAuthenticated)
22-
//{
23-
// authMessage = $"{user.Identity.Name} is authenticated.";
24-
// claims = user.Claims;
25-
// surname = user.FindFirst(c => c.Type == ClaimTypes.Surname)?.Value;
26-
//}
27-
//else
28-
//{
29-
// authMessage = "The user is NOT authenticated.";
30-
//}
31-
}
3211
}

0 commit comments

Comments
 (0)