Jump to content

Kubernetes: Difference between revisions

2,132 bytes added ,  9 February 2023
Line 265: Line 265:
kubectl run busybox-shell --rm -i --tty --image odise/busybox-curl -- sh
kubectl run busybox-shell --rm -i --tty --image odise/busybox-curl -- sh
</syntaxhighlight>
</syntaxhighlight>
==Deployments==
In most cases, you will use deployments to provision pods.<br>
Deployments internally use replicasets to create multiple identical pods.<br>
This is great for things such as webservers or standalone services which are not stateful.
In most cases, you can stick a service in front which will round-robin requests to different pods in your deployment.
{{hidden | Example Deployment |
<syntaxhighlight lang="yaml">
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nextcloud-app
  labels:
    app: nextcloud
spec:
  replicas: 1
  selector:
    matchLabels:
      pod-label: nextcloud-app-pod
  template:
    metadata:
      labels:
        pod-label: nextcloud-app-pod
    spec:
      containers:
        - name: nextcloud
          image: public.ecr.aws/docker/library/nextcloud:stable
          ports:
            - containerPort: 80
          env:
            - name: MYSQL_HOST
              value: nextcloud-db-service
            - name: MYSQL_DATABASE
              value: nextcloud
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: nextcloud-db-credentials
                  key: username
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: nextcloud-db-credentials
                  key: password
          volumeMounts:
            - name: nextcloud-app-storage
              mountPath: /var/www/html
      volumes:
        - name: nextcloud-app-storage
          persistentVolumeClaim:
            claimName: nextcloud-app-pvc
</syntaxhighlight>
}}
==StatefulSets==
[https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/ StatefulSets basics]
Stateful sets are useful when you need a fixed number of pods with stable identities.<br>
Pods created by stateful sets have a unique number suffix which allows you to query a specific pod.<br>
Typically, you will want to use a headless service (i.e. without ClusterIP) to give local dns records to each service.
In most cases, you will want to look for a helm chart instead of creating your own stateful sets.


==Services==
==Services==