Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheAshwanik/d1d82fd7eea747849259d01e51e8a216 to your computer and use it in GitHub Desktop.
Save TheAshwanik/d1d82fd7eea747849259d01e51e8a216 to your computer and use it in GitHub Desktop.
Code for Inject an Executable Script into a Container in Kubernetes http://blog.phymata.com/2017/07/29/inject-an-executable-script-into-a-container-in-kubernetes/
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ghost
labels:
role: blog
spec:
replicas: 1
template:
metadata:
labels:
role: blog
annotations:
pod.beta.kubernetes.io/init-containers: '[
{
"name": "init-ghost",
"image": "alpine:3.6",
"command": ["sh", "-c", "chmod u+x /scripts/..data/wrapper.sh"],
"volumeMounts": [{"name": "wrapper", "mountPath": "/scripts"}]
}
]'
spec:
containers:
- name: ghost
image: ghost:0.11-alpine
command: ["/scripts/wrapper.sh"]
ports:
- name: ghost
containerPort: 2368
protocol: TCP
volumeMounts:
- name: wrapper
mountPath: /scripts
volumes:
- name: wrapper
configMap:
name: wrapper
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ghost
labels:
app: ghost
spec:
replicas: 1
template:
metadata:
labels:
app: ghost
spec:
containers:
- name: ghost
image: ghost:0.11-alpine
ports:
- name: ghost
containerPort: 2368
protocol: TCP
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ghost
labels:
role: blog
spec:
replicas: 1
template:
metadata:
labels:
role: blog
spec:
containers:
- name: ghost
image: ghost:0.11-alpine
command: ["/scripts/wrapper.sh"]
ports:
- name: ghost
containerPort: 2368
protocol: TCP
volumeMounts:
- name: wrapper
mountPath: /scripts
volumes:
- name: wrapper
configMap:
name: wrapper
defaultMode: 0744
$ minikube start
Starting local Kubernetes v1.7.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Starting cluster components...
Connecting to cluster...
Setting up kubeconfig...
Kubectl is now configured to use the cluster.
$ git clone https://gist.github.com/82c039843663de7e7f1e18bf4debe5fa.git inject-exec-script
$ cd inject-exec-script
$ kubectl create configmap wrapper --from-file=wrapper.sh
configmap "wrapper" created
$ kubectl apply -f deployment.yaml
deployment "ghost" created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
ghost-3057289974-zvqm8 1/1 Running 0 30s
$ kubectl logs ghost-3057289974-zvqm8
Do my special initialization here then run the regular entrypoint
...
Ghost is running in development...
Listening on 0.0.0.0:2368
Url configured as: http://localhost:2368
Ctrl+C to shut down
#!/bin/sh
set -euo pipefail
echo "Do my special initialization here then run the regular entrypoint"
exec docker-entrypoint.sh npm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment