作者 yangfu

k8s

#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-dev get pods | grep -q opp
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/opp/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q opp
if [ "$?" == "0" ];then
echo "opp service install success!"
else
echo "opp service install fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment install success!"
else
echo "opp deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/opp/opp.yaml
kubectl -n mmm-suplus-dev get svc | grep -q opp
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get svc | grep -q opp
done
kubectl -n mmm-suplus-dev get pods | grep -q opp
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get pods | grep -q opp
done
kubectl create -f /tmp/dev/opp/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q opp
if [ "$?" == "0" ];then
echo "opp service update success!"
else
echo "opp service update fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment update success!"
else
echo "opp deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: opp
namespace: mmm-suplus-dev
labels:
k8s-app: opp
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
selector:
k8s-app: opp
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: opp
namespace: mmm-suplus-dev
labels:
k8s-app: opp
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: opp
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: opp
image: 192.168.0.243:5000/mmm/opp:dev
imagePullPolicy: Always
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: ENTERPRISE_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.enterprise
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.host
- name: MYSQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.port
- name: MYSQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.user
- name: MYSQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.password
- name: MYSQL_DB_NAME
value: "opportunity_dev"
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "9"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: RUN_MODE
value: "prod"
- name: aliyun_logs_suplus
value: "stdout"
- name: aliyun_logs_access
value: "/opt/logs/app.log"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-prd get pods | grep -q opp
if [ "$?" == "1" ];then
kubectl create -f /tmp/prd/opp/opp.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q opp
if [ "$?" == "0" ];then
echo "opp service install success!"
else
echo "opp service install fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment install success!"
else
echo "opp deployment install fail!"
fi
else
kubectl delete -f /tmp/prd/opp/opp.yaml
kubectl -n mmm-suplus-prd get svc | grep -q opp
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get svc | grep -q opp
done
kubectl -n mmm-suplus-prd get pods | grep -q opp
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get pods | grep -q opp
done
kubectl create -f /tmp/prd/opp/opp.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q opp
if [ "$?" == "0" ];then
echo "opp service update success!"
else
echo "opp service update fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment update success!"
else
echo "opp deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: opp
namespace: mmm-suplus-prd
labels:
k8s-app: opp
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
selector:
k8s-app: opp
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: opp
namespace: mmm-suplus-prd
labels:
k8s-app: opp
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: opp
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: opp
image: 192.168.0.243:5000/mmm/opp:master
imagePullPolicy: Always
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: ENTERPRISE_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.enterprise
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.host
- name: MYSQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.port
- name: MYSQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.user
- name: MYSQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.password
- name: MYSQL_DB_NAME
value: "opp"
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "9"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: RUN_MODE
value: "prod"
- name: aliyun_logs_suplus
value: "stdout"
- name: aliyun_logs_access
value: "/opt/logs/app.log"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-test get pods | grep -q opp
if [ "$?" == "1" ];then
kubectl create -f /tmp/test/opp/opp.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q opp
if [ "$?" == "0" ];then
echo "opp service install success!"
else
echo "opp service install fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment install success!"
else
echo "opp deployment install fail!"
fi
else
kubectl delete -f /tmp/test/opp/opp.yaml
kubectl -n mmm-suplus-test get svc | grep -q opp
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get svc | grep -q opp
done
kubectl -n mmm-suplus-test get pods | grep -q opp
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get pods | grep -q opp
done
kubectl create -f /tmp/test/opp/opp.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q opp
if [ "$?" == "0" ];then
echo "opp service update success!"
else
echo "opp service update fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment update success!"
else
echo "opp deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: opp
namespace: mmm-suplus-test
labels:
k8s-app: opp
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
selector:
k8s-app: opp
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: opp
namespace: mmm-suplus-test
labels:
k8s-app: opp
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: opp
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: opp
image: 192.168.0.243:5000/mmm/opp:test
imagePullPolicy: Always
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: ENTERPRISE_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.enterprise
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.host
- name: MYSQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.port
- name: MYSQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.user
- name: MYSQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.password
- name: MYSQL_DB_NAME
value: "opp_test"
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "9"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: RUN_MODE
value: "prod"
- name: aliyun_logs_suplus
value: "stdout"
- name: aliyun_logs_access
value: "/opt/logs/app.log"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...