FROM fnndsc/ubuntu-python3:latest
USER root
WORKDIR /opt/app
COPY ./ /opt/app/
RUN pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple/
---
#cat configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: python-config
namespace: default
labels:
name: python
data:
app.conf: |
#基础配置
[base]
host_root = "192.168.99.1"
port = "8118"
#cat deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: python
namespace: default
labels:
name: python
spec:
replicas: 1
selector:
matchLabels:
name: python
template:
metadata:
labels:
name: python
spec:
containers:
- name: python
securityContext:
runAsNonRoot: false
runAsUser: 0
image: "harborip-python:base"
command: ["/bin/bash"]
args: ["-c", "/usr/bin/python3 /opt/app/main.py"]
volumeMounts:
- name: config
mountPath: /opt/app/conf/
ports:
- name: http
containerPort: 8118
protocol: TCP
livenessProbe:
tcpSocket:
port: 8118
initialDelaySeconds: 5
periodSeconds: 20
timeoutSeconds: 3
readinessProbe:
tcpSocket:
port: 8118
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 3
resources:
requests:
cpu: 1000m
memory: 1024Mi
limits:
cpu: 2000m
memory: 2048Mi
volumes:
- name: config
configMap:
name: python-config
---
#cat service.yaml
apiVersion: v1
kind: Service
metadata:
name: python
namespace: default
spec:
ports:
- port: 8118
targetPort: 8118
protocol: TCP
selector:
name: python
---
#cat hpa.yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: python
spec:
maxReplicas: 3
minReplicas: 1
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: python
targetCPUUtilizationPercentage: 80
kubectl apply -f ./
#cat .gitlab-ci.yml
stages:
- docker
- deploy
docker:
stage: docker
image: kaniko-executor:debug
script:
- mkdir -p /kaniko/.docker
- echo "${DOCKER_AUTH_CONFIG}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination 192.168.10.100:8080/test/${CI_PROJECT_NAME}:$CI_COMMIT_SHORT_SHA
only:
- master
deploy:
stage: deploy
image: kubectl:1.18.1
variables:
GIT_STRATEGY: none
K8S_NAME_SPACE: default
script:
- mkdir -p $HOME/.kube
- echo "$KUBERNETES_SECRET" >> "$HOME/.kube/config"
- kubectl version
- kubectl get deployments.apps -n ${K8S_NAME_SPACE}
- kubectl set image deployment/${CI_PROJECT_NAME} python=192.168.10.100:8080/test/test2:${CI_COMMIT_SHORT_SHA}
only:
- master