Certainly! Below is a YAML configuration that should roughly match your requirements. Please note that you'll need to replace placeholders like<YOUR_SECRET_NAME>,<YOUR_DB_USERNAME>,<YOUR_DB_PASSWORD>, and<YOUR_DB_HOST>with your actual secret name and database credentials.
────────────────────────────────────────────────────────────────────
yamlCopy codeapiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:v1.0.1
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
env:
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: <YOUR_SECRET_NAME>
key: username
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: <YOUR_SECRET_NAME>
key: password
- name: DB_HOST
value: <YOUR_DB_HOST>
volumeMounts:
- name: myapp-storage
mountPath: /data
volumes:
- name: myapp-storage
emptyDir: {}
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp-deployment
: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-upgrade
spec:
replicas: 3
selector:
matchLabels:
app: myapp
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:new-version
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
env:
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: <YOUR_SECRET_NAME>
key: username
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: <YOUR_SECRET_NAME>
key: password
- name: DB_HOST
value: <YOUR_DB_HOST>
volumeMounts:
- name: myapp-storage
mountPath: /data
volumes:
- name: myapp-storage
emptyDir: {}
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: myapp-storage-class
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myapp-pvc
spec:
storageClassName: myapp-storage-class
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
This YAML configuration defines a Kubernetes Deployment for your application, a Service to expose it, an HPA for autoscaling, and a separate Deployment for handling upgrades. It also includes a StorageClass and PersistentVolumeClaim for attaching 50GB network storage to each instance. Please make sure to customize it further based on your specific environment and requirements.