0

I'm trying to figure out how to deploy my application with Kubernetes, but I haven't touched it in a couple of years, so, the little that I haven't forgotten seems to have changed.

I created a deployment.yaml which I deployed and as expected, it failed to start. I made some improvements, rebuilt the docker image, pushed it, changed the deployment.yaml to point to the new image and reapplied it:

kubectl apply -f deployment.yml

Now, I see this:

> kubectl.exe get pods
NAME                              READY   STATUS             RESTARTS   AGE
recruiters-wtf-665f58f994-tsf6l   1/2     CrashLoopBackOff   19         77m
recruiters-wtf-6f994cc5b9-9rj28   0/2     Pending            0          7m46s

Why aren't the new pods replacing the old ones?

My deployment.yaml looks like this:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: recruiters-wtf
  labels:
    app: recruiters-wtf
spec:
  replicas: 1
  selector:
    matchLabels:
      app: recruiters-wtf
  template:
    metadata:
      labels:
        app: recruiters-wtf
    spec:
      containers:
        - name: recruiters-wtf
          image: eu.gcr.io/recruiters-wtf/recruiters-wtf:edda1a5626d1
          ports:
            - containerPort: 80
          # The following environment variables will contain the database host,
          # user and password to connect to the PostgreSQL instance.
          env:
            - name: POSTGRES_DB_HOST
              value: 127.0.0.1:5432
            # [START cloudsql_secrets]
            - name: POSTGRES_DB_USER
              valueFrom:
                secretKeyRef:
                  name: cloudsql-db-credentials
                  key: username
            - name: POSTGRES_DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: cloudsql-db-credentials
                  key: password
            # [END cloudsql_secrets]
        # Change <INSTANCE_CONNECTION_NAME> here to include your GCP
        # project, the region of your Cloud SQL instance and the name
        # of your Cloud SQL instance. The format is
        # $PROJECT:$REGION:$INSTANCE
        # [START proxy_container]
        - name: cloudsql-proxy
          image: gcr.io/cloudsql-docker/gce-proxy:1.14
          command: ["/cloud_sql_proxy", "-instances=<INSTANCE_CONNECTION_NAME>=tcp:5432",
            # If running on a VPC, the Cloud SQL proxy can connect via Private IP. See:
            # https://cloud.google.com/sql/docs/mysql/private-ip for more info.
            # "-ip_address_types=PRIVATE",
                    "-credential_file=/secrets/cloudsql/credentials.json"]
          # [START cloudsql_security_context]
          securityContext:
            runAsUser: 2  # non-root user
            allowPrivilegeEscalation: false
          # [END cloudsql_security_context]
          volumeMounts:
            - name: cloudsql-instance-credentials
              mountPath: /secrets/cloudsql
              readOnly: true
        # [END proxy_container]
      # [START volumes]
      volumes:
        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
      # [END volumes]
Pablo
  • 7,249
  • 25
  • 68
  • 83

1 Answers1

0

You can follow documentation which describes what you should do in steps to update deployment.

Starting from Kubectl v. 1.15 you can run following command:

$ kubectl rollout restart deployment <deploymentname>

If you want to use it, make sure you have kubectl version 1.15. If you want to remove older version of your deployment, type:

$ kubectl delete deployment <deploymentname>
aga
  • 128
  • 3