kubectl apply
でデプロイするコマンドを実行するPodを作成します。git
, kubectl
コマンドを実行できるDockerイメージを作成するFROM alpine:latest
# install curl, yq, git
RUN apk update
RUN apk add --no-cache curl yq git
# install kubectl
RUN apk add --no-cache --virtual=build-deps wget \
&& wget https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \
&& mv kubectl /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl \
&& apk del build-deps
ENTRYPOINT ["/usr/local/bin/kubectl"]
CMD [""]
docker build -t kubectl-alpine:${TAG} .
docker tag kubectl-alpine:${TAG} ${DOCKERHUB_USER}/kubectl-alpine:${TAG}
docker login -u ${DOCKERHUB_USER}
docker push ${DOCKERHUB_USER}/kubectl-alpine:${TAG}
apiVersion: v1
kind: Secret
metadata:
name: git-access
namespace: default
type: Opaque
data:
username: GIT_ACCOUNT_BASE64
password: GIT_ACCESS_TOKEN_BASE64
apiVersion: v1
kind: Pod
metadata:
name: busybox-date
spec:
containers:
- name: busybox
image:${DOCKERHUB_USER}/kubectl-alpine:${TAG}
env:
- name: GIT_BRANCH
value: "master"
- name: GIT_REPOSITORY
value: "github.com/sample.git"
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name:git-access
key: username
- name: SECRET_ACCESS_TOKEN
valueFrom:
secretKeyRef:
name:git-access
key: password
args:
- |
git clone -b $(GIT_BRANCH) https://$(SECRET_USERNAME):$(SECRET_ACCESS_TOKEN)@$(GIT_REPOSITORY) files
kubectl apply -f files/$(RESOURCE_PATH) -n $(NAMESPACE)