以ceilometer-api为例,介绍调试的整个过程
将直接启动容器的方式改为不启动,自己进入容器后手动执行命令启动容器
以ceilometer-api为例,修改ceilometer-api这个deployment,具体执行如下命令:
先备份ceilometer-api这个deployment,即执行如下命令:
kubectl get deploy -n openstack ceilometer-api -oyaml > ceilometer-api.yaml
然后修改ceilomeyer-api的启动方式:
kubectl edit deploy -n openstack ceilometer-api
可以看到如下内容:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "6"
creationTimestamp: 2019-01-10T14:05:15Z
generation: 6
labels:
application: ceilometer
component: api
release_group: ceilometer
name: ceilometer-api
namespace: openstack
resourceVersion: "3704244"
selfLink: /apis/extensions/v1beta1/namespaces/openstack/deployments/ceilometer-api
uid: c13d6a4c-14e0-11e9-8623-fa163edc2997
spec:
progressDeadlineSeconds: 600
replicas: 3
revisionHistoryLimit: 3
selector:
matchLabels:
application: ceilometer
component: api
release_group: ceilometer
strategy:
rollingUpdate:
maxSurge: 3
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
annotations:
configmap-bin-hash: d2eb483473276e7aab27e7b639c4edc3bb0e60125f67b8fbe4b90c149e9744f1
configmap-etc-hash: f3303568db665b281aaf92fe22b55282ade57ffe0e5e61784e73c27ff38222d0
creationTimestamp: null
labels:
application: ceilometer
component: api
release_group: ceilometer
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: release_group
operator: In
values:
- ceilometer
- key: application
operator: In
values:
- ceilometer
- key: component
operator: In
values:
- api
topologyKey: kubernetes.io/hostname
containers:
- command:
- /tmp/ceilometer-api.sh
- start
image: hub.easystack.io/production/escloud-linux-source-ceilometer-api:5.0.1-3-beta82
imagePullPolicy: IfNotPresent
lifecycle:
preStop:
exec:
command:
- /tmp/ceilometer-api.sh
- stop
name: ceilometer-api
ports:
- containerPort: 8777
name: ce-api
protocol: TCP
readinessProbe:
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8777
timeoutSeconds: 1
resources:
limits:
cpu: "2"
memory: 1Gi
requests:
cpu: 100m
memory: 124Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /etc/ceilometer
name: pod-etc-ceilometer
- mountPath: /etc/ceilometer/ceilometer.conf
name: ceilometer-etc
readOnly: true
subPath: ceilometer.conf
- mountPath: /etc/ceilometer/api_paste.ini
name: ceilometer-etc
readOnly: true
subPath: api_paste.ini
- mountPath: /etc/ceilometer/policy.json
name: ceilometer-etc
readOnly: true
subPath: policy.json
- mountPath: /etc/ceilometer/event_definitions.yaml
name: ceilometer-etc
readOnly: true
subPath: event_definitions.yaml
- mountPath: /etc/ceilometer/event_pipeline.yaml
name: ceilometer-etc
readOnly: true
subPath: event_pipeline.yaml
- mountPath: /etc/ceilometer/pipeline.yaml
name: ceilometer-etc
readOnly: true
subPath: pipeline.yaml
- mountPath: /etc/ceilometer/gnocchi_resources.yaml
name: ceilometer-etc
readOnly: true
subPath: gnocchi_resources.yaml
- mountPath: /etc/httpd/conf.d/wsgi-ceilometer.conf
name: ceilometer-etc
readOnly: true
subPath: wsgi-ceilometer.conf
- mountPath: /etc/ceilometer/mapping.json
name: ceilometer-etc
readOnly: true
subPath: mapping.json
- mountPath: /tmp/ceilometer-api.sh
name: ceilometer-bin
readOnly: true
subPath: ceilometer-api.sh
dnsPolicy: ClusterFirst
initContainers:
- command:
- kubernetes-entrypoint
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: INTERFACE_NAME
value: eth0
- name: DEPENDENCY_SERVICE
value: openstack:keystone-api,openstack:mariadb,openstack:mongodb
- name: DEPENDENCY_JOBS
value: ceilometer-db-init-mongodb,ceilometer-db-sync,ceilometer-ks-user,ceilometer-ks-endpoints
- name: DEPENDENCY_DAEMONSET
- name: DEPENDENCY_CONTAINER
- name: COMMAND
value: echo done
image: hub.easystack.io/production/kubernetes-entrypoint:v0.2.1
imagePullPolicy: IfNotPresent
name: init
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
nodeSelector:
openstack-control-plane: enabled
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 600
volumes:
- emptyDir: {}
name: pod-etc-ceilometer
- configMap:
defaultMode: 292
name: ceilometer-etc
name: ceilometer-etc
- configMap:
defaultMode: 365
name: ceilometer-bin
name: ceilometer-bin
status:
availableReplicas: 3
conditions:
- lastTransitionTime: 2019-01-21T06:56:00Z
lastUpdateTime: 2019-01-21T06:56:00Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: 2019-01-10T14:21:48Z
lastUpdateTime: 2019-01-22T04:34:58Z
message: ReplicaSet "ceilometer-api-546b888f69" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 6
readyReplicas: 3
replicas: 3
updatedReplicas: 3
找到command这一行的内容,具体如下:
containers:
- command:
- /tmp/ceilometer-api.sh
- start
image: hub.easystack.io/production/escloud-linux-source-ceilometer-api:5.0.1-3-beta82
修改为:
containers:
- command:
- sleep
- 3d
image: hub.easystack.io/production/escloud-linux-source-ceilometer-api:5.0.1-3-beta82
即将容器的启动命令,从
- /tmp/ceilometer-api.sh
- start
修改为:
- sleep
- 3d
表示容器启动时会执行: sleep 3d这个休眠3天的命令,这样就表示容器启动后不会开启ceilometer-api服务
kubectl cp
注意:
请将
请将
请将
请将 /root 替换为需要调试的源码位置,通常是: /usr/lib/python2.7/site-packages 下面待调试的python项目中对应位置的文件所在目录
以ceilometer-api为例,进入ceilometer-api这个pod
即执行如下命令:
kubectl exec -it -n
请将:
然后进入到步骤2刚才拷贝的待调试源码所在位置,找到拷贝到容器中需要调试的python文件,
在待调试位置加上:
import pdb;pdb.set_trace()
即可
找到原先容器启动命令执行的脚本
以ceilometer-api为例,
根据步骤1中原先ceilometer-api容器中启动的脚本命令是:
- /tmp/ceilometer-api.sh
- start
因此,可以确认启动容器的脚本文件为:
/tmp/ceilometer-api.sh
查看该脚本文件内容如下:
cat /tmp/ceilometer-api.sh
结果如下:
#!/usr/local/bin/dumb-init /bin/bash
set -ex
COMMAND="${@:-start}"
function start () {
exec httpd -DFOREGROUND
}
function stop () {
# apachectl -k graceful-stop
kill -TERM 1
}
$COMMAND
本来可以直接用这个命令: exec httpd -DFOREGROUND
开启调试,由于这个开启针对ceilometer-api是以wsgi方式执行,不好调试,因此可以用
下面的方式调试:
由于ceilometer-api可以通过手动开启,即执行如下命令:
ceilometer-api --port 8777
容器中的服务被手动启动后,进入到自己刚才设置的断点处,此时即可进行调试