Kubernetes-yaml-examples
-
Namespace
-
kind: Namespace apiVersion: v1 metadata: name: test labels: name: test
-
-
Deployment
- https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment
-
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
-
Secrets
- https://kubernetes.io/docs/tasks/configmap-secret/managing-secret-using-config-file/#create-the-config-file
-
echo -n 'secret value' | base64 echo $SECRET | base64 -d
- [[sealed-secrets]]
-
apiVersion: v1 kind: Secret metadata: name: mysecret type: Opaque data: username: YWRtaW4= password: MWYyZDFlMmU2N2Rm
- Secrets from env files:
kubectl create secret generic env --from-env-file=.env
-
envFrom: - secretRef: name: env
Services
- ### Nodeport
- ```yaml
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
selector:
app.kubernetes.io/name: MyApp
ports:
# By default and for convenience, the `targetPort` is set to the same value as the `port` field.
- port: 80
targetPort: 80
# Optional field
# By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
nodePort: 30007
```
Ingress
-
NFS Volumes
- There are two ways to handle NFS:
-
Example for NFS Volume:
apiVersion: apps/v1 kind: Deployment metadata: name: example-app labels: app: example-app spec: replicas: 1 selector: matchLabels: app: example-app template: metadata: labels: app: example-app spec: containers: - name: example-app image: busybox:latest command: ["sleep", "3000"] volumeMounts: - mountPath: /persistent-volume name: nfs-volume volumes: - name: nfs-volume nfs: server: "server_ip" path: "/path/to/directory"