サポート切れのUbuntu (17.x) のapt updateが失敗する場合の対処

環境
– Google Cloud / Compute Engine / Ubuntu 17.10

サポート切れの古いUbuntuのアップデートをした際に以下のようなエラーで更新ができないことがあります

Ign:1 http://us-east1.gce.archive.ubuntu.com/ubuntu artful InRelease
Ign:2 http://us-east1.gce.archive.ubuntu.com/ubuntu artful-updates InRelease
Ign:3 http://us-east1.gce.archive.ubuntu.com/ubuntu artful-backports InRelease
Err:4 http://us-east1.gce.archive.ubuntu.com/ubuntu artful Release
404 Not Found [IP: 35.196.128.168 80]
Err:5 http://us-east1.gce.archive.ubuntu.com/ubuntu artful-updates Release
404 Not Found [IP: 35.196.128.168 80]
Err:6 http://us-east1.gce.archive.ubuntu.com/ubuntu artful-backports Release
404 Not Found [IP: 35.196.128.168 80]
Ign:7 http://security.ubuntu.com/ubuntu artful-security InRelease
Err:8 http://security.ubuntu.com/ubuntu artful-security Release
404 Not Found [IP: 91.189.91.39 80]
Get:9 http://packages.cloud.google.com/apt google-cloud-logging-wheezy InRelease [5483 B]
Ign:10 http://packages.cloud.google.com/apt google-cloud-monitoring-artful InRelease
Err:11 http://packages.cloud.google.com/apt google-cloud-monitoring-artful Release
404 Not Found [IP: 142.250.98.113 80]
Hit:12 http://archive.canonical.com/ubuntu artful InRelease
Err:9 http://packages.cloud.google.com/apt google-cloud-logging-wheezy InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B53DC80D13EDEF05 NO_PUBKEY FEEA9169307EA071
Reading package lists… Done
E: The repository 'http://us-east1.gce.archive.ubuntu.com/ubuntu artful Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://us-east1.gce.archive.ubuntu.com/ubuntu artful-updates Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://us-east1.gce.archive.ubuntu.com/ubuntu artful-backports Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://security.ubuntu.com/ubuntu artful-security Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://packages.cloud.google.com/apt google-cloud-monitoring-artful Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.cloud.google.com/apt google-cloud-logging-wheezy InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B53DC80D13EDEF05 NO_PUBKEY FEEA9169307EA071

1)キーを更新します。
これでKeyのエラーは解消されます

curl -f https://packages.cloud.google.com/apt/doc/apt-key.gpg \
| sudo apt-key add -

2)リポジトリの接続先が古いので修正します

参照先を http://old-releases.ubuntu.com/ に修正します。archiveもsecurityも同様です。Compute EngineのリストはGoogleのミラーを示しているので一旦Ubuntuの方に変更しておくのもよいかと思います。ググるとリストから取り除くみたいな記述もあるのですがそれをするとUpdateできなくなりますので修正しておきます。

deb http://old-releases.ubuntu.com/ubuntu/ artful main restricted
deb http://old-releases.ubuntu.com/ubuntu/ artful-updates main restricted
deb http://old-releases.ubuntu.com/ubuntu/ artful universe
deb http://old-releases.ubuntu.com/ubuntu/ artful-updates universe
deb http://old-releases.ubuntu.com/ubuntu/ artful multiverse
deb http://old-releases.ubuntu.com/ubuntu/ artful-updates multiverse
deb http://old-releases.ubuntu.com/ubuntu/ artful-backports main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ artful-security main restricted
deb http://old-releases.ubuntu.com/ubuntu/ artful-security universe
deb http://old-releases.ubuntu.com/ubuntu/ artful-security multiverse

これで無事に apt upgrade 出来るようになったかと思います。

サイトのサーバをGCEのE2-Microインスタンスタイプに変更

サイトの費用が気になっていたもの手を付けてなかったのでサーバ(Google Compute Engine)の構成を変えた。

  • これまで Cloudfare ---> Global Load Balancer ---> Instance Group ---> GCE(f1-micro) という構成。
  • 以前、 jpリージョンで動作させていたGCEを無料枠のUSリージョンに移動したりしたときにGLB経由にして移動したときの名残。
  • f1-microでは何ヶ月か前から処理が間に合わなくなり良く停止していたため今回 e2-micro に変更
  • GLBを破棄して直接 Cloudfareから接続をするように変更
  • 最近E2マシンタイプという新しいモデルがでてきたので使ってみたいと思います。 https://googlecloud.4watcher365.dev/google-cloud/e2-vm-machinetypes/
  • 2020/01より外部IPアドレスが利用していても有料化されるので少しでもコストを下げたい

ということで以下のことを実施しました

  • GLBに関するリソースを削除
  • GCEのCPUモデルを e2-micro に変更
  • GCEのネットワーク設定にて外部IPアドレスを固定で新規に追加(既存はエフェメラル)
  • 作成したIPアドレスを、CloudFare側の設定に追加(既存は削除)

費用的にはGCEの無料枠から外れる、外部IPが新規にかかる。代わりにGLBの費用が削減ということでトータルで1000Yen/Month程度は下がる予定です。

gcloud/kubectlコマンドの補完をインタラクティブに選択可能にするalpha版が登場

Read More

Google Compute Platform の操作をするためのCLI gcloud コマンドで新しい補完スタイルが提案されました。これまでも bash や zsh ではコマンドの引数を <TAB> で保管する事が出来ます。通常はこれでも十分に実用的な機能として利用できます。

今回の新しい機能を導入すると下の図のように引数の候補、説明などが表示されます。(今環境は mac + iTerm2 上で動かしていますので Windows 環境だとどんな感じなのかはチョットわかりません)

  • gcloudだけじゃなくて kubectl も補完されるので k8s ユーザにもおすすめ
  • 引数の説明は覚え切らないのでヘルプがとても便利(ON/OFF可能)
  • キー操作は vi / emace に切り替え可能

導入は簡単でalpha版の機能を有効にするだけです

gcloud components  update
gcloud components install alpha
gcloud alpha interactive --update-cli-trees
gcloud alpha interactive

これだけで利用することが出来ます。