DEV Community

Cover image for DevPill 3: How to deploy a container to your Kubernetes cluster (GKE)
Raul Paes Silva
Raul Paes Silva

Posted on • Edited on

DevPill 3: How to deploy a container to your Kubernetes cluster (GKE)

1. Specify the deployment.yaml file.

Example:

  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: api-gateway
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: api-gateway
    template:
      metadata:
        labels:
          app: api-gateway
      spec:
        containers:
          - name: api-gateway
            image: us-central1-docker.pkg.dev/<project-id>/<repository-name>/api-gateway
            ports:
              - containerPort: 8081
            resources:
              requests:
                memory: "128Mi"
                cpu: "125m"
              limits:
                memory: "128Mi"
                cpu: "125m"
            env:
              # Accessing an env variable from the app-config config map
              - name: GATEWAY_HTTP_ADDR
                valueFrom:
                  configMapKeyRef:
                    key: GATEWAY_HTTP_ADDR
                    name: app-config
              - name: JAEGER_ENDPOINT
                valueFrom:
                  configMapKeyRef:
                    key: JAEGER_ENDPOINT
                    name: app-config


  apiVersion: v1
  kind: Service
  metadata:
    name: api-gateway
  spec:
    type: LoadBalancer
    ports:
      - port: 8081
        targetPort: 8081
    selector:
      app: api-gateway
Enter fullscreen mode Exit fullscreen mode

2. Access Google Cloud Console and create your GKE cluster

(this might take a while)

3. Execute the following command:

gcloud container clusters get-credentials <cluster-id> --region us-central-1 --project <project-id>
Enter fullscreen mode Exit fullscreen mode

4. Upload the manifests.

Example:

kubectl apply -f infra/production/k8s/app-config.yaml
kubectl apply -f infra/production/k8s/secrets.yaml

kubectl apply -f infra/production/k8s/api-gateway-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

If you want to check the status of the deployments try the following commands:

kubectl get deployments
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Top comments (0)