1
0

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 1 year has passed since last update.

Game of Pods攻略(Pento編)

Last updated at Posted at 2022-01-06

Game of Pods攻略~Pento~

FileServerの構築です。
ただK8sのAPIserverに一部エラー有り

Game of Pods関連のソースコードを挙げてます
https://github.com/hayama17/Game-of-Pods

作りたい環境

  • FileServer
    • NodePort
    • PVC
      • PV

動かない...

kubectlが動かない

controlplane $ kubectl get node
The connection to the server 172.17.0.44:6443 was refused - did you specify the right host or port?

controlplane $ kubectl api-resources 
NAME   SHORTNAMES   APIGROUP   NAMESPACED   KIND
The connection to the server 172.17.0.44:6443 was refused - did you specify the right host or port?

https://qiita.com/pnpnd1111/items/cac6f9f33a25de06e3e9
https://qiita.com/AseiSugiyama/items/8b10bf2c2968da6b9e2c
→config周りが怪しい or PortやIPアドレスが違う

確認したこと

ポート,IP

$ iptables -L --line-numbers

おかしい点は無かった

log

apiサーバーがおかしい事がクイズポータルから確認できるので、apiサーバーのコンテナを確認

$ docker ps -a |grep ap
## APIサーバーコンテナのIDを取得
$ docker logs コンテナID
...
Error: unable to load client CA file: open /etc/kubernetes/pki/ca-authority.crt: no such file or directory
...

証明書がないとエラーが出ているので証明書のあるディレクトリを確認

$ ls /etc/kubernetes/pki/
apiserver-etcd-client.crt     apiserver-kubelet-client.key  ca.crt  front-proxy-ca.crt      front-proxy-client.key
apiserver-etcd-client.key     apiserver.crt                 ca.key  front-proxy-ca.key      sa.key
apiserver-kubelet-client.crt  apiserver.key                 etcd    front-proxy-client.crt  sa.pub

ca-authority.crtは無くca.crtがあったのでこちらに書き換える

$ vi /etc/kubernetes/manifests/kube-apiserver.yaml

--client-ca-file=/etc/kubernetes/pki/ca-authority.crt
↓
--client-ca-file=/etc/kubernetes/pki/ca.crt

kubectlが動くようになった

$ kubectl get node
NAME           STATUS                     ROLES    AGE   VERSION
controlplane   Ready                      master   48m   v1.18.0
node01         Ready,SchedulingDisabled   <none>   48m   v1.18.0

coreDNSのimageを変更

kubeDNSからcoreDNSへ変更するためにコンテナのイメージを変える

$ kubectl -n kube-system edit deploy coredns

image: k8s.gcr.io/kubedns:1.3.1 
↓ 
image: k8s.gcr.io/coredns:1.6.7

Nodeの追加

nodeの状態が「SchedulingDisabled 」となっており、Podを作れないのでPodを作れる状態=スケジュールするようにする

$ kubectl uncordon node01

FileServerの構築

ほぼ前回と同じでPV→PVC→Pod→Serviceの流れで作る

PVとPVC

apiVersion: v1
kind: PersistentVolume
metadata:
  name: data-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: /web
    type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-pvc
spec:
  volumeName: data-pv
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

Pod

前回とほぼ同じ
NodePortを使いapp: gopのNodeを外部に公開する為書き込む

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: gop
  name: gop-fileserver
spec:
  containers:
    - name: gop
      image: kodekloud/fileserver
      ports:
        - containerPort: 8080
      volumeMounts:
        - name: data-store
          mountPath: /web
  volumes:
    - name: data-store
      persistentVolumeClaim:
        claimName: data-pvc

Service

NodePortを書けばいい

ホスト31200→Pod8080をつなげるように書く

apiVersion: v1
kind: Service
metadata: 
  name: gop-fs-service
spec:
  type: NodePort
  selector:
    app: gop
  ports:
    - name: gop-ports
      protocol: TCP
      nodePort: 31200
      targetPort: 8080
      port: 8080

参考文献

https://github.com/fdmsantos/game-of-pods-solutions/tree/master/Solutions/Pento%20-%20FileServer
答えだけど...

github

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?