Kubernetes-yaml-examples

Namespace

kind: Namespace
apiVersion: v1
metadata:
  name: test
  labels:
    name: test

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

echo -n 'secret value' | base64
echo $SECRET | base64 -d
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  username: YWRtaW4=
  password: MWYyZDFlMmU2N2Rm
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