Scopes required for executing "gcloud container clusters create" on GCE VM instance - google-compute-engine

I am trying to create a GKE cluster by executing the following command on a GCE VM instance:
sudo gcloud container clusters create my-cluster \
--machine-type g1-small --num-nodes 1
Execution fails with this error message (despite kubectl being installed):
WARNING: Accessing a Container Engine cluster requires the kubernetes commandline client [kubectl].
ERROR: (gcloud.container.clusters.create) ResponseError: code=403, message=Request had insufficient authentication scopes.
This problem is perhaps cause by the VM instance not possessing enough scopes. It currently possesses the following ones. Which other scope(s) is required in order for the problem to disappear?

Google Container Engine requires the https://www.googleapis.com/auth/cloud-platform scope, so you'll need to select "Allow full access to all Cloud APIs" when you create the VM instance.

Related

How to SSH to worker nodes of openshift cluster on IBM cloud

I have a openshift cluster on IBM cloud. I want to connect to the worker nodes using SSH via Putty but documentation says,
SSH by password is unavailable on the worker nodes.
Is there a way to connect to those?
If you use OpenShift v4 on IBM cloud, you may access your worker nodes using oc debug node/<target node name> instead of SSH. oc debug node command launches a temporary pod for the terminal session on the target node. You can check and run linux commands like usual SSH session through the Pod. Try it.
SSH access to worker nodes in OpenShift is disabled for security reasons. The documentation suggests to use DaemonSets for actions to be performed on worker nodes.

Google Compute Engine is not responding

My GCP server is down. It was working last day. I can see the server in VM Instances but can not connect using SSH. All the client websites are down.
Can any one help ?
There is several reasons this could happen:
If your disk is full
sshd deamon isn't configured properly
If OS login is enabled on your instance
A firewall rule block port 20
Sometimes, you see some connection errors in the console, that worth to take a look.
EDIT:
I will need additional information if that still not working;
Take a look to your serial console logs and tell me if you have any relevant logs that can help like a kernel panic, issue with networking, permission denied, etc
Use Cloud Shell and try to connect to your VM instance with these commands:
gcloud compute firewall-rules create --network=default default-allow-ssh --allow tcp:22
gcloud compute ssh YOUR_INSTANCE_NAME --zone YOUR_ZONE -- -vvv
If you can't connect from cloud shell, try to ping your VM instance (internal IP & external IP)
I highly recommend to delete your screenshots showing information about your VM instance (Firewall rules, Project name, nmap scans, etc).

What are the differences between various SSH methods in Google Cloud Compute Engine?

I usually SSH into a Google Cloud Compute Engine Instance using my local terminal like:
ssh -i ~/.ssh/[KEY_FILENAME [USERNAME]#ip_address
where the [KEY_FILENAME] is generated using
ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
There is also another way to connect to the instance which is through the browser, however I would connect to the instance with a different user account. Is there a way that I can make it consistent regardless of the method I use to connect?
There are several ways to connect a Linux instance via the SSH. The way you are connecting to an instance is via the terminal. You can connect via the Cloud Console Web UI which is in general the most convenient way to connect to an instance. Also, you can use Google Cloud SDK and run below command to connect to an instance via SSH:
gcloud compute ssh [INSTANCE_NAME]
You can also use Cloud Shell to connect your instance from the Cloud Console web UI by using the same command as above. You can connect via the serial console using the Google Cloud Platform Console, the gcloud command-line tool, or a third-party SSH client. The serial console authenticates users with SSH keys. Specifically, you must add your public SSH key to the project or instance metadata, and store your private key on the local machine from which you want to connect. There are other advanced methods to connect to an instance which you can find at this link.
By default, the gcloud compute command-line tool uses the $USER variable to add users to the /etc/passwd file for connecting to virtual machine instances using SSH. You can specify a different user using the --ssh-key-file PRIVATE_KEY_FILE flag when running the gcloud compute ssh command. Depending on your use case and convenience, you can use any method consistently.

SSH to Google Compute Engine Instance Failing

I created a simple f1 micro instance (Ubuntu 16.10) on Google Compute Engine. I had created a VPC (Networking) and allowed http/https. I explicitly created a Firewall rule to allow SSH (tcp:22). But I am not able to login to the VM instance.
I keep getting this error:
Here is my Firewall Rule:
How to fix this?
I was able to finally ssh into an instance by Choosing "Automatic" while creating a new VPC network instead of Custom and also chose allow ssh. This added default Firewall rules which were more accurate.
For anyone that runs into this problem I reached out to Google support by email (who responded!!) and they instructed me to run the following commands from terminal (where I have gcloud installed):
If you haven't yet authenticated / or to set the correct project
gcloud auth login
gcloud config set project PROJECT_ID
This is the meat of it - setting the firewall rules.
gcloud beta compute firewall-rules create default-allow-ssh --allow tcp:22 --priority=65534
Also - use chrome - the interface seems to occasionally throw a fit whenever you use any other browser.

How to change machine type of GCE instance?

As there isn't any direct option to change machine type and i have to create a new instance. What are the steps to do so that the configuration/software that I had installed remain same ?
1) Delete the instance that you want to upgrade by keeping its boot disk.
gcloud compute instances delete <instance-name> --keep-disks boot
2) Now create image from this boot disk
gcloud compute images create <any-image-name> --source-disk <instance-name>
3) Now Check Images list
gcloud compute images list
4) Now Create new instance from developer console or using gcloud compute
and select your image as boot disk.
5) Done.
Here is the link.
Updated answer
I'm not sure when this launched, but it is now possible to change the machine type, without deleting instance and re-creating it from scratch, per the docs:
You can change the machine type of a stopped instance if it is not part of a managed instance group.
Here's how you can do this with gcloud:
$ gcloud compute instances set-machine-type INSTANCE_NAME \
--machine-type NEW_MACHINE_TYPE
Also, note the caveat about moving to smaller instance types:
If you move from a machine type with more resources to a machine type with fewer resources, such as moving from a e2-standard-8 machine type to a e2-standard-2, you could run into hardware resource issues or performance limitations because smaller machine types are less powerful than larger machine types. Make sure that your new machine type is able to support any applications or services that are currently running on the instance, or that you update your services and applications to run on the smaller machine types.
Original answer (outdated)
You can't change the instance type of a VM on-the-fly. To upgrade or downgrade the VM type, you should do the following:
VERY IMPORTANT: make sure to not delete VM's boot disk while shutting down the VM; see this answer for details
shut down the VM cleanly while taking into account the information from step #1 if you're doing this via Google Developers Console or via gcloud on the CLI by using the --keep-disks option or by having already set those disks to not auto-delete as described in this answer:
gcloud compute instances delete VM \
--keep-disks=all \
--project $PROJECT
--zone $ZONE
Note that --keep-disks accepts any of the following options: boot, data, or all. In your case, you want at least boot but if you've attached other disks, you want to specify all. See the docs for more info.
create a new VM and choose a larger/smaller instance type: again, this can be done via Google Developers Console or via gcloud on the CLI and instead of creating a new boot disk, select the boot disk from the original VM, e.g.,
gcloud compute instances create $VM \
--disk name=${DISK_NAME},boot=yes \
--machine-type ${MACHINE_TYPE} \
--project $PROJECT
--zone $ZONE
See the docs for more info.
As of today, this ability can be seen on Google Compute Engine. You will need to stop the instance and then edit the instance.. which will give you a drop-down menu for the Machine Types
https://cloud.google.com/sdk/gcloud/reference/alpha/compute/instances/set-machine-type?hl=en