Oracle Linux Container Services for use with Kubernetes
https://blogs.oracle.com/linux/announcing-oracle-linux-container-services-for-use-with-kubernetes
すでにマニュアルも用意されています。
上記のアナウンスの直前に、Yum に配置されている Kubernetes が更新
(v1.6 → v1.7)されていたのですが、ドキュメントにも一応反映されているようです。
Oracle Linux 7
Oracle Linux Container Services for use with Kubernetes User's Guide
https://docs.oracle.com/cd/E52668_01/E88884/html/index.html
ということで、さっそくインストールしてみました。
Oracle の Kubernetes の特徴としては・・・
- セットアップでは kubeadm / kubeadm-setup.sh を利用します。
- kubeadm で利用する Kubernetes の Docker コンテナは、デフォルトでは Oracle Container Registry からダウンロードされます。
ちなみに Oracle Container Registry では、「Container Services」(日本語を選択すると Kubernetes に・・・)のリポジトリが用意されています。
今回のサーバ構成。
OS は、すべて Oracle Linux 7.4 です。
下記の3台構成にします。
- Master: k8s-master.go-lab.jp / 192.168.1.120
- Worker#1:k8s-work-01.go-lab.jp / 192.168.1.121
- Worker#2:k8s-work-02.go-lab.jp / 192.168.1.122
OS の準備。
Master / Worker すべてのサーバで、下記の OS セットアップをしておきます。
ホスト名、ネットワーク設定をします。
今回、各ノードのホスト名は既にラボ内の DNS で名前解決できるようにしてあります。
(各パラメータは自宅ラボ ネットワーク構成のもの)
[root@localhost ~]# hostnamectl set-hostname k8s-master
[root@localhost ~]# nmcli c modify ens192 ipv4.addresses 192.168.1.120/24
[root@localhost ~]# nmcli c modify ens192 ipv4.gateway 192.168.1.1
[root@localhost ~]# nmcli c modify ens192 ipv4.dns 192.168.1.254,192.168.1.253
[root@localhost ~]# nmcli c modify ens192 ipv4.dns-search go-lab.jp
[root@localhost ~]# nmcli c modify ens192 ipv4.method manual
Worker Node #1
[root@localhost ~]# hostnamectl set-hostname k8s-worker-01
[root@localhost ~]# nmcli c modify ens192 ipv4.addresses 192.168.1.121/24
~
Worker Node #2
[root@localhost ~]# hostnamectl set-hostname k8s-worker-02
[root@localhost ~]# nmcli c modify ens192 ipv4.addresses 192.168.1.122/24
~
SELinux は permissive にしてしまいます。
[root@localhost ~]# sed -i -e "s/^SELINUX=.*/SELINUX=permissive/" /etc/selinux/config
[root@localhost ~]# grep -v -E "^#|^$" /etc/selinux/config
SELINUX=permissive
SELINUXTYPE=targeted
Yum リポジトリを設定します。
最新のリポジトリ設定ファイルをダウンロードして ol7_preview と ol7_addons を有効化します。
ただし Oracle Container Services Kubernetes 1.1.9 から Yumリポジトリが
ol7_preview → ol7_addons になりました。
ということで下記の「--enable ol7_preview」は不要になります。
[root@localhost ~]# curl http://yum.oracle.com/public-yum-ol7.repo -o /etc/yum.repos.d/public-yum-ol7.repo
[root@localhost ~]# yum upgrade -y
[root@localhost ~]# yum install -y yum-utils
[root@localhost ~]# yum-config-manager --enable ol7_preview
[root@localhost ~]# yum-config-manager --enable ol7_addons
iptables を設定します。
[root@localhost ~]# iptables -P FORWARD ACCEPT
[root@localhost ~]# iptables-save > /etc/sysconfig/iptables
[root@localhost ~]# firewall-cmd --add-masquerade --permanent
[root@localhost ~]# firewall-cmd --add-port=10250/tcp --permanent
[root@localhost ~]# firewall-cmd --add-port=8472/udp --permanent
Docker をインストール、起動しておきます。
[root@localhost ~]# yum install -y docker-engine
[root@localhost ~]# systemctl enable docker
[root@localhost ~]# systemctl start docker
Oracle Container Registry にログインしておきます。
※これは、事前に下記でアカウント登録しておく必要があります。
https://container-registry.oracle.com/
[root@localhost ~]# docker login container-registry.oracle.com
Username: ★アカウント(メールアドレス)を入力
Password: ★パスワードを入力
Login Succeeded
kubeadm をインストールします。
[root@localhost ~]# yum install -y kubeadm
kubeadm-setup.sh は、この RPM に含まれています。
[root@localhost ~]# which kubeadm-setup.sh
/usr/bin/kubeadm-setup.sh
[root@localhost ~]# rpm -qf /usr/bin/kubeadm-setup.sh
kubeadm-1.7.4-2.0.1.el7.x86_64
[root@localhost ~]# rpm -ql kubeadm
/etc/sysctl.d/k8s.conf
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
/usr/bin/kubeadm
/usr/bin/kubeadm-setup.sh
/usr/local/share/kubeadm/flannel-ol.yaml
/usr/share/licenses/kubeadm-1.7.4
/usr/share/licenses/kubeadm-1.7.4/LICENSE
[root@localhost ~]#
OS を再起動してきます。
[root@localhost ~]# reboot
Master Node のセットアップ。
Master Node だけ、下記のポートを開放しておきます。
[root@k8s-master ~]# firewall-cmd --add-port=6443/tcp --permanent
[root@k8s-master ~]# firewall-cmd --add-port=6443/tcp
kubeadm-setup.sh の実行。
[root@k8s-master ~]# kubeadm-setup.sh up
Checking if env is ready ...
Checking whether docker can pull busybox image ...
Checking access to container-registry.oracle.com/kubernetes ...
3.0: Pulling from kubernetes/pause-amd64
Digest: sha256:9f9003ed856139e91d6fbd41a7ad71badd8ec0f3adca6ee0345aef4502f58923
Status: Image is up to date for container-registry.oracle.com/kubernetes/pause-amd64:3.0
Checking whether docker can run container ...
Checking firewalld settings ...
Checking iptables default rule ...
Checking br_netfilter module ...
Checking sysctl variables ...
Check successful, ready to run 'up' command ...
Enabling kubelet ...
Waiting for kubeadm to setup master cluster...
...............
clusterrole "flannel" created
clusterrolebinding "flannel" created
serviceaccount "flannel" created
configmap "kube-flannel-cfg" created
daemonset "kube-flannel-ds" created
[preflight] WARNING: firewalld is active, please ensure ports [6443 10250] are open or your cluster may not function correctly
[kubeadm] WARNING: starting in 1.8, tokens expire after 24 hours by default (if you require a non-expiring token use --token-ttl 0)
[===> PLEASE DO THE FOLLOWING STEPS BELOW: <===]
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run (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 can now join any number of machines by running the following on each node
as root:
kubeadm-setup.sh join --token 0c7672.5171a2cf0548196b 192.168.1.120:6443
[root@k8s-master ~]#
Kubernetes 操作むけに一般ユーザを作成して、sudo できるようにしておきます。
[root@k8s-master ~]# useradd kubeuser
[root@k8s-master ~]# echo 'kubeuser ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/kubeuser
[root@k8s-master ~]# su - kubeuser
Kubernetes の設定を読み込むように設定しておきます。
[kubeuser@k8s-master ~]$ sudo cp /etc/kubernetes/admin.conf $HOME/
[kubeuser@k8s-master ~]$ sudo chown $(id -u):$(id -g) $HOME/admin.conf
[kubeuser@k8s-master ~]$ ls -l $HOME/admin.conf
-rw-------. 1 root root 5453 9月 20 08:19 /root/admin.conf
[kubeuser@k8s-master ~]$ export KUBECONFIG=$HOME/admin.conf
[kubeuser@k8s-master ~]$ echo 'export KUBECONFIG=$HOME/admin.conf' >> $HOME/.bashrc
Master Node の様子が見えます。
[root@k8s-master ~]# kubectl get nodes
NAME STATUS AGE VERSION
k8s-master Ready 3m v1.7.4+0c1a5fc
Worker Node のセットアップ。
kubeadm-setup.sh join ~ で、Worker Node をクラスタに Join させます。
Worker Node #1
[root@k8s-worker-01 ~]# kubeadm-setup.sh join --token 0c7672.5171a2cf0548196b 192.168.1.120:6443
Checking if env is ready ...
Checking whether docker can pull busybox image ...
Checking access to container-registry.oracle.com/kubernetes ...
3.0: Pulling from kubernetes/pause-amd64
Digest: sha256:9f9003ed856139e91d6fbd41a7ad71badd8ec0f3adca6ee0345aef4502f58923
Status: Image is up to date for container-registry.oracle.com/kubernetes/pause-amd64:3.0
Checking whether docker can run container ...
Checking firewalld settings ...
Checking iptables default rule ...
Checking br_netfilter module ...
Checking sysctl variables ...
Check successful, ready to run 'join' command ...
Enabling kubelet ...
[preflight] Running pre-flight checks
[preflight] Starting the kubelet service
[discovery] Trying to connect to API Server "192.168.1.120:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.1.120:6443"
[discovery] Cluster info signature and contents are valid, will use API Server "https://192.168.1.120:6443"
[discovery] Successfully established connection with API Server "192.168.1.120:6443"
[bootstrap] Detected server version: v1.7.4+0c1a5fc
[bootstrap] The server supports the Certificates API (certificates.k8s.io/v1beta1)
[csr] Created API client to obtain unique certificate for this node, generating keys and certificate signing request
[csr] Received signed certificate from the API server, generating KubeConfig...
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"
Node join complete:
* Certificate signing request sent to master and response
received.
* Kubelet informed of new secure connection details.
Run 'kubectl get nodes' on the master to see this machine join.
[root@k8s-worker-01 ~]#
Mater Node でも Worker Node が Join できたことを確認できます。
※STATUS が NotReady の時は少し待つと Ready になります。
[root@k8s-master ~]# kubectl get nodes
NAME STATUS AGE VERSION
k8s-master Ready 6m v1.7.4+0c1a5fc
k8s-worker-01 Ready 41s v1.7.4+0c1a5fc
Worker Node #2 も同様に join します。
[root@k8s-worker-02 ~]# kubeadm-setup.sh join --token 0c7672.5171a2cf0548196b 192.168.1.120:6443
Master Node でも Worker Node #2 が参加できたことを確認できます。
[root@k8s-master ~]# kubectl get nodes
NAME STATUS AGE VERSION
k8s-master Ready 8m v1.7.4+0c1a5fc
k8s-worker-01 Ready 3m v1.7.4+0c1a5fc
k8s-worker-02 Ready 2m v1.7.4+0c1a5fc
様子を見る。
kubeadm により、Kubernetes コンポーネントの Docker コンテナが起動しています。
Master Node
[kubeuser@k8s-master ~]$ kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
etcd-k8s-master 1/1 Running 0 20m
kube-apiserver-k8s-master 1/1 Running 0 20m
kube-controller-manager-k8s-master 1/1 Running 0 20m
kube-dns-910383606-hp34j 3/3 Running 0 21m
kube-flannel-ds-cc3v1 2/2 Running 0 16m
kube-flannel-ds-cmnc1 2/2 Running 0 21m
kube-flannel-ds-jjvw7 2/2 Running 0 15m
kube-proxy-2j0t7 1/1 Running 0 21m
kube-proxy-d7cvz 1/1 Running 0 16m
kube-proxy-jp3rr 1/1 Running 0 15m
kube-scheduler-k8s-master 1/1 Running 0 20m
[kubeuser@k8s-master ~]$
実際に起動されてたコンテナの様子です。
[root@k8s-master ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4be71deeea45 container-registry.oracle.com/kubernetes/k8s-dns-sidecar-amd64@sha256:4367c60e50188d3304b03ff2bf4e36f7103a6528df06f1d8adb00b035fe437d4 "/sidecar --v=2 --..." 12 minutes ago Up 12 minutes k8s_sidecar_kube-dns-910383606-hp34j_kube-system_c293ccfd-9d90-11e7-99d6-0050568a21da_0
d967ed8912f8 container-registry.oracle.com/kubernetes/k8s-dns-dnsmasq-nanny-amd64@sha256:d6026a5bd4e14f38804b6589e185d90f475eb1491b51e318be055f81ebcc9773 "/dnsmasq-nanny -v..." 12 minutes ago Up 12 minutes k8s_dnsmasq_kube-dns-910383606-hp34j_kube-system_c293ccfd-9d90-11e7-99d6-0050568a21da_0
9fcca4a82db1 container-registry.oracle.com/kubernetes/k8s-dns-kube-dns-amd64@sha256:dd0ee0412a0def4487fe40ccfa776a2efd77074c819c7bb230663ae81fdc781f "/kube-dns --domai..." 12 minutes ago Up 12 minutes k8s_kubedns_kube-dns-910383606-hp34j_kube-system_c293ccfd-9d90-11e7-99d6-0050568a21da_0
6c478109cfe8 container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 12 minutes ago Up 12 minutes k8s_POD_kube-dns-910383606-hp34j_kube-system_c293ccfd-9d90-11e7-99d6-0050568a21da_0
fa962f2570d5 container-registry.oracle.com/kubernetes/flannel@sha256:ca39c889256e8f2e54981e81e3e03696cf40f4c123843d7297bd97ba5217e6b0 "/bin/sh -c 'set -..." 12 minutes ago Up 12 minutes k8s_install-cni_kube-flannel-ds-cmnc1_kube-system_c4420273-9d90-11e7-99d6-0050568a21da_0
e00fae4d16ae container-registry.oracle.com/kubernetes/flannel@sha256:ca39c889256e8f2e54981e81e3e03696cf40f4c123843d7297bd97ba5217e6b0 "/opt/bin/flanneld..." 12 minutes ago Up 12 minutes k8s_kube-flannel_kube-flannel-ds-cmnc1_kube-system_c4420273-9d90-11e7-99d6-0050568a21da_0
c2a4bf1eea76 container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 12 minutes ago Up 12 minutes k8s_POD_kube-flannel-ds-cmnc1_kube-system_c4420273-9d90-11e7-99d6-0050568a21da_0
084beb1a0172 container-registry.oracle.com/kubernetes/kube-proxy-amd64@sha256:5a15f773217a2485729306c160226021358a01e37b187c1bf01660c38ae3bab6 "/usr/local/bin/ku..." 12 minutes ago Up 12 minutes k8s_kube-proxy_kube-proxy-2j0t7_kube-system_c2913cfa-9d90-11e7-99d6-0050568a21da_0
8ee20c4ebe8a container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 12 minutes ago Up 12 minutes k8s_POD_kube-proxy-2j0t7_kube-system_c2913cfa-9d90-11e7-99d6-0050568a21da_0
04dca852a385 container-registry.oracle.com/kubernetes/etcd-amd64@sha256:711659e03dc79d7e80e9b25b08d5035a34b7a80b8a29561cb5c42cb5e32ea03a "etcd --listen-cli..." 13 minutes ago Up 13 minutes k8s_etcd_etcd-k8s-master_kube-system_4fff05d7dcf615c353194e3e3a3d6a6f_0
1797a2bc3383 container-registry.oracle.com/kubernetes/kube-apiserver-amd64@sha256:cc9b4c552950e06a12459db4bc7901942b7f5e423bacd8aba7c8a38f742856c7 "kube-apiserver --..." 13 minutes ago Up 13 minutes k8s_kube-apiserver_kube-apiserver-k8s-master_kube-system_34b082fbb289cf80e85e5c4a493fc6a4_0
67ca14973ad0 container-registry.oracle.com/kubernetes/kube-controller-manager-amd64@sha256:44cffa6eeb34b2810a1a323f8744220a02d3ef0dd568248c7ba0b65b0ce70e7b "kube-controller-m..." 13 minutes ago Up 13 minutes k8s_kube-controller-manager_kube-controller-manager-k8s-master_kube-system_19d2936dc4c6b64a615920083b578d4a_0
4760bbfc9338 container-registry.oracle.com/kubernetes/kube-scheduler-amd64@sha256:6a63eda9726194e69034ecc10e24572479981d3252190a42e97752a24202a5ee "kube-scheduler --..." 13 minutes ago Up 13 minutes k8s_kube-scheduler_kube-scheduler-k8s-master_kube-system_929ca32de88fbd58488e4baad5a4b6a7_0
470d0b6bd5a5 container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 13 minutes ago Up 13 minutes k8s_POD_kube-controller-manager-k8s-master_kube-system_19d2936dc4c6b64a615920083b578d4a_0
88ab36657dbe container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 13 minutes ago Up 13 minutes k8s_POD_etcd-k8s-master_kube-system_4fff05d7dcf615c353194e3e3a3d6a6f_0
7fbbf114099f container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 13 minutes ago Up 13 minutes k8s_POD_kube-apiserver-k8s-master_kube-system_34b082fbb289cf80e85e5c4a493fc6a4_0
500a2c04a386 container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 13 minutes ago Up 13 minutes k8s_POD_kube-scheduler-k8s-master_kube-system_929ca32de88fbd58488e4baad5a4b6a7_0
[root@k8s-master ~]#
Worker Node #1
[root@k8s-worker-01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cda7734d8939 container-registry.oracle.com/kubernetes/flannel@sha256:ca39c889256e8f2e54981e81e3e03696cf40f4c123843d7297bd97ba5217e6b0 "/bin/sh -c 'set -..." 7 minutes ago Up 7 minutes k8s_install-cni_kube-flannel-ds-cc3v1_kube-system_7185efd1-9d91-11e7-99d6-0050568a21da_0
814f5bd37b09 container-registry.oracle.com/kubernetes/kube-proxy-amd64@sha256:5a15f773217a2485729306c160226021358a01e37b187c1bf01660c38ae3bab6 "/usr/local/bin/ku..." 7 minutes ago Up 7 minutes k8s_kube-proxy_kube-proxy-d7cvz_kube-system_7185e3db-9d91-11e7-99d6-0050568a21da_0
3266487806bd container-registry.oracle.com/kubernetes/flannel@sha256:ca39c889256e8f2e54981e81e3e03696cf40f4c123843d7297bd97ba5217e6b0 "/opt/bin/flanneld..." 7 minutes ago Up 7 minutes k8s_kube-flannel_kube-flannel-ds-cc3v1_kube-system_7185efd1-9d91-11e7-99d6-0050568a21da_0
597005b57c30 container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 7 minutes ago Up 7 minutes k8s_POD_kube-flannel-ds-cc3v1_kube-system_7185efd1-9d91-11e7-99d6-0050568a21da_0
c634fdd50e4c container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 7 minutes ago Up 7 minutes k8s_POD_kube-proxy-d7cvz_kube-system_7185e3db-9d91-11e7-99d6-0050568a21da_0
[root@k8s-worker-01 ~]#
Worker Node #2
[root@k8s-worker-02 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
755b9195ab20 container-registry.oracle.com/kubernetes/flannel@sha256:ca39c889256e8f2e54981e81e3e03696cf40f4c123843d7297bd97ba5217e6b0 "/bin/sh -c 'set -..." 11 minutes ago Up 11 minutes k8s_install-cni_kube-flannel-ds-jjvw7_kube-system_928d24cf-9d91-11e7-99d6-0050568a21da_0
c4f1368fefa8 container-registry.oracle.com/kubernetes/flannel@sha256:ca39c889256e8f2e54981e81e3e03696cf40f4c123843d7297bd97ba5217e6b0 "/opt/bin/flanneld..." 11 minutes ago Up 11 minutes k8s_kube-flannel_kube-flannel-ds-jjvw7_kube-system_928d24cf-9d91-11e7-99d6-0050568a21da_0
36b5228a3e40 container-registry.oracle.com/kubernetes/kube-proxy-amd64@sha256:5a15f773217a2485729306c160226021358a01e37b187c1bf01660c38ae3bab6 "/usr/local/bin/ku..." 11 minutes ago Up 11 minutes k8s_kube-proxy_kube-proxy-jp3rr_kube-system_928d198f-9d91-11e7-99d6-0050568a21da_0
8c92e31298c1 container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 11 minutes ago Up 11 minutes k8s_POD_kube-flannel-ds-jjvw7_kube-system_928d24cf-9d91-11e7-99d6-0050568a21da_0
8920a3b4f705 container-registry.oracle.com/kubernetes/pause-amd64:3.0 "/pause" 11 minutes ago Up 11 minutes k8s_POD_kube-proxy-jp3rr_kube-system_928d198f-9d91-11e7-99d6-0050568a21da_0
[root@k8s-worker-02 ~]#
まずはいきおいでセットアップしてみました。続く・・・
Oracle Linux 7 の Kubernetes で kubectl Basics。
kubectl 実行例の投稿へのリンクを追記しました。
返信削除Oracle Container Services Kubernetes 1.1.9 で Yumリポジトリが
返信削除ol7_preview → ol7_addons になりました。
http://gowatana.blogspot.jp/2018/03/oracle-k8s119.html