argocd
官网: https://argo-cd.readthedocs.io/en/stable/#getting-started
整体发布流程如图所示 用户提交 应用发布文件(k8s manifest yaml / helm / kustomize 等)到 git 仓库(gitlab/github 等) argocd 监听 git 仓库的文件变化,根据配置手动或者自动把应用发布文件同步变更到 k8s 集群中
创建名称空间,下载yaml文件
kubectl create ns argo
//在安装yaml文件的目录下,执行
kubectl apply -n argo -f .
本地访问Argocd
我们将 argo-ui 改成 NodePort 类型的 Service(当然也可以创建 Ingress 对象通过域名进行访问、port_forward等方式)
[10:28:21] yang :: lucky ? ~ ? kubectl edit svc -n argocd argocd-server -oyaml
apiVersion: v1
kind: Service
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"server","app.kubernetes.io/name":"argocd-server","app.kubernetes.io/part-of":"argocd"},"name":"argocd-server","namespace":"argocd"},"spec":{"ports":[{"name":"http","port":80,"protocol":"TCP","targetPort":8080},{"name":"https","port":443,"protocol":"TCP","targetPort":8080}],"selector":{"app.kubernetes.io/name":"argocd-server"}}}
creationTimestamp: "2022-04-25T02:17:13Z"
labels:
app.kubernetes.io/component: server
app.kubernetes.io/name: argocd-server
app.kubernetes.io/part-of: argocd
name: argocd-server
namespace: argocd
resourceVersion: "165890"
uid: f0adb693-08f3-43c8-86c0-e047959d037b
spec:
clusterIP: 10.109.64.172
clusterIPs:
- 10.109.64.172
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
nodePort: 32337
port: 80
protocol: TCP
targetPort: 8080
- name: https
nodePort: 30069
port: 443
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/name: argocd-server
sessionAffinity: None
type: NodePort
status:
loadBalancer: {}
[10:37:30] yang :: lucky ? ~ ? kubectl get svc -n argocd argocd-server
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
argocd-server NodePort 10.109.64.172 <none> 80:32337/TCP,443:30069/TCP 25m
在浏览器访问 http://127.0.0.1:30069
// 查看 argocd 默认密码(argocd 1.9 以后的版本,参考:https://argoproj.github.io/argo-cd/faq/
pVLydNUWOOwiSxJm
// 更改 admin 密码
// 先到 https://www.browserling.com/tools/bcrypt 生成 bcrypt 字符串,比如 123456 就是 $2a$10$O8NqwiyZY0Yl8LyteZyJf.4XYBIFBlUHT0kmFR9jrs1a1HwDgyAFK
// 替换为下面的 admin.password 的值
kubectl -n argocd patch secret argocd-secret \
-p '{"stringData": {
"admin.password": "$2a$10$O8NqwiyZY0Yl8LyteZyJf.4XYBIFBlUHT0kmFR9jrs1a1HwDgyAFK",
"admin.passwordMtime": "'$(date +%FT%T%Z)'"
}}'
访问 argocd web 页面,输入账号 admin 和 密码 123456 就可以登录了
怎么部署服务
添加代码仓库
https://gitee.com/why777/py-k8s
添加project
发布成功后的状态 在页面上可以看到各个资源的状态、配置、以及关联关系
能看pod日志,事件,yaml等,算是一个简单版本的k8s dashboard
其他
如果项目有 configmap、ingress 等其他资源也是差不多的发布流程
容器镜像要提前通过 CI 流程打包到镜像仓库,发布时更改对应项目 git 仓库里 deployment 的 image 版本即可
参考: https://argo-cd.readthedocs.io/en/stable/getting_started/ https://www.jianshu.com/p/3e9ca0c2668b https://www.kancloud.cn/willseecloud/jenkins/2424038 https://kubeoperator.io/docs/user_manual/argocd/
|