How to create an example kubernetes deployment?

Here is a simple example of how to create a kubernetes deployment out of a yaml file.

cat << EOF > client.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: client
  labels:
    app: client
spec:
  replicas: 1
  selector:
    matchLabels:
      app: client
  template:
    metadata:
      labels:
        app: client
    spec:
      containers:
      - name: client
        image: ubuntu:18.04
        command: ["sleep"]
        args: ["3600"]
      restartPolicy: Always
EOF

The file can then be applied with kubectl apply -f client.yaml.

To verify the pod being started, just run kubectl get pod -l app=client.

Leave a comment

Your email address will not be published. Required fields are marked *