在这篇博客中,我们将通过使用ReplicaSet在Kubernetes(K8s)中部署Keptn的步骤,快速了解在Kubernetes(K8s)中使用Replica Set部署Keptn!所以,让我们深入了解一下 🙂
什么是Keptn?
Keptn是一个开源的控制平面,用于构建云原生的、行业驱动的持续交付系统。根据Dynatrace的说法,Keptn增强了任何标准的Kubernetes集群,以支持基于自动化质量门和自愈运营工作流程的交付。
现在让我们使用ReplicaSet在Kubernetes(K8s)中部署Keptn。
前提条件
要在Kubernetes中部署Keptn,我们需要以下条件:
- 关于Kubernetes和副本集的基本知识。
- 关于yaml文件的基本知识。
- 复制集和复制控制器之间的区别。
代码块
在你的yaml文件中复制复制集的代码并保存为keptn-rs.yaml。
apiVersion: apps/v1
kind: ReplicaSet
metadata:
#contains 2 things object name and label
name: keptn-rs
spec:
#contains no. of replicas and pods spec
replicas: 3
selector:
matchLabels:
app: keptn-app
template:
#pods spec
metadata:
name: keptn-pod
labels:
app: keptn-app
spec:
containers:
- name: keptn-container
image: gardnera/thekindkeptn:0.0.15
ports:
- containerPort: 80
这里我们要创建一个复制控制器,规格如下。
- 复制集的元数据:keptn-rs
- keptn pods的复制:3
- 容器名称:keptn-container
- Keptn镜像: gardnera/thekindkeptn:0.0.15
- 运行的端口:80
默认情况下,只有3个Keptn的pod会在节点上运行。要增加或减少pod的数量,请使用下面的命令。
代码实现
- Deploy keptn rs with (default 3 replicas) following command.
kubectl create -f keptn-rs.yaml
- Get output of running pods using this command.
kubectl get po -o wide
- Scale Up / Scale Down the pods using this command.
kubectl scale rs keptn-rs --replicas=5
kubectl scale rs keptn-rs --replicas=1
- Delete keptn-rs after deployment
kubectl delete -f keptn-rs.yaml
趣味部分 🙂
如果你不想执行上述步骤,我为你制作了一个脚本,可以做到这一点 🙂
echo "Please enter the number of pods you want to deploy for Keptn"
read count
echo $count
#Start keptn: with 3 nodes
kubectl create -f keptn-rs.yaml && kubectl scale rs keptn-rs --
replicas=$count
#Check output:
kubectl get po -o wide
echo
while true; do
read -p "Do you want to scalup Pods? [y for Yes ; n for No ; q for
Quit] " yn
echo ""
case $yn in
[Yy]* ) echo "Enter number of pods to scale up"
read scale_count
echo "Pods scaled up to $scale_count" && kubectl scale rs keptn-rs --
replicas=$scale_count ; break;;
[Nn]* ) break ;;
[Qq]* ) exit 0;;
* ) echo "Please provide a yes or no answer."
esac
done
echo
while true; do
read -p "Do you want to scaldown Pods? [y for Yes ; n for No ; q for
Quit] " yn
echo ""
case $yn in
[Yy]* ) echo "Enter number of pods to scale down"
read scale_count
echo "Pods scaled down to $scale_count" && kubectl scale rs keptn-rs
--replicas=$scale_count ; break;;
[Nn]* ) break ;;
[Qq]* ) exit 0;;
* ) echo "Please provide a yes or no answer."
esac
done
echo
while true; do
read -p "Do you want to delete this Deployment? [y for Yes ; n for No
; q for Quit] " yn
echo ""
case $yn in
[Yy]* ) kubectl delete -f keptn-rs.yaml ; break;;
[Nn]* ) break ;;
[Qq]* ) exit 0;;
* ) echo "Please provide a yes or no answer."
esac
done
输出
用上述命令运行和扩大Keptn pods的规模。


用上面的命令运行和缩减Keptn pods。


总结
在这篇博客中,我试图介绍使用Kubernetes(K8s)部署Keptn。我已经尽力为你提供了源代码,以及为你完成所有步骤的脚本。