实践环境升级基于K8s和ArgoCD
本文是第七期DevOps训练营,开营环境准备内容。通过terraform+kind进行本地测试环境Kubernetes集群部署,部署ArgoCD来对后续DevOps工具进行交付。
跟着做,第一次配置20-30分钟左右,后续3分钟启动一个Kubernetes不成问题。第七期训练营正在进行中,如果有兴趣可以扫码了解详情!
实验环境类型= 操作系统:CentOS8 Linux ,内存资源:32GB+
工具名称 | Version | 描述信息 |
---|---|---|
Terraform | 1.1.7 | 使用kind provider操作kind |
Kind | 0.14.0 | 创建Kubernetes集群工具 |
Docker-CE | 1.19+ (Docker version 23.0.3, build 3e7cbfd) | 容器运行时 |
kubectl | version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.0 | |
Kubernetes | 1.24.0 | 容器云环境 |
ArgoCD | 2.6.7 | 云原生应用持续部署工具 |
NFS | 存储系统,持久化存储容器数据 |
基础设施代码库:https://jihulab.com/devopsvip/myiac kubernetes官方文档:https://kubernetes.io/docs/concepts/
常见问题:
下载链接:https://developer.hashicorp.com/terraform/downloads?product_intent=terraform 课程中使用1.1.8版本:https://releases.hashicorp.com/terraform/1.1.7/terraform_1.1.7_linux_amd64.zip
$: unzip terraform_1.1.7_darwin_amd64.zip
Archive: terraform_1.1.7_darwin_amd64.zip
inflating: terraform
# ls
install.md terraform_1.1.7_darwin_amd64.zip
terraform
# mv terraform /usr/local/bin
# terraform version
wget https://github.com/kubernetes-sigs/kind/releases/download/v0.14.0/kind-linux-amd64
mv kind-linux-amd64 /usr/bin/kind
chmod +x /usr/bin/kind
kind官网: https://kind.sigs.k8s.io/docs/user/configuration/#getting-started kind download: https://github.com/kubernetes-sigs/kind/releases/
https://kubernetes.io/docs/tasks/tools/#kubectl
需要用到的docker images 【提前pull下来】:
下载代码库
git clone https://jihulab.com/devopsvip/myiac.git
Terraform初始化和发布
# install
cd k8s
terraform init
terraform apply --auto-approve
# uninstall
terraform destroy --auto-approve
等待Terraform发布成功后,检查集群状态。
kubectl get node
NAME STATUS ROLES AGE VERSION
devopscluster-control-plane Ready control-plane 2m53s v1.24.0
devopscluster-worker Ready <none> 2m19s v1.24.0
test-cluster-worker2 Ready <none> 2m20s v1.24.0
ingress-nginx
[root@zeyang-nuc-service k8s]# kubectl get pod -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-fbh5n 0/1 Completed 0 5m41s
ingress-nginx-admission-patch-xttkh 0/1 Completed 0 5m41s
ingress-nginx-controller-7bd87766fb-lsv89 1/1 Running 0 5m41s
添加Hosts, 访问https://argocd.idevops.site
192.168.1.200 argocd.idevops.site
image.png
# GetDockerImage
docker pull ccr.ccs.tencentyun.com/argocds/dex:v2.35.3
docker pull ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine
docker pull ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7
# TagDockerImage
docker tag ccr.ccs.tencentyun.com/argocds/dex:v2.35.3 ghcr.io/dexidp/dex:v2.35.3
docker tag ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7 quay.io/argoproj/argocd:v2.6.7
docker tag ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine redis:7.0.8-alpine
# From local to Kind K8s Cluster
images=`grep image: install.yaml | awk -F 'image: ' '{print $NF}' | sort -n | uniq`
for image in $images
do
kind load docker-image $image --name devopscluster
done
# Install argocd
kubectl create ns argocd
kubectl -n argocd apply -f install.yaml
kubectl -n argocd apply -f ingress.yaml
sleep 3
kubectl -n argocd get pod
kubectl -n argocd get secret
sleep 5
# Get password
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d ; echo
pod
[root@devops-nuc-service argocd]# kubectl -n argocd get pod
NAME READY STATUS RESTARTS AGE
argocd-application-controller-0 1/1 Running 0 7m25s
argocd-applicationset-controller-56bcd8d9c5-8jwq5 1/1 Running 0 7m25s
argocd-dex-server-5c7956f67-zthlg 1/1 Running 0 7m25s
argocd-notifications-controller-d9849775f-vwbn2 1/1 Running 0 7m25s
argocd-redis-6489dcbcd5-kbjhj 1/1 Running 0 7m25s
argocd-repo-server-6c68b85655-s8gkz 1/1 Running 0 7m25s
argocd-server-747b8c84bd-5b9r4 1/1 Running 0 7m25s
更多精彩
往期推荐
全国软件开发项目管理会议交流︱2023第十二届中国PMO大会将于8月在京召开