Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to create an Ubuntu based deployment

I've created my cluster in GKE and now I want to create a deployment that uses the ubuntu:latest docker image. I cannot figure out how to do that

If anyone knows how to that'll be greatly appreciated

0 8 3,656
8 REPLIES 8

Hello gal-hadar115, 

You can refer to this documentation for deploying an Ubuntu docker image. The documentation assumes that you already have a working docker image, that you can build and run on your local machine, and obviously a Google Cloud account with all of the necessary APIs activated, and the Google Cloud SDK installed on your machine.

Hey gal-hadar115,

To create a YAML file for the deployment, you can follow these steps:

Run the following command to a create yaml file:

 

 

echo 'apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-ubuntu
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-ubuntu
  template:
    metadata:
      labels:
        app: my-ubuntu
    spec:
      containers:
        - name: my-ubuntu-container
          image: ubuntu:latest
          command: ["/bin/sleep", "infinity"]' > my-ubuntu-deployment.yaml

 

To create the deployment using the YAML file, use the following command:

 

kubectl apply -f my-ubuntu-deployment.yaml

 

To check the status of the pods created by the deployment, you can run the following command:

 

kubectl get pods

 

To access the shell of the pod, use the following command, replacing my-ubuntu-xxxxx-xxxxx with the actual name of your pod:

 

kubectl exec -it my-ubuntu-xxxxx-xxxxx -- /bin/bash

 

Feel free to reach out if you have any further questions!

Hello devenes,

Thank you for your answer. I would guess this works in GKE console too? Because it seems this is just cmd commands for vanilla Kubernetes

Maybe you could give us a few more details on what you are trying/hoping to do?
What workload do you want to deploy?

I'm trying through GKE to create a cluster of 2 nodes that each has a single pod based off of the Ubuntu 22.04 image

Certainly, the commands I provided are applicable to the GKE (Google Kubernetes Engine) as well. I personally tested them to ensure their compatibility before sharing them with you.

It's important to note that GKE is a managed Kubernetes service offered by Google Cloud. While it abstracts some of the underlying infrastructure and provides additional features, at its core, GKE still adheres to the Kubernetes standard. Therefore, you can interact with your GKE cluster using kubectl, the command-line tool for Kubernetes.

By using kubectl, you can manage your GKE cluster, deploy applications, scale resources, view logs, and perform other essential tasks. The commands I shared earlier, which are standard Kubernetes commands, can be executed in the GKE console or any other environment where kubectl is installed.

So I connected to the cluster I created in GKE using the cloud shell, then I ran the command "kubectl apply -f my-ubuntu-deploy.yaml" and I received the following error:
"error: error parsing my-ubuntu-deploy.yaml: error converting YAML to JSON: yaml: line 19: found unexpected end of stream"

When you received the error message "error: error parsing my-ubuntu-deploy.yaml: error converting YAML to JSON: yaml: line 19: found unexpected end of stream" after running the command "kubectl apply -f my-ubuntu-deploy.yaml," it indicates that there was an issue with the syntax or structure of your YAML file.

You can use the command I posted earlier to create a yaml file.

To resolve this error, you should review the contents of the "my-ubuntu-deploy.yaml" file and ensure that it follows the correct YAML syntax.

If you're not familiar with YAML syntax, you can use an online YAML validator or a YAML linter to verify the correctness of your file. 

Top Labels in this Space
Top Solution Authors