Closed9
MicroK8sの独習5 〜Persistent Volumeを使用したWordpressとMySQLをデプロイする〜
次はこれやけどなんか警告大量に書かれてて萎えるな。。。
本番では使うなとか。。。
まぁいいやとりあえずクラスタ初期化しよ
この手順もだいぶ馴染んできたなk8s関係ないけど
$ seq 4 | xargs -n1 -P4 -I{} lxc restore mk8s{} snap0
$ microk8s status --wait-ready
microk8s is running
high-availability: yes
datastore master nodes: 10.116.214.136:19001 10.116.214.122:19001 10.116.214.107:19001
datastore standby nodes: 10.116.214.248:19001
addons:
enabled:
ha-cluster # Configure high availability on the current node
disabled:
ambassador # Ambassador API Gateway and Ingress
cilium # SDN, fast with full network policy
dashboard # The Kubernetes dashboard
dns # CoreDNS
fluentd # Elasticsearch-Fluentd-Kibana logging and monitoring
gpu # Automatic enablement of Nvidia CUDA
helm # Helm 2 - the package manager for Kubernetes
helm3 # Helm 3 - Kubernetes package manager
host-access # Allow Pods connecting to Host services smoothly
ingress # Ingress controller for external access
istio # Core Istio service mesh services
jaeger # Kubernetes Jaeger operator with its simple config
keda # Kubernetes-based Event Driven Autoscaling
knative # The Knative framework on Kubernetes.
kubeflow # Kubeflow for easy ML deployments
linkerd # Linkerd is a service mesh for Kubernetes and other frameworks
metallb # Loadbalancer for your Kubernetes cluster
metrics-server # K8s Metrics Server for API access to service metrics
multus # Multus CNI enables attaching multiple network interfaces to pods
portainer # Portainer UI for your Kubernetes cluster
prometheus # Prometheus operator for monitoring and logging
rbac # Role-Based Access Control for authorisation
registry # Private image registry exposed on localhost:32000
storage # Storage class; allocates storage from host directory
traefik # traefik Ingress controller for external access
$ kubectl get pods
No resources found in default namespace.
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
mk8s3 Ready <none> 6h39m v1.20.5-34+40f5951bd9888a
mk8s1 Ready <none> 5d3h v1.20.5-34+40f5951bd9888a
mk8s4 Ready <none> 6h38m v1.20.5-34+40f5951bd9888a
mk8s2 Ready <none> 6h41m v1.20.5-34+40f5951bd9888a
ここまで使ってきたアドオンは全部有効にしとこう
$ microk8s enable metallb dns storage
Enabling MetalLB
Enter each IP address range delimited by comma (e.g. '10.64.140.43-10.64.140.49,192.168.0.105-192.168.0.111'): 10.116.214.2-10.116.214.99
Applying Metallb manifest
namespace/metallb-system created
secret/memberlist created
podsecuritypolicy.policy/controller created
podsecuritypolicy.policy/speaker created
serviceaccount/controller created
serviceaccount/speaker created
clusterrole.rbac.authorization.k8s.io/metallb-system:controller created
clusterrole.rbac.authorization.k8s.io/metallb-system:speaker created
role.rbac.authorization.k8s.io/config-watcher created
role.rbac.authorization.k8s.io/pod-lister created
clusterrolebinding.rbac.authorization.k8s.io/metallb-system:controller created
clusterrolebinding.rbac.authorization.k8s.io/metallb-system:speaker created
rolebinding.rbac.authorization.k8s.io/config-watcher created
rolebinding.rbac.authorization.k8s.io/pod-lister created
daemonset.apps/speaker created
deployment.apps/controller created
configmap/config created
MetalLB is enabled
Enabling DNS
Applying manifest
serviceaccount/coredns created
configmap/coredns created
deployment.apps/coredns created
service/kube-dns created
clusterrole.rbac.authorization.k8s.io/coredns created
clusterrolebinding.rbac.authorization.k8s.io/coredns created
Restarting kubelet
Adding argument --cluster-domain to nodes.
Configuring node 10.116.214.107
Configuring node 10.116.214.136
Configuring node 10.116.214.248
Configuring node 10.116.214.122
Adding argument --cluster-dns to nodes.
Configuring node 10.116.214.107
Configuring node 10.116.214.136
Configuring node 10.116.214.122
Configuring node 10.116.214.248
Restarting nodes.
Configuring node 10.116.214.107
Configuring node 10.116.214.136
Configuring node 10.116.214.248
Configuring node 10.116.214.122
DNS is enabled
Enabling default storage class
deployment.apps/hostpath-provisioner created
storageclass.storage.k8s.io/microk8s-hostpath created
serviceaccount/microk8s-hostpath created
clusterrole.rbac.authorization.k8s.io/microk8s-hostpath created
clusterrolebinding.rbac.authorization.k8s.io/microk8s-hostpath created
Storage will be available soon
$ lxc shell mk8s1
root@mk8s1:~# cat <<EOF >./kustomization.yaml
> secretGenerator:
> - name: mysql-pass
> literals:
> - password=YOUR_PASSWORD
> EOF
root@mk8s1:~# curl -LO https://k8s.io/examples/application/wordpress/mysql-deployment.yaml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 839 0 --:--:-- --:--:-- --:--:-- 839
100 1193 100 1193 0 0 1881 0 --:--:-- --:--:-- --:--:-- 7364
root@mk8s1:~# curl -LO https://k8s.io/examples/application/wordpress/wordpress-deployment.yaml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 1085 0 --:--:-- --:--:-- --:--:-- 1092
100 1278 100 1278 0 0 1887 0 --:--:-- --:--:-- --:--:-- 1887
root@mk8s1:~# cat <<EOF >>./kustomization.yaml
> resources:
> - mysql-deployment.yaml
> - wordpress-deployment.yaml
> EOF
root@mk8s1:~# kubectl apply -k ./
secret/mysql-pass-c57bb4t7mf created
service/wordpress-mysql created
service/wordpress created
deployment.apps/wordpress-mysql created
deployment.apps/wordpress created
persistentvolumeclaim/mysql-pv-claim created
persistentvolumeclaim/wp-pv-claim created
root@mk8s1:~# kubectl get secrets
NAME TYPE DATA AGE
default-token-84sxx kubernetes.io/service-account-token 3 5d3h
mysql-pass-c57bb4t7mf Opaque 1 19s
root@mk8s1:~# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
wp-pv-claim Bound pvc-2ecc507b-6acf-4a6b-832e-934813984495 20Gi RWO microk8s-hostpath 39s
mysql-pv-claim Bound pvc-6ffe91b2-92f9-42a1-9cce-ad7f23a94ba0 20Gi RWO microk8s-hostpath 39s
root@mk8s1:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
wordpress-mysql-66d69866f6-p98ll 1/1 Running 0 3m13s
wordpress-578dd85b66-pvnjl 1/1 Running 1 3m13s
root@mk8s1:~# kubectl get services wordpress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer 10.152.183.109 10.116.214.2 80:31034/TCP 3m32s
拍子抜けするぐらい手順通りでうごきましたわ
逆に怪しい🤔
ここで重要なのはkustomization.yamlとかいうので色々まとめて適用できるってことなんかな
docker-compose.ymlみたいなもんなか
ふむふむkustomization.yamlの
secretGeneratorとかいうのでmysql用のパスワードを生成してるのね
それをmysqlとwordpressそれぞれに
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
って形で渡してると
でそれをWPはDBに繋ぐ時にパスワードとして使ってますよってこっちゃね
とりあえず最初にアドオン全部入れたけどこれ多分全部使ってるな
storageないとデプロイでこけるやろうし
dns無いとwpからmysql名前解決出来ないやろうし
metalLB無いとブラウザ確認できなかったやろうし
なんとなく有効化したけど正解やったな
あんまり見る所無いなこのチュートリアルとりあえずクローズしよう
このスクラップは2021/04/21にクローズされました