From 5df1c7704f7b6f444057a04a743e8468e9accecb Mon Sep 17 00:00:00 2001 From: Hamaguchi Kazuki Date: Tue, 9 Jun 2020 23:28:41 +0900 Subject: [PATCH 1/6] =?UTF-8?q?(add)=20kubeadm=20install=20shell=20script?= =?UTF-8?q?=20kubeadm=20init=E5=89=8D=E3=81=BE=E3=81=A7=E3=81=AE=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E8=87=AA=E5=8B=95=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Vagrantfile | 34 ++++++++++++++++++++++--------- deployments/vm/kubeadm_install.sh | 17 ++++++++++++++++ join_token.txt | 2 ++ lanch_kubectl_kind.sh | 2 ++ 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 deployments/vm/kubeadm_install.sh create mode 100644 join_token.txt diff --git a/Vagrantfile b/Vagrantfile index 68d6eb9..1d323f9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -13,15 +13,32 @@ Vagrant.configure("2") do |config| # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box = "ubuntu/bionic64" - # config.vm.network "forwarded_port", guest: 3306, host:22 , protocol: "tcp" + config.disksize.size = "40GB" config.vm.provider "virtualbox" do |vb| - # 割り当てるメモリー(MB) - vb.memory = 8192 - # CPUの数 + vb.memory = 8192 vb.cpus = 4 - # I/O APICの有効化 - # vb.customize ["modifyvm", :id, "--ioapic", "on"] end + + config.vm.define "master" do |atomic| + atomic.vm.hostname="master.atomichost" + atomic.vm.network "private_network", ip: "192.168.33.41" + end + + config.vm.define "node01" do |atomic| + atomic.vm.hostname="node01.atomichost" + atomic.vm.network "private_network", ip: "192.168.33.42" + end + + config.vm.define "node02" do |atomic| + atomic.vm.hostname="node02.atomichost" + atomic.vm.network "private_network", ip: "192.168.33.43" + end + + config.vm.provision :shell, path: "./deployments/vm/docker-install.sh" + config.vm.provision :shell, path: "./deployments/vm/permission.sh" + config.vm.provision :shell, path: "./deployments/vm/kubeadm_install.sh" + # config.vm.provision :shell, path: "./deployments/vm/golang-install.sh" +end # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. @@ -72,7 +89,4 @@ Vagrant.configure("2") do |config| # Enable provisioning with a shell script. Additional provisioners such as # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the # documentation for more information about their specific syntax and use. - config.vm.provision :shell, path: "./deployments/vm/docker-install.sh" - config.vm.provision :shell, path: "./deployments/vm/permission.sh" - # config.vm.provision :shell, path: "./deployments/vm/golang-install.sh" -end + diff --git a/deployments/vm/kubeadm_install.sh b/deployments/vm/kubeadm_install.sh new file mode 100644 index 0000000..9b3b3ee --- /dev/null +++ b/deployments/vm/kubeadm_install.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +sudo apt-get update && sudo apt-get install -y apt-transport-https curl + +curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - + +cat < Date: Mon, 22 Jun 2020 22:26:41 +0900 Subject: [PATCH 2/6] (add) sample of kubernetes create yaml --- demo/pod/pod-definition-db.yml | 13 +++++++++++++ demo/pod/pod-definition.yml | 11 +++++++++++ demo/pod/rc-definition.yml | 19 +++++++++++++++++++ demo/pod/replicaset-definition.yml | 22 ++++++++++++++++++++++ join_token.txt | 4 ++-- 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 demo/pod/pod-definition-db.yml create mode 100644 demo/pod/pod-definition.yml create mode 100644 demo/pod/rc-definition.yml create mode 100644 demo/pod/replicaset-definition.yml diff --git a/demo/pod/pod-definition-db.yml b/demo/pod/pod-definition-db.yml new file mode 100644 index 0000000..87462fa --- /dev/null +++ b/demo/pod/pod-definition-db.yml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Pod +metadata: + name: postgres + labels: + app: db-tier +spec: + containers: + - name: postgres + image: postgres + env: + - name: POSTGRES_PASSWORD + value: mysecretpassword diff --git a/demo/pod/pod-definition.yml b/demo/pod/pod-definition.yml new file mode 100644 index 0000000..c56cab5 --- /dev/null +++ b/demo/pod/pod-definition.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Pod +metadata: + name: myapp-pod + labels: + app: myapp + tier: front-end +spec: + containers: + - name: nginx-container + image: nginx \ No newline at end of file diff --git a/demo/pod/rc-definition.yml b/demo/pod/rc-definition.yml new file mode 100644 index 0000000..29f174d --- /dev/null +++ b/demo/pod/rc-definition.yml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: myapp-rc + labels: + app: myapp + type: front-end +spec: + template: + metadata: + name: myapp-pod + labels: + app: myapp + type: front-end + spec: + containers: + - name: nginx-container + image: nginx + replicas: 3 diff --git a/demo/pod/replicaset-definition.yml b/demo/pod/replicaset-definition.yml new file mode 100644 index 0000000..adba752 --- /dev/null +++ b/demo/pod/replicaset-definition.yml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: myapp-replicaset + labels: + app: myapp + type: front-end +spec: + template: + metadata: + name: myapp-pod + labels: + app: myapp + type: front-end + spec: + containers: + - name: nginx-container + image: nginx + replicas: 3 + selector: + matchLabels: + tier: front-end \ No newline at end of file diff --git a/join_token.txt b/join_token.txt index 84730ea..f5232e8 100644 --- a/join_token.txt +++ b/join_token.txt @@ -1,2 +1,2 @@ -kubeadm join 192.168.33.41:6443 --token gncgix.urhdxfvxlf1tcj7o \ - --discovery-token-ca-cert-hash sha256:206b97267d11e669d6ee70f5ff7096c209115b2ce687f4838ae2dc0c1a703f78 \ No newline at end of file +kubeadm join 192.168.33.41:6443 --token cf48wx.d9tz2pcmqy7dm4vt \ + --discovery-token-ca-cert-hash sha256:b8e47ecfc30bb3bb1dd94e75812552ba289153639944860080f218fafc070dde \ No newline at end of file From 3b261f37d2ee6d07a1842c317722f38dbc5da0f6 Mon Sep 17 00:00:00 2001 From: hama-matcha Date: Tue, 30 Jun 2020 16:21:25 +0900 Subject: [PATCH 3/6] =?UTF-8?q?(add)=20practice=20deployment=20yaml=20Repl?= =?UTF-8?q?icaset=E3=81=8B=E3=82=89Deployment=E3=81=AEyaml=E3=81=BE?= =?UTF-8?q?=E3=81=A7=E6=9B=B8=E3=81=84=E3=81=A6=E3=81=BF=E3=81=9F=20?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=8C=E3=81=82=E3=82=8B=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AFyaml=E3=82=92=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88?= =?UTF-8?q?=E3=81=A6kubectl=20apply=20-f=20~~=20=E3=81=8C=E3=82=88?= =?UTF-8?q?=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/deployment/deployment-def.yml | 21 +++++++++++++++++++ demo/deployment/deployment-definition.yml | 25 +++++++++++++++++++++++ demo/pod/replicaset-definition.yml | 4 ++-- demo/replicaset/replicaset-definition.yml | 22 ++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 demo/deployment/deployment-def.yml create mode 100644 demo/deployment/deployment-definition.yml create mode 100644 demo/replicaset/replicaset-definition.yml diff --git a/demo/deployment/deployment-def.yml b/demo/deployment/deployment-def.yml new file mode 100644 index 0000000..e22160e --- /dev/null +++ b/demo/deployment/deployment-def.yml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend + labels: + app: mywebsite + tier: frontend +spec: + replicas: 4 + template: + metadata: + name: myapp-pod + labels: + app: myapp + spec: + containers: + - name: nginx + image: nginx + selector: + matchLabels: + app: myapp diff --git a/demo/deployment/deployment-definition.yml b/demo/deployment/deployment-definition.yml new file mode 100644 index 0000000..2e24f3a --- /dev/null +++ b/demo/deployment/deployment-definition.yml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp-deployment + labels: + app: myapp + type: front-end +spec: + template: + metadata: + name: myapp-pod + labels: + app: myapp + spec: + containers: + - name: nginx-container + image: nginx + + replicas: 5 + selector: + matchLabels: + app: myapp + + + diff --git a/demo/pod/replicaset-definition.yml b/demo/pod/replicaset-definition.yml index adba752..8bab9b9 100644 --- a/demo/pod/replicaset-definition.yml +++ b/demo/pod/replicaset-definition.yml @@ -16,7 +16,7 @@ spec: containers: - name: nginx-container image: nginx - replicas: 3 + replicas: 2 selector: matchLabels: - tier: front-end \ No newline at end of file + type: front-end diff --git a/demo/replicaset/replicaset-definition.yml b/demo/replicaset/replicaset-definition.yml new file mode 100644 index 0000000..815f147 --- /dev/null +++ b/demo/replicaset/replicaset-definition.yml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: myapp-replicaset + labels: + app: myapp + type: front-end +spec: + template: + metadata: + name: myapp-pod + labels: + app: myapp + spec: + containers: + - name: nginx-container + image: nginx + + replicas: 5 + selector: + matchLabels: + app: myapp From 7dcf3617ca76a3b3e7733afe35d01b5c42394300 Mon Sep 17 00:00:00 2001 From: hama-matcha Date: Mon, 6 Jul 2020 17:15:45 +0900 Subject: [PATCH 4/6] (add) flask web app --- Vagrantfile | 2 +- demo/deployment/deployment_flask_app_def.yml | 22 ++++++++++++++++++++ deployments/vm/docker-install.sh | 6 ++++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 demo/deployment/deployment_flask_app_def.yml diff --git a/Vagrantfile b/Vagrantfile index 1d323f9..bfd9ac7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -13,7 +13,7 @@ Vagrant.configure("2") do |config| # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box = "ubuntu/bionic64" - config.disksize.size = "40GB" + config.disksize.size = "20GB" config.vm.provider "virtualbox" do |vb| vb.memory = 8192 vb.cpus = 4 diff --git a/demo/deployment/deployment_flask_app_def.yml b/demo/deployment/deployment_flask_app_def.yml new file mode 100644 index 0000000..323d6e9 --- /dev/null +++ b/demo/deployment/deployment_flask_app_def.yml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp-deployment + labels: + app: myapp + type: front-end +spec: + template: + metadata: + name: myapp-pod + labels: + app: myapp + spec: + containers: + - name: flask-app-container + image: hamamatcha/flask_app + + replicas: 5 + selector: + matchLabels: + app: myapp diff --git a/deployments/vm/docker-install.sh b/deployments/vm/docker-install.sh index 123c91b..2618b61 100644 --- a/deployments/vm/docker-install.sh +++ b/deployments/vm/docker-install.sh @@ -1,5 +1,7 @@ #!/bin/bash +sudo apt-get update -y + sudo apt-get install -y \ apt-transport-https \ ca-certificates \ @@ -10,7 +12,7 @@ sudo apt-get install -y \ 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 \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" @@ -18,4 +20,4 @@ sudo apt-get update -y sudo apt-get -y install docker-ce docker-ce-cli containerd.io -sudo curl -L --fail https://github.com/docker/compose/releases/download/1.25.0/run.sh -o /usr/local/bin/docker-compose \ No newline at end of file +sudo curl -L --fail https://github.com/docker/compose/releases/download/1.25.0/run.sh -o /usr/local/bin/docker-compose From 489ec89f4e05cf933f91b05d5097192757fc2662 Mon Sep 17 00:00:00 2001 From: hama-matcha Date: Mon, 6 Jul 2020 17:53:43 +0900 Subject: [PATCH 5/6] (add) yaml update --- demo/deployment/deployment_flask_app.yml | 34 ++++++++++++++++++++ demo/deployment/deployment_flask_app_def.yml | 26 ++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 demo/deployment/deployment_flask_app.yml diff --git a/demo/deployment/deployment_flask_app.yml b/demo/deployment/deployment_flask_app.yml new file mode 100644 index 0000000..338290e --- /dev/null +++ b/demo/deployment/deployment_flask_app.yml @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: Service +metadata: + name: hello-python-service +spec: + selector: + app: hello-python + ports: + - protocol: "TCP" + port: 6000 + targetPort: 5000 + type: LoadBalancer + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-python +spec: + selector: + matchLabels: + app: hello-python + replicas: 4 + template: + metadata: + labels: + app: hello-python + spec: + containers: + - name: hello-python + image: hamamatcha/flask_app:latest + imagePullPolicy: Never + ports: + - containerPort: 5000 diff --git a/demo/deployment/deployment_flask_app_def.yml b/demo/deployment/deployment_flask_app_def.yml index 323d6e9..aa63c95 100644 --- a/demo/deployment/deployment_flask_app_def.yml +++ b/demo/deployment/deployment_flask_app_def.yml @@ -1,3 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: hello-python-service +spec: + selector: + app: hello-python + ports: + - protocol: "TCP" + port: 6000 + targetPort: 5000 + type: LoadBalancer + +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -6,6 +20,10 @@ metadata: app: myapp type: front-end spec: + replicas: 4 + selector: + matchLabels: + app: myapp template: metadata: name: myapp-pod @@ -15,8 +33,6 @@ spec: containers: - name: flask-app-container image: hamamatcha/flask_app - - replicas: 5 - selector: - matchLabels: - app: myapp + imagePullPolicy: Never + ports: + - containerPort: 5000 From ba4cd32e285205707115c8fae2fc21b7b5844746 Mon Sep 17 00:00:00 2001 From: hama-matcha Date: Tue, 7 Jul 2020 21:06:42 +0900 Subject: [PATCH 6/6] (add) service yaml and gitignore --- .gitignore | 96 +++++++++++++++++++++++ demo/deployment/deployment-definition.yml | 4 +- demo/pod/pod-definition.yml | 2 +- demo/service/service-definition.yml | 14 ++++ lanch_kubeadm.sh | 5 ++ 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 demo/service/service-definition.yml create mode 100644 lanch_kubeadm.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00d13dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,96 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/windows,macos,linux,visualstudiocode,vagrant +# Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,linux,visualstudiocode,vagrant + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vagrant ### +# General +.vagrant/ + +# Log files (if you are creating logs in debug mode, uncomment this) +# *.log + +### Vagrant Patch ### +*.box + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/windows,macos,linux,visualstudiocode,vagrant \ No newline at end of file diff --git a/demo/deployment/deployment-definition.yml b/demo/deployment/deployment-definition.yml index 2e24f3a..51dba9b 100644 --- a/demo/deployment/deployment-definition.yml +++ b/demo/deployment/deployment-definition.yml @@ -14,9 +14,9 @@ spec: spec: containers: - name: nginx-container - image: nginx + image: nginx:1.18 - replicas: 5 + replicas: 6 selector: matchLabels: app: myapp diff --git a/demo/pod/pod-definition.yml b/demo/pod/pod-definition.yml index c56cab5..2aa3792 100644 --- a/demo/pod/pod-definition.yml +++ b/demo/pod/pod-definition.yml @@ -4,7 +4,7 @@ metadata: name: myapp-pod labels: app: myapp - tier: front-end + spec: containers: - name: nginx-container diff --git a/demo/service/service-definition.yml b/demo/service/service-definition.yml new file mode 100644 index 0000000..6a5c40c --- /dev/null +++ b/demo/service/service-definition.yml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: myapp-service + + +spec: + type: NodePort + ports: + - targetPort: 80 + port: 80 + nodePort: 30008 + selector: + app: myapp \ No newline at end of file diff --git a/lanch_kubeadm.sh b/lanch_kubeadm.sh new file mode 100644 index 0000000..c4cd320 --- /dev/null +++ b/lanch_kubeadm.sh @@ -0,0 +1,5 @@ +sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.33.41 +mkdir -p $HOME/.kube +sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config +sudo chown $(id -u):$(id -g) $HOME/.kube/config +kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml \ No newline at end of file