--------------------------------mysql.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "Huawei@123"
- name: MYSQL_DATABASE
value: springsecurity
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
---------------------------------myweb.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myweb
spec:
replicas: 2
selector:
matchLabels:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: registry.cn-hangzhou.aliyuncs.com/kaungshen-test/kaugnshen_test:2.0
ports:
- containerPort: 80
env:
- name: MYSQL_SERVICE_HOST
value: 'mysql'
- name: MYSQL_SERVICE_PORT
value: '3306'
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
ports:
- port: 80
selector:
app: myweb
type: LoadBalancer (如果加ingress 则删除这行)
myweb-ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: myweb-ingress
annotations:
# use the shared ingress-nginx
kubernetes.io/ingress.class: "nginx"
spec:
rules:
host: "k8s-ingress.example.xyz"
http:paths: - path: / backend: serviceName: myweb servicePort: 80
apiVersion: v1
kind: Pod
metadata:
name: liveness-http
spec:
containers:
image: nginx:alpine
name: nginx
livenessProbe:httpGet: path: / port: 80 initialDelaySeconds: 15 failureThreshold: 1 periodSeconds: 15
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-tcp
spec:
containers:
name: liveness
image: nginx:alpine
livenessProbe:tcpSocket: port: 80 periodSeconds: 15 timeoutSeconds: 2