Skip to content

Commit

Permalink
chore: Add kubernetes deployment (#605)
Browse files Browse the repository at this point in the history
* add kubernetes deployment

* add kubernetes deployment README

* update deployment README

* update deployment yaml
  • Loading branch information
willzhang authored Sep 20, 2024
1 parent c50c19a commit f464536
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
64 changes: 64 additions & 0 deletions deploy/yamls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 快速入门指南

本指南旨在帮助您在 Kubernetes 中部署基于 `wcjiang/linux-command` 镜像的 `linux-command` 应用。该应用提供了一套 `Deployment`,并通过 `Service` 对外暴露服务端口。

## 前提条件

- 已安装并配置好的 Kubernetes 集群
- 安装并配置好的 `kubectl`,并连接至你的 Kubernetes 集群

## 安装步骤

我们将使用此存储库中的`kubectl`应用 YAML 文件,该文件将安装 `linux-command` 应用。

```bash
$ kubectl apply -f https://raw.githubusercontent.com/jaywcjlove/linux-command/master/deploy/yamls/linux-command.yaml
```

检查 `Deployment` 状态:

```bash
$ kubectl get deployments -n linux-command
NAME READY UP-TO-DATE AVAILABLE AGE
linux-command 1/1 1 1 17m
```

你可以查看 `Pod` 的状态以确保其正常运行:

```bash
$ kubectl get pods -n linux-command
NAME READY STATUS RESTARTS AGE
linux-command-fff454654-427zp 1/1 Running 0 12m
```

验证 `Service` 是否成功创建并获取暴露的端口:

```
$ kubectl get services -n linux-command
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
linux-command-service NodePort 10.96.2.225 <none> 9665:30204/TCP 18m
```

## 访问应用

通过获取 `NodePort` 的端口来访问应用。以下是获取 `NodePort` 服务信息的命令:

```
$ kubectl get svc linux-command-service -n linux-command
```

根据输出,使用 `EXTERNAL-IP:PORT` 访问服务。例如:

```
http://<Node-IP>:<NodePort>
```

## 卸载应用

如果需要删除已部署的资源,可以按以下顺序操作:

```
kubectl delete -f linux-command.yaml
```

这将会清理所有创建的 Kubernetes 资源。
50 changes: 50 additions & 0 deletions deploy/yamls/linux-command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: linux-command
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: linux-command
namespace: linux-command
labels:
app: linux-command
spec:
replicas: 1
selector:
matchLabels:
app: linux-command
template:
metadata:
labels:
app: linux-command
spec:
containers:
- name: linux-command-container
image: wcjiang/linux-command:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
resources:
requests:
cpu: "100m"
memory: "50Mi"
limits:
cpu: "100m"
memory: "50Mi"
---
apiVersion: v1
kind: Service
metadata:
name: linux-command-service
namespace: linux-command
spec:
selector:
app: linux-command
ports:
- protocol: TCP
port: 9665
targetPort: 3000
type: NodePort

0 comments on commit f464536

Please sign in to comment.