Open10

debian11 セットアップ & lxc セットアップ

ほなふくほなふく

OSインストールは終わったものとする
デスクトップ環境は無い、CLIのみでセットアップする

ほなふくほなふく

apt

apt update && apt install -y sudo vim

SSH

wget https://github.com/honahuku.keys
mv honahuku.keys authorized_keys
mkdir -p ~/.ssh
mv authorized_keys ~/.ssh
sudo systemctl restart sshd
ほなふくほなふく

init

cat <<EOF | sudo lxd init --preseed 
config: {}
networks:
- config:
    ipv4.address: auto
    ipv6.address: auto
  description: ""
  name: lxdbr0
  type: ""
  project: default
storage_pools:
- config: {}
  description: ""
  name: default
  driver: dir
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      network: lxdbr0
      type: nic
    root:
      path: /
      pool: default
      type: disk
  name: default
projects: []
cluster: null
EOF

doc:
https://lxd-ja.readthedocs.io/ja/latest/howto/initialize/

ほなふくほなふく

コンテナ作成

CT_NAME=hoge
sudo lxc launch images:debian/11 $CT_NAME

コンテナ設定の編集

lxcコンテナでk8sを動かすためにいくつか設定する

wget https://raw.githubusercontent.com/honahuku/manifest/main/doc/lxc/config.yaml
sudo lxc config show $CT_NAME > org.yaml

# 既存の設定をマージするためにyqを入れる
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq

# マージする
# 重複する項目はconfig.yamlで上書きされる
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' org.yaml config.yaml > merged.yaml

# 設定を反映する
sudo lxc config edit $CT_NAME < merged.yaml

doc:
https://github.com/corneliusweig/kubernetes-lxd/blob/master/README.md#starting-your-lxc-container

ほなふくほなふく

kubeadmの設定

initやjoinのパラメータに追加で

--ignore-preflight-errors=FileContent--proc-sys-net-bridge-bridge-nf-call-iptables

を付与する必要がある

ほなふくほなふく

lxcコンテナの操作

コンテナ名はCT_NAME=hogeで予め定義しているものとする

起動

sudo lxc start $CT_NAME

停止

sudo lxc stop $CT_NAME

コンテナのリスト

sudo lxc list

コンテナの情報表示

sudo lxc info $CT_NAME

スナップショット

作成

lxc snapshot コンテナ名 スナップショット名でスナップショットが取れる
スナップショット名は省略できる

sudo lxc snapshot $CT_NAME

スナップショットの一覧

sudo lxc info $CT_NAME

スナップショットの削除

sudo lxc delete $CT_NAME/[snapshot-name]

https://gihyo.jp/admin/serial/01/ubuntu-recipe/0574