K8S常建应用
K8S搭建ETCD(项目使用)
apiVersion: apps/v1
kind: Deployment
metadata:
name: etcd
namespace: work
spec:
replicas: 1
selector:
matchLabels:
app: etcd
template:
metadata:
labels:
app: etcd
spec:
containers:
- name: etcd
image: quay.io/coreos/etcd:v3.5.0
command:
- "/usr/local/bin/etcd"
args:
- "--advertise-client-urls=http://0.0.0.0:22379"
- "--listen-client-urls=http://0.0.0.0:22379"
ports:
- containerPort: 22379
---
apiVersion: v1
kind: Service
metadata:
name: etcd-service
namespace: work
spec:
selector:
app: etcd
ports:
- protocol: TCP
port: 22379
targetPort: 22379
mysql(持久化存储):
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-8.0
namespace: work
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
hostNetwork: true
containers:
- name: mysql
image: 10.0.204.94/work/mysql:8.0
env:
- name: MYSQL_ROOT_PASSWORD
value: ASDFasdf123.@
ports:
- containerPort: 3306
name: mysql
livenessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 60
periodSeconds: 15
readinessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 60
periodSeconds: 20
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
imagePullSecrets:
- name: my-harbor
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: mysql-data
---
apiVersion: v1
kind: Service
metadata:
name: mysql-service
namespace: work
spec:
selector:
app: mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
nodePort: 30001
type: NodePort
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-data
namespace: work
annotations:
volume.beta.kubernetes.io/storage-class: "course-nfs-storage"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1G
nginx:
piVersion: v1
kind: PersistentVolume
metadata:
name: nginx-pv
namespace: work
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
storageClassName: nginx-pv
nfs:
path: /usr/local/work/work/nginx/work
server: 192.168.2.249
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-pvc
namespace: work
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
storageClassName: nginx-pv
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-web
namespace: work
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.18
ports:
- containerPort: 80
volumeMounts:
- name: work
mountPath: /work
- name: nginx-conf
mountPath: /etc/nginx/conf.d
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 15
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 15
volumes:
- name: work
persistentVolumeClaim:
claimName: nginx-pvc
- name: nginx-conf
configMap:
name: nginx-conf
---
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: work
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
name: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx
namespace: work
spec:
ingressClassName: nginx
rules:
- host: test.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
jenkins(持久化):
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv
namespace: work
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: jenkins-pv
nfs:
path: /usr/local/work/work/jenkins/data
server: 192.168.2.249
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pvc
namespace: work
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: jenkins-pv
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: work
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: jenkins/jenkins:2.401.2-jdk11
ports:
- containerPort: 8080
- containerPort: 50000
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 30
periodSeconds: 60
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 35
periodSeconds: 60
volumeMounts:
- name: jenkins-data
mountPath: /var/jenkins_home
volumes:
- name: jenkins-data
persistentVolumeClaim:
claimName: jenkins-pvc
securityContext:
runAsUser: 0
runAsGroup: 0
---
apiVersion: v1
kind: Service
metadata:
name: jenkins-service
namespace: work
spec:
selector:
app: jenkins
ports:
- protocol: TCP
port: 8080
targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: jenkins-ingress
namespace: work
spec:
ingressClassName: nginx
rules:
- host: jenkins.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: jenkins-service
port:
number: 8080
redis:
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-config
namespace: work
data:
redis.conf: |
port 15079
requirepass 123456
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: work
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: 192.168.2.247/work/redis:6.2.0
command: ["redis-server","/etc/redis/redis.conf"]
ports:
- containerPort: 15079
livenessProbe:
tcpSocket:
port: 15079
initialDelaySeconds: 10
periodSeconds: 15
readinessProbe:
tcpSocket:
port: 15079
initialDelaySeconds: 15
periodSeconds: 20
volumeMounts:
- name: redis-config
mountPath: /etc/redis
readOnly: true
volumes:
- name: redis-config
configMap:
name: redis-config
imagePullSecrets:
- name: harbor
---
apiVersion: v1
kind: Service
metadata:
name: redis-service
namespace: work
spec:
selector:
app: redis
ports:
- protocol: TCP
port: 15079