[英]How to start docker container with dynamic url
My requirement is as follows:我的要求如下:
For this purpose I was reading this https://medium.com/swlh/ci-cd-pipeline-using-jenkins-dynamic-nodes-86ea854ff7a7 but I am not sure how to achive step #5.为此,我正在阅读此https://medium.com/swlh/ci-cd-pipeline-using-jenkins-dynamic-nodes-86ea854ff7a7但我不确定如何完成步骤 5。 Can you please advice how to achive this autometically?
您能否建议如何自动实现这一目标?
Reformatting answers from commentaries, having a Jenkins installation and Kubernetes cluster, you may automate your deployments using a Jenkins plugin such as oc
or kubernetes
, or you could prefer using the kubectl
client directly, assuming your agents do have that binary. Reformatting answers from commentaries, having a Jenkins installation and Kubernetes cluster, you may automate your deployments using a Jenkins plugin such as
oc
or kubernetes
, or you could prefer using the kubectl
client directly, assuming your agents do have that binary.
Not going through the RBAC specifics, you would probably need a ServiceAccount for Jenkins, and use a token (can be found in a Secret named after your ServiceAccount).不了解 RBAC 细节,您可能需要 Jenkins 的 ServiceAccount,并使用令牌(可以在以您的 ServiceAccount 命名的 Secret 中找到)。 That ServiceAccount should have enough privileges to create resources in the namespaces you intend to deploy stuff into -- usually the
edit
ClusterRole, with a namespace-scoped RoleBinding:该 ServiceAccount 应该有足够的权限在您打算将内容部署到的命名空间中创建资源——通常是
edit
ClusterRole,具有命名空间范围的 RoleBinding:
kubectl create sa jenkins -n my-namespace
kubectl create rolebinding jenkins-edit \
--clusterrole=edit \
--serviceaccount=my-namespace:jenkins-edit \
--namespace=my-namespace
Once Jenkins is done building your image, you would deploy it to Kubernetes, most likely creating a Deployment, a Service, and an Ingress, substituting resource names, namespaces and your ingress requested FQDN to match your requirements.一旦 Jenkins 完成构建您的映像,您将其部署到 Kubernetes,最有可能创建部署、服务和入口,替换资源名称、命名空间和入口请求的 FQDN 以匹配您的要求。
Prepare your deployment yaml, something like:准备部署 yaml,类似于:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-BRANCH
spec:
selector:
matchLabels:
name: app-BRANCH
template:
spec:
containers:
- image: my-registry/path/to/image:BRANCH
[...]
---
apiVersion: v1
kind: Service
metadata:
name: app-BRANCH
spec:
selector:
name: app-BRANCH
ports:
[...]
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: app-BRANCH
spec:
rules:
- host: app-BRANCH.my-base-domain.com
http:
paths:
- backend:
serviceName: app-BRANCH
Then, have your Jenkins agent apply that configuration, substituting values properly:然后,让您的 Jenkins 代理应用该配置,并正确替换值:
sed "s|BRANCH|$BRANCH|" deploy.yaml | kubectl apply -n my-namespace -f-
kubectl wait -n my-namespace deploy/app-$BRANCH --for=condition=Available
kubectl logs -n my-namespace deploy/app-$BRANCH --tail=200
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.