LoginSignup
2
0

More than 1 year has passed since last update.

Power SystemsでもKubernetesを使う!

Last updated at Posted at 2019-11-27

Linux on Powerだとx86となにか違うの?

基本的にPowerでもx86と同じです。
ただ、当然ながらx86のイメージはPowerでは動かないので、アーキテクチャに合わせたイメージが必要になります。
その点だけ気をつければ、x86と同じように使えます。
なお、Power SystemsからインターネットへのアクセスにProxyが必要な環境で使っている皆様が多いかと思いますので、この記事ではProxyを使った手順をご紹介したいと思います。

構成

ここでは、1つのノードだけで動作するKubernetes(シングル・マスター・クラスター)をkubeadmコマンドを使って構成します。
わたしは以下の環境でトライしました。

OS: RHEL 7.9 LE
Memory: 4GB
CPU: 2コア (POWER8)
ストレージ: 50GB

Proxyの設定

とりあえず、.bashrcとか.bash_profileで以下の環境変数を設定しておきます。
自ノードへのアクセスのためにNO_PROXYをきちんと設定しておかないと、あとでハマります。

export http_proxy="http://10.91.0.1:8080"
export https_proxy="http://10.91.0.1:8080"
export ftp_proxy="http://10.91.0.1:8080"
export proxy="http://10.91.0.1:8080/"
export NO_PROXY="localhost,10.91.XX.XX"
export no_proxy="localhost,10.91.XX.XX"

また、/etc/rhsm/rhsm.confへ以下の設定を入れておきます。

# an http proxy server to use
proxy_hostname = 10.91.0.1

# The scheme to use for the proxy when updating repo definitions, if needed
# e.g. http or https
proxy_scheme = http

# port for http proxy server
proxy_port = 8080

Subscription登録

Dockerの導入にserver-extraとserver-optionalのレポジトリが必要になるので、subscription登録します。

subscription-manager register --username XXXXXX --autosubscribe

その後、追加レポジトリを有効化します。

subscription-manager repos --enable=rhel-7-server-extras-rpms
subscription-manager repos --enable=rhel-7-server-optional-rpms

/etc/hostsに自ホストを追加

自ホスト名が解決できるように、hostsに自ホストを追加しておきます。

10.91.XX.XX      k8snode

Dockerの導入

下記のRedHatのドキュメントを参考にDockerを入れました。

Getting Docker in RHEL 7
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_atomic_host/7/html-single/getting_started_with_containers/index#getting_docker_in_rhel_7

yum install docker device-mapper-libs device-mapper-event-libs
systemctl start docker.service
systemctl enable docker.service

DockerにもProxyの設定をしておきます。

mkdir -p /etc/systemd/system/docker.service.d
vi /etc/systemd/system/docker.service.d/http-proxy.conf
http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://10.91.0.1:8080/" "HTTPS_PROXY=http://10.91.0.1:8080/" "NO_PROXY=10.91.xx.xx/16"

docker daemonを再起動し、docker infoでプロキシーが設定されていることを確認します。

systemctl daemon-reload
systemctl restart docker
docker info

今更ですが、firewallは停止しておきます。
下記忘れましたが、SELinuxもpermissiveかdisableにしてます。

systemctl disable firewalld
systemctl stop firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

swapも無効にしておきます。

sudo swapoff -a

/etc/fstabの編集も忘れずに。

UUID=d06071e3-4760-4d1b-98d3-891566cbf0c3 / ext4 defaults 0 0
#/swap.img      none    swap    sw      0       0

Kubernetesの導入

Kubernetes導入のためのレポジトリを追加します。

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-ppc64le
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kube*
EOF

kubelet、kubeadm、kubectlを導入します。

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet

kubeadmを使ってkubernetesの構成を行います。
最初は、dry-runをしてエラーがないことを確認した後、本番にのぞみましょう。
"--pod-network-cidr="は、kubernetesクラスター内で使うCIDRを指定します。

kubeadm init --pod-network-cidr=192.168.0.0/16 --dry-run
kubeadm init --pod-network-cidr=192.168.0.0/16

成功すると、以下のような出力を得られます。
この情報は、後でKubernetesにアクセスするために使うので、大切に保存しておきます。

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 10.91.133.55:6443 --token 5yu18p.kf9k01j8ndzfbok4 \
    --discovery-token-ca-cert-hash sha256:d6e4c68bcc8347e71d946dbc7992c474c17170ce262cc9fa36b3dc980cd887f1

早速、kubernetesにadminでアクセスするために、~/.kube/configをコピーしてきます。

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

初期状態では、マスターノードにはPodが置かれないようにtaintされているため、taintを解除します。

kubectl get node
kubectl describe node <自ノード>
kubectl taint nodes <自ノード> node-role.kubernetes.io/master:NoSchedule-

以上でkubernetesの導入を完了しました。

Calicoの導入

複数ノードで使うときは、CNIを導入する必要があります。
以下にCalicoを導入したときの手順を紹介します。

curl https://docs.projectcalico.org/manifests/calico.yaml -O
kubectl apply -f calico.yaml

参考文献

kubeadmを使用したシングルマスタークラスターの作成
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

Creating a single master cluster with kubeadm
https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

Install Calico for on-premises deployments
https://docs.projectcalico.org/getting-started/kubernetes/self-managed-onprem/onpremises

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