K3s
インストールする
Quick-Start Guide | K3s
| # インストール
$ curl -sfL https://get.k3s.io | sh -
# アンインストール
$ /usr/local/bin/k3s-uninstall.sh
|
sudo なしで kubectl を動かす
設定を行えば kubectl をユーザー権限で動かすことができる。
| $ mkdir -p ~/.kube
$ sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
$ sudo chown $USER:$USER ~/.kube/config
$ chmod 600 ~/.kube/config
|
~/.bashrcに以下を追加する。
| ~/.bashrc |
|---|
| # k3s
export KUBECONFIG=$HOME/.kube/config
|
Kompose をインストールする
Kompose
コンテナを動かす
Nginx を動かす
| docker-compose.yml |
|---|
| services:
nginx:
image: nginx:latest
ports:
- "8080:80"
restart: always
volumes:
- ./html:/usr/share/nginx/html:ro
|
| html/index.html |
|---|
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
Hi!
</body>
</html>
|
| $ kompose convert -o ./nginx-manifests/ --volumes hostPath
|
コンテナを起動する。
| $ kubectl apply -f ./nginx-manifests/
|
ポートフォワーディングする。
| $ kubectl port-forward service/nginx 8080:8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
|
http://localhost:8080にアクセスする。
コンテナを終了する。
| $ kubectl delete -f ./nginx-manifests/
|
コマンド類
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | # ポッドの一覧を確認する
$ kubectl get pods
# ポッドの状態を確認する
$ kubectl describe pod $POD_NAME
# ポッドを削除する
$ kubectl delete pod $POD_NAME
# サービスの一覧を確認する
$ kubectl get services
# サービスを削除する
$ kubectl delete service $SERVICE_NAME
# デプロイの一覧を確認する
$ kubectl get deployments
# デプロイを削除する
$ kubectl delete deployment $DEPLOYMENT_SERVICE
|
Pod の状態
ImagePullBackOff
Kubernetes がコンテナイメージを取得できない
ErrImagePull
イメージのプルに失敗している