k8s 容器启动后执行命令
apiVersion: apps/v1kind: StatefulSetmetadata:labels:app: hive-metastorename: hive-metastorespec:replicas: 1selector:matchLabels:app: hive-metastoreserviceName: "hive-metastore"template:metadata:labels
·
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: hive-metastore
name: hive-metastore
spec:
replicas: 1
selector:
matchLabels:
app: hive-metastore
serviceName: "hive-metastore"
template:
metadata:
labels:
app: hive-metastore
spec:
containers:
- image: docker-registry-node:5000/hive-mysql-metastore:v1
name: hive-metastore
ports:
- containerPort: 9083
### 启动后执行命令
lifecycle:
postStart:
exec:
command: ["/bin/bash", "-c", "/opt/hive/bin/hive --service metastore &"]
env:
- name: "TZ"
value: "Asia/Shanghai"
- name: "SERVICE_PRECONDITION"
value: "hadoop-hdfs-master:50070 mysql-svc:3306"
# kubectl explain StatefulSet.spec.template.spec.containers.lifecycle
KIND: StatefulSet
VERSION: apps/v1
RESOURCE: lifecycle <Object>
DESCRIPTION:
Actions that the management system should take in response to container
lifecycle events. Cannot be updated.
Lifecycle describes actions that the management system should take in
response to container lifecycle events. For the PostStart and PreStop
lifecycle handlers, management of the container blocks until the action is
complete, unless the container process fails, in which case the handler is
aborted.
FIELDS:
postStart <Object>
PostStart is called immediately after a container is created. If the
handler fails, the container is terminated and restarted according to its
restart policy. Other management of the container blocks until the hook
completes. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
preStop <Object>
PreStop is called immediately before a container is terminated due to an
API request or management event such as liveness/startup probe failure,
preemption, resource contention, etc. The handler is not called if the
container crashes or exits. The reason for termination is passed to the
handler. The Pod's termination grace period countdown begins before the
PreStop hooked is executed. Regardless of the outcome of the handler, the
container will eventually terminate within the Pod's termination grace
period. Other management of the container blocks until the hook completes
or until the termination grace period is reached. More info:
https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
-bash-4.2#
更多推荐
已为社区贡献65条内容
所有评论(0)