1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Kubernetes v1.16

Last updated at Posted at 2019-11-29

環境構築

クラスター構成管理ツールをインストール

kind, minikube, microkube などから、どれかを選択するか、
GKE, AKS, EKS などから、どれかを選ぶ。
Kubernetes v1.16 が選べるものの中から選ぶ。

kind

iKind() {
  curl -sLo kind https://github.com/kubernetes-sigs/kind/releases/download/$(
    git ls-remote --tags --refs https://github.com/kubernetes-sigs/kind.git | tail -1 | awk -F/ '{print $3}'
  )/kind-$(uname)-amd64
  chmod +x kind
  sudo mv kind /usr/local/bin
} && iKind

minikube

xdg-open https://kubernetes.io/ja/docs/tasks/tools/install-minikube/

microk8s

xdg-open https://microk8s.io/docs/

Docker をインストール

iDocker() {
  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  sudo apt install -y docker-ce apt-transport-https
  sudo usermod -aG docker $(whoami)
} && iDocker
$SHELL -l

kubectl をインストール

iKubectl() {
  curl -LO https://storage.googleapis.com/kubernetes-release/release/$(
    curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt
  )/bin/linux/amd64/kubectl
  chmod +x kubectl
  sudo mv kubectl /usr/local/bin
} && iKubectl

nodejs をインストール

iNodejs() {
  curl -o- https://raw.githubusercontent.com/creationix/nvm/$(
    git ls-remote --tags --refs https://github.com/nvm-sh/nvm.git | grep -P 'v0.\d\d' | tail -1 | awk -F/ '{print $3}'
  )/install.sh | bash
  . ~/.bashrc
  LATEST=$(nvm ls-remote | grep 'Latest LTS' | tail -1 | awk '{print $1}')
  nvm install $LATEST
  nvm alias default $LATEST
  nvm use $LATEST
  node --version
  npm --version
  id
} && iNodejs

環境変数

example() {
  export KINDNAME=example
  export KINDHTTP=80
  export KINDHTTPS=443
  export KINDCONFIG=multinode.yaml
  curl -O https://raw.githubusercontent.com/jobscale/_/master/cloud/k8s/multinode.yaml
  exposedDeployment() {
    kubectl create deployment $1 --image $2
    kubectl expose deployment $1 --name $1 --type LoadBalancer --port $3 --target-port $4
    [[ "$5" != "0" ]] && kubectl autoscale deployment $1 --cpu-percent 50 --min $5 --max 20
  }
} && example

クラスターを作成

createKind() {
  rm -fr ~/.kube/config
  ln -sfn kind-config-$KINDNAME ~/.kube/config
  kind create cluster --config $KINDCONFIG --name $KINDNAME
} && createKind

全てのノードが Ready になるのを待つ

kubectl get nodes -o wide -w

全てのポッドが Running になるのを待つ

kubectl get pods -A -o wide -w

名前空間を設定

createNamespace() {
  kubectl create namespace standard
  kubectl config set-context $(kubectl config current-context) --namespace standard
  kubectl apply -f https://raw.githubusercontent.com/jobscale/_/master/cloud/k8s/limitrange-limits.yaml
} && createNamespace

ノードのリソースを確認

kubectl describe nodes

メトリクスサーバーをデプロイ

metricsServer() {
  git clone https://github.com/kubernetes-sigs/metrics-server.git
  kubectl apply -f metrics-server/deploy/1.8+
} && metricsServer

ロードバランサーをデプロイ

metalLB() {
  METAL_VERSION=$(git ls-remote --tags --refs https://github.com/danderson/metallb.git | tail -1 | awk -F/ '{print $3}')
  echo -e "\n MetalLB ${METAL_VERSION} \n"
  kubectl apply -f https://raw.githubusercontent.com/google/metallb/${METAL_VERSION}/manifests/metallb.yaml
  kubectl apply -f https://git.io/km-config.yaml
} && metalLB

イングレスをデプロイ

ingressNginx() {
  kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
  kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
} && ingressNginx

管理ダッシュボードをデプロイ

adminDashboard() {
  kubectl apply -f https://raw.githubusercontent.com/jobscale/_/master/cloud/k8s/kubernetes-dashboard.yaml
  kubectl apply -f https://raw.githubusercontent.com/jobscale/_/master/cloud/k8s/admin-user-service-account.yaml
} && adminDashboard

アプリをデプロイ

アプリをデプロイ

wetty をデプロイ

exposedDeployment wetty jobscale/wetty 443 3000 0

laravel をデプロイ

exposedDeployment laravel jobscale/laravel 80 80 3

ラーメンタイマーをデプロイ

exposedDeployment ramen-timer jobscale/ramen-timer 80 80 3

wordpress をデプロイ

exposedDeployment wordpress jobscale/wordpress 80 80 3

django をデプロイ

exposedDeployment django jobscale/django 80 80 3

dokuwiki をデプロイ

exposedDeployment dokuwiki jobscale/dokuwiki 80 80 3

tomcat をデプロイ

exposedDeployment tomcat tomcat 80 8080 3

ポート転送

sudo -E kubectl port-forward --address 0.0.0.0 svc/tomcat 80:80
xdg-open http://127.0.0.1

管理ダッシュボード

トークンの表示

token() {
  kubectl -n kube-system describe secret $(
    kubectl -n kube-system get secret | grep admin-user | awk '{print $1}'
  )
} && token

ポート転送

sudo -E kubectl -n kubernetes-dashboard port-forward --address 0.0.0.0 svc/kubernetes-dashboard 443:443

google-chrome-stable

google-chrome-stable https://127.0.0.1

おわりに

いらないやつもありますが、あえて書きました。
各自、自分の環境に合わせて読みかえてください。

以上
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?