我正在尝试将Spinnaker部署到Kubernetes集群中。为此,我 使用使用Helm的Halyard。 在尝试运行Helm Pod时,我将显示以下输出:
this.httpClient.get(environment.apiUrl + this.config.getSettings()['cleard']['api']['user']['distribution-zone'], { headers: new HttpHeaders({ 'Authorization': 'BEARER ' + this.auth.getUserSession().access_token })}).subscribe( (arrayDistributionZoneResult: Array<DistributionZoneResult>) => {
console.log(environment.apiUrl);
console.log('unfiltered distribution zone result : ' + arrayDistributionZoneResult.length);
for (const obj of arrayDistributionZoneResult) {
this.distributionZone.push(obj.distributionZoneId);
// console.log('arrayDistribZone : ' + obj.distributionZoneId);
}
const distinct = (value, index , self) => {
return self.indexOf(value) === index;
};
this.distributionZone = this.distributionZone.filter(distinct);
console.log('filtered distribution zone result : ' + this.distributionZone.length);
console.log('filtered distribution zone result : ' + this.distributionZone);
});
一切似乎正确。但是我的pod引发了一个 CrashLoopBackOff 事件,没有任何其他错误,并且我的pod毫无明显原因地重新启动。
我用来构建掌舵docker映像的dockerfile如下:
Cluster "default" set.
Context "default" created.
User "user" set.
Context "default" modified.
Switched to context "default".
Creating /home/spinnaker/.helm
Creating /home/spinnaker/.helm/repository
Creating /home/spinnaker/.helm/repository/cache
Creating /home/spinnaker/.helm/repository/local
Creating /home/spinnaker/.helm/plugins
Creating /home/spinnaker/.helm/starters
Creating /home/spinnaker/.helm/cache/archive
Creating /home/spinnaker/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /home/spinnaker/.helm.
Tiller (the Helm server-side component) has been upgraded to the current version.
Happy Helming!
这是 halyard-configure.sh shell脚本的内容:
FROM gcr.io/spinnaker-marketplace/halyard:stable
ARG GCP_SPINNAKER_GCR_KEY
# install helm
WORKDIR /home/spinnaker
# get helm
RUN curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
RUN sed -i 's/\/usr\/local\/bin/\/home\/spinnaker/g' get_helm.sh
# sudo user workaround
RUN sed -i 's/sudo //g' get_helm.sh
RUN chmod u+x get_helm.sh
# add the current folder to the path
ENV PATH="/home/spinnaker:${PATH}"
# install helm
RUN ./get_helm.sh
# importing the configuration script
ADD shell/halyard-configure.sh .
# auhtorize the spinnaker user to execute the configuration script
USER root
RUN chown -R spinnaker halyard-configure.sh
USER spinnaker
# create the gcp key directory for docker registry
RUN mkdir -p ~/.gcp
RUN echo $GCP_SPINNAKER_GCR_KEY | base64 -d > ~/.gcp/gcr-account.json
ENTRYPOINT [ "./halyard-configure.sh" ]
CMD "/opt/halyard/bin/halyard"
答案 0 :(得分:1)
您的入口点脚本需要以魔术行exec "$@"
结尾。
通常在Docker中,容器启动会启动容器入口点,并将命令作为参数传递给它。 (Kubernetes pod规范将这些部分称为“命令”和“参数”。)入口点完成后,容器退出。由于您的入口点脚本只运行kubectl config
和helm init
命令,这些命令都会迅速完成,因此容器几乎立即退出;当它这样做时,Kubernetes重新启动它;并且必须重新启动两次或三遍以上时,它会进入CrashLoopBackOff
状态。
解决此问题的通常方法是设置入口点脚本以进行任何必需的首次设置,然后exec
作为参数传递给它的命令。然后,该命令(在您的情况下为/opt/halyard/bin/halyard
)成为“主容器进程”,并且具有魔术进程ID 1,并且将在容器终止时接收信号。
还要注意,有一个合理的标准pattern for accessing the Kubernetes API from a pod涉及为Pod配置服务帐户并使用官方API,或者启动kubectl proxy
辅助工具。您可能可以使用它来代替此处的手动设置步骤。 (不过,我从未尝试从Kubernetes容器内部启动Helm。)