root@ubuntu22:~# apt autoremove
:(中略)
root@ubuntu22:~# apt clean
:(中略)
root@ubuntu22:~# apt update
:(中略)
root@ubuntu22:~# apt upgrade
:(中略)
root@ubuntu22:~# apt autoremove
:(中略)
root@ubuntu22:~# apt clean
:(中略)
root@ubuntu22:~# apt upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
libglib2.0-0 libglib2.0-bin libglib2.0-data
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
root@ubuntu22:~#
後で使うのでgoogle cloud SDKが紐づいているか確認する。
gavannitsales@ubuntu22:~$ gcloud config list
[core]
account = 225919338029-compute@developer.gserviceaccount.com
disable_usage_reporting = True
project = fourth-elixir-383118
Your active configuration is: [default]
gavannitsales@ubuntu22:~$
普通にgit入れる。
root@ubuntu22:~# apt install git
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
git is already the newest version (1:2.34.1-1ubuntu1.8).
git set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
root@ubuntu22:~#
gavannitsales@ubuntu22:~/sample$ cp -rf ./python-docs-samples/appengine/standard/flask/hello_world/ ./hello_world
gavannitsales@ubuntu22:~/sample$ cd hello_world/
gavannitsales@ubuntu22:~/sample/hello_world$ git init .
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /home/gavannitsales/sample/hello_world/.git/
gavannitsales@ubuntu22:~/sample/hello_world$ git add .
gavannitsales@ubuntu22:~/sample/hello_world$ git commit -m "Initial Commit"
[master (root-commit) 2f88308] Initial Commit
5 files changed, 98 insertions(+)
create mode 100644 .gitignore
create mode 100644 README.md
create mode 100644 app.yaml
create mode 100644 main.py
create mode 100644 main_test.py
gavannitsales@ubuntu22:~/sample/hello_world$
gavannitsales@ubuntu22:~/sample/hello_world$ git remote add google ssh://gavannitsales@gmail.com@source.developers.google.com:2022/p/fourth-elixir-383118/r/hello-world
gavannitsales@ubuntu22:~/sample/hello_world$
ローカルリポジトリをcloud repositoryへ登録する。
gavannitsales@ubuntu22:~/sample/hello_world$ git push --all google
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 4 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 1.55 KiB | 1.55 MiB/s, done.
Total 7 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2)
To ssh://gmail.com@source.developers.google.com:2022/p/fourth-elixir-383118/r/hello-world
* [new branch] master -> master
gavannitsales@ubuntu22:~/sample/hello_world$
はい、入ったー。
すぐにこれはいらんけど、扱い方はイメージできた。 GCRでも似たようなことやる。
source repositoriesからpullしてとってくる
入った結果をpullしてみると、VMからはスコープ外って怒られた。 なんやねん、取れへんのかいな。
gavannitsales@ubuntu22:~$ mkdir sampleClone
gavannitsales@ubuntu22:~$ cd sampleClone
gavannitsales@ubuntu22:~/sampleClone$
gavannitsales@ubuntu22:~/sampleClone$ gcloud source repos clone hello-world --project=fourth-elixir-383118
ERROR: (gcloud.source.repos.clone) PERMISSION_DENIED: Request had insufficient authentication scopes.
- '@type': type.googleapis.com/google.rpc.ErrorInfo
domain: googleapis.com
metadata:
method: google.devtools.sourcerepo.v1.SourceRepo.GetRepo
service: sourcerepo.googleapis.com
reason: ACCESS_TOKEN_SCOPE_INSUFFICIENT
If you are in a compute engine VM, it is likely that the specified scopes during VM creation are not enough to run this command.
See https://cloud.google.com/compute/docs/access/service-accounts#accesscopesiam for more information about access scopes.
See https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes for how to update access scopes of the VM.
gavannitsales@ubuntu22:~/sampleClone$
gavannitsales@ubuntu22:~/sampleClone/hello-world$ sudo apt install python-pip gunicorn
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
:(中略)
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up build-essential (12.9ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
gavannitsales@ubuntu22:~/sampleClone/hello-world$
pipを更新して、requirements.txtにあるパッケージを入れてく。
gavannitsales@ubuntu22:~/sampleClone/hello-world$ pip install --upgrade pip
Command 'pip' not found, but can be installed with:
apt install python3-pip
Please ask your administrator.
gavannitsales@ubuntu22:~/sampleClone/hello-world$
ありゃ、python3入れろやぁって怒られた。 入れてからもう1回やってみるとOK。
gavannitsales@ubuntu22:~/sampleClone/hello-world$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
:(中略)
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
gavannitsales@ubuntu22:~/sampleClone/hello-world$ pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in /usr/lib/python3/dist-packages (22.0.2)
Collecting pip
Downloading pip-23.1.2-py3-none-any.whl (2.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 13.9 MB/s eta 0:00:00
Installing collected packages: pip
WARNING: The scripts pip, pip3 and pip3.10 are installed in '/home/gavannitsales/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.1.2
gavannitsales@ubuntu22:~/sampleClone/hello-world$
gavannitsales@ubuntu22:~/sample/python-docs-samples/appengine/standard/flask/tutorial$ cat README.md
:(中略)
This sample shows how to use [Flask](http://flask.pocoo.org/) to handle
requests, forms, templates, and static files on Google App Engine Standard.
Before running or deploying this application, install the dependencies using
[pip](http://pip.readthedocs.io/en/stable/):
pip install -t lib -r requirements.txt
For more information, see the [App Engine Standard README](../../README.md)
gavannitsales@ubuntu22:~/sample/python-docs-samples/appengine/standard/flask/tutorial$ cat requirements.txt
Flask==1.1.4; python_version < '3.0'
Flask==2.1.0; python_version > '3.0'
Werkzeug==1.0.1; python_version < '3.0'
gavannitsales@ubuntu22:~/sample/python-docs-samples/appengine/standard/flask/tutorial$ cp -p requirements.txt ~/sampleClone/hello-world/
gavannitsales@ubuntu22:~/sampleClone/hello-world$ sudo pip install -r requirements.txt
Ignoring Flask: markers 'python_version < "3.0"' don't match your environment
Ignoring Werkzeug: markers 'python_version < "3.0"' don't match your environment
Collecting Flask==2.1.0
Downloading Flask-2.1.0-py3-none-any.whl (95 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 95.2/95.2 KB 2.4 MB/s eta 0:00:00
Requirement already satisfied: click>=8.0 in /usr/lib/python3/dist-packages (from Flask==2.1.0->-r requirements.txt (line 2)) (8.0.3)
Collecting Werkzeug>=2.0
Downloading Werkzeug-2.3.2-py3-none-any.whl (242 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 242.2/242.2 KB 7.9 MB/s eta 0:00:00
Collecting itsdangerous>=2.0
Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Requirement already satisfied: Jinja2>=3.0 in /usr/lib/python3/dist-packages (from Flask==2.1.0->-r requirements.txt (line 2)) (3.0.3)
Collecting MarkupSafe>=2.1.1
Downloading MarkupSafe-2.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: MarkupSafe, itsdangerous, Werkzeug, Flask
Attempting uninstall: MarkupSafe
Found existing installation: MarkupSafe 2.0.1
Not uninstalling markupsafe at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'MarkupSafe'. No files were found to uninstall.
Successfully installed Flask-2.1.0 MarkupSafe-2.1.2 Werkzeug-2.3.2 itsdangerous-2.1.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
gavannitsales@ubuntu22:~/sampleClone/hello-world$
gavannitsales@ubuntu22:~$ sudo apt-get install ca-certificates curl gnupg lsb-release
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu4).
lsb-release set to manually installed.
ca-certificates is already the newest version (20211016ubuntu0.22.04.1).
ca-certificates set to manually installed.
curl is already the newest version (7.81.0-1ubuntu1.10).
curl set to manually installed.
gnupg is already the newest version (2.2.27-3ubuntu2.1).
gnupg set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
gavannitsales@ubuntu22:~$
gavannitsales@ubuntu22:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
gavannitsales@ubuntu22:~$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
gavannitsales@ubuntu22:~$ sudo apt-get update
Hit:1 http://us-central1.gce.archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://us-central1.gce.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:3 http://us-central1.gce.archive.ubuntu.com/ubuntu jammy-backports InRelease [108 kB]
Get:4 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB]
Get:5 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [16.7 kB]
Fetched 402 kB in 1s (554 kB/s)
Reading package lists... Done
gavannitsales@ubuntu22:~$ sudo apt-get install docker-ce
:(中略)
Setting up docker-ce (5:23.0.5-1~ubuntu.22.04~jammy) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Scanning processes...
Scanning candidates...
Scanning linux images...
Running kernel seems to be up-to-date.
Restarting services...
Service restarts being deferred:
systemctl restart networkd-dispatcher.service
systemctl restart unattended-upgrades.service
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
gavannitsales@ubuntu22:~$
gavannitsales@ubuntu22:~$ groups gavannitsales
gavannitsales : gavannitsales adm dialout cdrom floppy audio dip video plugdev netdev lxd ubuntu google-sudoers docker
gavannitsales@ubuntu22:~$
gavannitsales@ubuntu22:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
gavannitsales@ubuntu22:~$
gavannitsales@ubuntu22:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
420dd58ee25f hello-world "/hello" About a minute ago Exited (0) About a minute ago distracted_bassi
gavannitsales@ubuntu22:~$ docker rm 420dd58ee25f
420dd58ee25f
gavannitsales@ubuntu22:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 19 months ago 13.3kB
gavannitsales@ubuntu22:~$ docker rmi feb5d9fea6a5
Untagged: hello-world:latest
Untagged: hello-world@sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
gavannitsales@ubuntu22:~$
gavannitsales@ubuntu22:~/GCRsample/hello-world$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world-container latest 5de507c26f8a 19 minutes ago 245MB
gavannitsales@ubuntu22:~/GCRsample/hello-world$ docker -v
Docker version 23.0.5, build bc4487a
gavannitsales@ubuntu22:~/GCRsample/hello-world$
gavannitsales@ubuntu22:~/GCRsample/hello-world$ gcloud auth login
You are running on a Google Compute Engine virtual machine.
It is recommended that you use service accounts for authentication.
You can run:
$ gcloud config set account `ACCOUNT`
to switch accounts if necessary.
Your credentials may be visible to others with access to this
virtual machine. Are you sure you want to authenticate with
your personal account?
Do you want to continue (Y/n)? Y
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=5kI8tuy5M5tkgodbf44G5EXt6DSVcN&prompt=consent&access_type=offline&code_challenge=n1FnysifOhZJ4q1NT1koimVlQ9q0ig3wDP5qlpXFRqk&code_challenge_method=S256
Enter authorization code: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You are now logged in as [gavannitsales@gmail.com].
Your current project is [fourth-elixir-383118]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
gavannitsales@ubuntu22:~/GCRsample/hello-world$
gavannitsales@ubuntu22:~/GCRsample/hello-world$ gcloud auth configure-docker
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
After update, the following will be written to your Docker config file located at
[/home/gavannitsales/.docker/config.json]:
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud"
}
}
Do you want to continue (Y/n)?
Docker configuration file updated.
gavannitsales@ubuntu22:~/GCRsample/hello-world$ ls -l /home/gavannitsales/.docker
total 8
drwx------ 5 gavannitsales gavannitsales 4096 Apr 29 20:53 buildx
-rw------- 1 gavannitsales gavannitsales 204 Apr 29 21:28 config.json
gavannitsales@ubuntu22:~/GCRsample/hello-world$
ローカルイメージにタグ付けする。 今はv1.0とかつけとく。
gavannitsales@ubuntu22:~/GCRsample/hello-world$ docker tag hello-world-container gcr.io/fourth-elixir-383118/hello-world-container:v1.0
gavannitsales@ubuntu22:~/GCRsample/hello-world$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world-container latest 5de507c26f8a 2 hours ago 245MB
gcr.io/fourth-elixir-383118/hello-world-container v1.0 5de507c26f8a 2 hours ago 245MB
gavannitsales@ubuntu22:~/GCRsample/hello-world$
gavannitsales@ubuntu22:~/hoge$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world-container latest 5de507c26f8a 2 hours ago 245MB
gcr.io/fourth-elixir-383118/hello-world-container v1.0 5de507c26f8a 2 hours ago 245MB
gavannitsales@ubuntu22:~/hoge$ docker rmi gcr.io/fourth-elixir-383118/hello-world-container:v1.0
Untagged: gcr.io/fourth-elixir-383118/hello-world-container:v1.0
Untagged: gcr.io/fourth-elixir-383118/hello-world-container@sha256:fe215a34dc5b5ea4cc1f22c809798e507562daaf9085e1a8304d91d515758554
gavannitsales@ubuntu22:~/hoge$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world-container latest 5de507c26f8a 2 hours ago 245MB
gavannitsales@ubuntu22:~/hoge$
gavannitsales@ubuntu22:~/hoge$
gavannitsales@ubuntu22:~/hoge$ docker pull gcr.io/fourth-elixir-383118/hello-world-container:v1.0
v1.0: Pulling from fourth-elixir-383118/hello-world-container
Digest: sha256:fe215a34dc5b5ea4cc1f22c809798e507562daaf9085e1a8304d91d515758554
Status: Downloaded newer image for gcr.io/fourth-elixir-383118/hello-world-container:v1.0
gcr.io/fourth-elixir-383118/hello-world-container:v1.0
gavannitsales@ubuntu22:~/hoge$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world-container latest 5de507c26f8a 2 hours ago 245MB
gcr.io/fourth-elixir-383118/hello-world-container v1.0 5de507c26f8a 2 hours ago 245MB
gavannitsales@ubuntu22:~/hoge$
gavannitsales@ubuntu22:~/hoge$ docker run -p 80:8000 gcr.io/fourth-elixir-383118/hello-world-container:v1.0
2023-04-29 22:52:54 [1] [INFO] Starting gunicorn 17.5
2023-04-29 22:52:54 [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
2023-04-29 22:52:54 [1] [INFO] Using worker: sync
2023-04-29 22:52:54 [11] [INFO] Booting worker with pid: 11
同じようにブラウザで表示できた。
GKEで動かす
GCRに登録したアプリをGKEで動かしてみる。
クラスタ作成甘くない
まずはクラスタ作成して接続。
gavannitsales@ubuntu22:~/gcloud$ gcloud config set project fourth-elixir-383118
Updated property [core/project].
gavannitsales@ubuntu22:~/gcloud$
gavannitsales@ubuntu22:~/gcloud$ gcloud config set compute/zone us-central1-c
Updated property [compute/zone].
gavannitsales@ubuntu22:~/gcloud$
gavannitsales@ubuntu22:~/gcloud$ gcloud container clusters create nariCluster --num-nodes=3
Default change: VPC-native is the default mode during cluster creation for versions greater than 1.21.0-gke.1500. To create advanced routes based clusters, please pass the `--no-enable-ip-alias` flag
Default change: During creation of nodepools or autoscaling configuration changes for cluster versions greater than 1.24.1-gke.800 a default location policy is applied. For Spot and PVM it defaults to ANY, and for all other VM kinds a BALANCED policy is used. To change the default values use the `--location-policy` flag.
Note: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s).
Creating cluster hello-world in us-central1-c... Cluster is being deployed...⠛
root@ubuntu22:~# apt-get update
Hit:1 http://us-central1.gce.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://us-central1.gce.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://us-central1.gce.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:5 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:4 https://packages.cloud.google.com/apt kubernetes-xenial InRelease
Get:6 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Fetched 110 kB in 1s (135 kB/s)
Reading package lists... Done
W: https://apt.kubernetes.io/dists/kubernetes-xenial/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
root@ubuntu22:~#
root@ubuntu22:~#
root@ubuntu22:~# cat /etc/apt/sources.list.d/
docker.list kubernetes.list
root@ubuntu22:~# cat /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
root@ubuntu22:~# echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main
root@ubuntu22:~# cat /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
root@ubuntu22:~# curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
100 1210 100 1210 0 0 8948 0 --:--:-- --:--:-- --:--:-- 8962
OK
root@ubuntu22:~#
root@ubuntu22:~# sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
google-cloud-sdk-gke-gcloud-auth-plugin
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 3129 kB of archives.
After this operation, 11.0 MB of additional disk space will be used.
Get:1 https://packages.cloud.google.com/apt cloud-sdk/main amd64 google-cloud-sdk-gke-gcloud-auth-plugin amd64 428.0.0-0 [3129 kB]
Fetched 3129 kB in 0s (17.5 MB/s)
Selecting previously unselected package google-cloud-sdk-gke-gcloud-auth-plugin.
(Reading database ... 101371 files and directories currently installed.)
Preparing to unpack .../google-cloud-sdk-gke-gcloud-auth-plugin_428.0.0-0_amd64.deb ...
Unpacking google-cloud-sdk-gke-gcloud-auth-plugin (428.0.0-0) ...
Setting up google-cloud-sdk-gke-gcloud-auth-plugin (428.0.0-0) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@ubuntu22:~#
gavannitsales@ubuntu22:~$ cat connectGcloud.sh
gcloud config set project fourth-elixir-383118
gcloud config set compute/zone us-central1-a
gcloud projects describe fourth-elixir-383118
gavannitsales@ubuntu22:~$
gavannitsales@ubuntu22:~$ sh ./connectGcloud.sh
Updated property [core/project].
Updated property [compute/zone].
createTime: '2023-04-08T18:24:56.947Z'
lifecycleState: ACTIVE
name: gvis-7502
projectId: fourth-elixir-383118
projectNumber: '225919338029'
gavannitsales@ubuntu22:~$
gavannitsales@ubuntu22:~$ cat makeGke.sh
gcloud container clusters create narigke --num-nodes=3
gavannitsales@ubuntu22:~$ sh ./makeGke.sh
Default change: VPC-native is the default mode during cluster creation for versions greater than 1.21.0-gke.1500. To create advanced routes based clusters, please pass the `--no-enable-ip-alias` flag
Default change: During creation of nodepools or autoscaling configuration changes for cluster versions greater than 1.24.1-gke.800 a default location policy is applied. For Spot and PVM it defaults to ANY, and for all other VM kinds a BALANCED policy is used. To change the default values use the `--location-policy` flag.
Note: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s).
Creating cluster narigke in us-central1-a... Cluster is being health-checked (master is healthy)...done.
Created
.
To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1-a/narigke?project=fourth-elixir-383118
kubeconfig entry generated for narigke.
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
narigke us-central1-a 1.25.7-gke.1000 34.71.84.23 e2-medium 1.25.7-gke.1000 3 RUNNING
gavannitsales@ubuntu22:~$
クラスタの認証情報取得して接続
認証情報取得して、作ったクラスタに接続する。
gavannitsales@ubuntu22:~$ gcloud container clusters get-credentials narigke
Fetching cluster endpoint and auth data.
kubeconfig entry generated for narigke.
gavannitsales@ubuntu22:~$
Pod起動
Podを起動する。
クラスタ作ってすぐ実行したらcouldn't get resource list for metrics.k8s.io/v1beta1: the server is currently unable to handle the requestって表示されることあるけど起動はできる。
gavannitsales@ubuntu22:~$ kubectl run hello-world --image=gcr.io/fourth-elixir-383118/hello-world-container:v1.0 --port=8000
pod/hello-world created
gavannitsales@ubuntu22:~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-world 1/1 Running 0 10m
gavannitsales@ubuntu22:~$