【发布时间】:2019-03-31 05:35:37
【问题描述】:
我的 pod 处于 "CrashloopBackOff" 状态,设置为 Jenkins with Kubernetes on GCP。
但我在 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 describe pod **** -n production 时,我得到以下响应:
Normal Created 3m (x4 over 4m) kubelet, gke-jenkins-cd-default-pool-83e2f18e-hvwp 创建容器 正常 开始 3m (x4 over 4m) kubelet, gke-jenkins-cd-default-pool-83e2f18e-hvwp 启动容器警告 BackOff 2m (x8 over 4m) kubelet, gke-jenkins-cd-default-pool-83e2f18e-hvwp 后退重启失败 容器
关于如何调试的任何提示?
【问题讨论】:
-
kubectl logs通常是很好的第一步;如果容器在启动时崩溃,它可能会说些什么。 -
@DavidMaze 谢谢你,我在这里得到了一些指标。我会深入挖掘,而不是让你知道。
-
@DavidMaze 我得到 'sh: 1: app: not found' 并且我还从 docker 中删除了 EXPOSE 80,因为它与生产不在同一个端口上。有什么提示吗?
标签: docker jenkins kubernetes google-cloud-platform yaml