news 2026/4/20 3:18:49

flux + kubernetes + gitops + Kustomization

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
flux + kubernetes + gitops + Kustomization

# 1. 安装依赖
yum install -y git

# 2. 设置代理(根据你的环境)
export http_proxy=http://192.168.3.77:20171
export https_proxy=http://192.168.3.77:20171
export NO_PROXY=*.baidu.com,10.0.0.0/8,.cluster.local,192.168.3.0/24

# 3. 安装 flux CLI
curl -s https://fluxcd.io/install.sh | bash
source ~/.bashrc

# 4. 初始化 Git 仓库
mkdir -p /root/gitops-repo
cd /root/gitops-repo/
git init
git config --global user.name "user"
git config --global user.email "user@example.com"

# 5. 安装 Flux 到 Kubernetes
flux install

# 6. 创建目录结构
mkdir -p base overlays/dev

# 7. 编写 base 资源
cat > base/deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx:alpine
ports:
- containerPort: 80
EOF

cat > base/service.yaml << EOF
apiVersion: v1
kind: Service
metadata:
name: myapp
spec:
type: ClusterIP
ports:
- port: 80
selector:
app: myapp
EOF

cat > base/kustomization.yaml << EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources: //这里必须写resources "./overlays/dev" 不用写是应为他是监听主目录是唯一的例外
- deployment.yaml
- service.yaml
EOF

# 8. 编写 overlays/dev
cat > overlays/dev/kustomization.yaml << EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
replicas: //只会修改被resources引入的yaml
- name: myapp
count: 2
images:
- name: nginx
newTag: 1.25-alpine
EOF

# 9. 提交到 Git
git add .
git commit -m "init gitops"

# 10. 配置 SSH 密钥(本地Git认证)
ssh-keygen -t rsa -N "" -f /root/.ssh/id_rsa
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
ssh -o StrictHostKeyChecking=no root@192.168.3.243 "echo OK"

# 11. 创建 Git 源(Flux 拉取 Git)
flux create source git gitops-repo \
--url=ssh://root@192.168.3.243/root/gitops-repo \
--branch=master \
--interval=30s \
--private-key-file=/root/.ssh/id_rsa

# 12. 授予 Flux 集群权限
kubectl create clusterrolebinding flux-cluster-admin \
--clusterrole=cluster-admin \
--serviceaccount=flux-system:flux-system

# 13. 加入测试资源(带 namespace)
cat > overlays/dev/nginx-test.yaml << EOF
apiVersion: v1
kind: Pod
metadata:
namespace: default
name: nginx-test
spec:
containers:
- name: nginx
image: nginx:alpine
EOF

git add .
git commit -m "fix: add namespace"

# 14. 创建 Kustomization(自动部署)
flux create kustomization gitops-dev \
--source=gitops-repo \
--path="./overlays/dev" \
--prune=true \
--interval=30s \
--target-namespace=default

# 15. 查看最终状态
flux get all
kubectl get po

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/18 7:09:00

计算机网络知识学习助手:基于SmallThinker-3B-Preview的智能问答系统

计算机网络知识学习助手&#xff1a;基于SmallThinker-3B-Preview的智能问答系统 1. 引言&#xff1a;当学习网络知识遇到瓶颈时 学计算机网络&#xff0c;很多人都有过类似的体验&#xff1a;面对厚厚的教材&#xff0c;满篇的协议、报文格式、状态码&#xff0c;感觉每个字…

作者头像 李华
网站建设 2026/4/18 7:08:28

不止于3D地球:用Cesium PostProcessStage打造酷炫雨雪天气与高级视觉特效

超越基础地图&#xff1a;用Cesium PostProcessStage打造电影级天气特效 想象一下&#xff0c;当用户打开你的地理可视化应用时&#xff0c;迎接他们的不是单调的3D地球&#xff0c;而是一场逼真的暴风雪或细雨蒙蒙的城市景观。这种沉浸式体验正是现代数据可视化所追求的高级境…

作者头像 李华
网站建设 2026/4/18 7:30:28

Ubuntu系统FTP安装脚本之虚拟用户登录

#!/bin/bash set -eecho " 开始安装配置 vsftpd "# 1. 安装 vsftpd echo "[1/8] 安装 vsftpd..." apt-get update apt-get install -y vsftpd db5.3-util db-util# 2. 创建 FTP 根目录和用户 echo "[2/8] 创建 FTP 目录..." mkdir -p /var/ftp u…

作者头像 李华
网站建设 2026/4/19 4:52:26

LFM2.5-1.2B-Thinking-GGUF一键部署体验:对比传统源码编译部署的优势

LFM2.5-1.2B-Thinking-GGUF一键部署体验&#xff1a;对比传统源码编译部署的优势 1. 引言 还记得第一次部署大模型时的痛苦经历吗&#xff1f;下载源码、解决依赖、编译报错、配置环境...整个过程就像在玩一场没有攻略的解谜游戏。今天我们要介绍的LFM2.5-1.2B-Thinking-GGUF…

作者头像 李华