我的广告连播处于“CrashloopBackOff” 的状态,设置为Jenkins with Kubernetes on GCP。
我发现了一些answers where it indicates that my Dockerfile is not good and that it needs to be in an infinite state。
但是我在production.yaml中运行命令 [“sh”,“-c”,“app -port = 8080”] 以使其处于该状态。
使用完全相同的 Dockerfile ,当我将项目手动部署到kubernetes时,它可以正常工作。
我要提交的项目如下所示:
Dockerfile
FROM php:7.2.4-apache
COPY apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
COPY src /var/www/html/src
COPY public /var/www/html/public
COPY config /var/www/html/config
ADD composer.json /var/www/html
ADD composer.lock /var/www/html
# Install software
RUN apt-get update && apt-get install -y git
# Install unzip
RUN apt-get install -y unzip
# Install curl
RUN apt-get install -y curl
# Install dependencies
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN cd /var/www/html && composer install --no-dev --no-interaction --optimize-autoloader
# install pdo for mysql
RUN docker-php-ext-install pdo pdo_mysql
COPY "memory-limit-php.ini" "/usr/local/etc/php/conf.d/memory-limit-php.ini"
RUN chmod 777 -R /var/www
# Production envivorment
ENV ENVIVORMENT=prod
EXPOSE 80
CMD apachectl -D FOREGROUND
CMD ["app"]
Jenkins文件
def project = '****'
def appName = 'wobbl-mobile-backend'
def imageTag = "gcr.io/${project}/${appName}"
def feSvcName = "wobbl-main-backend-service"
pipeline {
agent {
kubernetes {
label 'sample-app'
defaultContainer 'jnlp'
yamlFile 'k8s/pod/pod.yaml'
}
}
stages {
// Deploy Image and push with image container builder
stage('Build and push image with Container Builder') {
steps {
container('gcloud') {
sh "PYTHONUNBUFFERED=1 gcloud container builds submit -t ${imageTag} ."
}
}
}
// Deploy to production
stage('Deploy Production') {
// Production branch
steps{
container('kubectl') {
// Change deployed image in canary to the one we just built
sh("sed -i.bak 's#gcr.io/cloud-solutions-images/wobbl-main:1.0.0#${imageTag}#' ./k8s/production/*.yaml")
sh("kubectl --namespace=production apply -f k8s/services/")
sh("kubectl --namespace=production apply -f k8s/production/")
sh("echo http://`kubectl --namespace=production get service/${feSvcName} -o jsonpath='{.status.loadBalancer.ingress[0].ip}'` > ${feSvcName}")
}
}
}
}
}
比yaml kubernetes配置:
pod.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
component: ci
spec:
# Use service account that can deploy to all namespaces
serviceAccountName: default
containers:
- name: gcloud
image: gcr.io/cloud-builders/gcloud
command:
- cat
tty: true
- name: kubectl
image: gcr.io/cloud-builders/kubectl
command:
- cat
tty: true
该服务使用了 backend.yaml
kind: Service
apiVersion: v1
metadata:
name: wobbl-main-backend-service
spec:
ports:
- name: http
port: 8080
targetPort: 8080
protocol: TCP
selector:
role: backend
app: wobbl-main
部署 production.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: wobbl-main-backend-production
spec:
replicas: 1
template:
metadata:
name: backend
labels:
app: wobbl-main
role: backend
env: production
spec:
containers:
- name: backend
image: gcr.io/cloud-solutions-images/wobbl-main:1.0.0
resources:
limits:
memory: "500Mi"
cpu: "100m"
imagePullPolicy: Always
readinessProbe:
httpGet:
path: /healthz
port: 8080
command: ["sh", "-c", "app -port=8080"]
ports:
- name: backend
containerPort: 8080
当我运行kubernetes描述pod **** -n production时,我得到以下响应:
Normal Created 3m (x4 over 4m) kubelet, gke-jenkins-cd-default-pool-83e2f18e-hvwp Created container Normal Started 3m (x4 over 4m) kubelet, gke-jenkins-cd-default-pool-83e2f18e-hvwp Started container Warning BackOff 2m (x8 over 4m) kubelet, gke-jenkins-cd-default-pool-83e2f18e-hvwp Back-off restarting failed container
关于如何调试的任何提示?
最佳答案
首先,您的Docker文件说:
CMD ["app"]
然后在您的部署定义中,您可以:
command: ["sh", "-c", "app -port=8080"]
这是重复。我建议您使用其中之一。
其次,我假设
install
命令之一为您提供了app
二进制文件。确保它是您的$PATH
的一部分另外,您还有一个Pod和一个部署 list 。我希望您正在使用其中之一,并且不要同时部署两者。
关于docker - Kubernetes中Pod上的CrashloopBackOff(在具有Jenkins的GCP上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53009045/