{"id":367,"date":"2020-04-28T09:51:13","date_gmt":"2020-04-28T07:51:13","guid":{"rendered":"http:\/\/blog.xoupix.fr\/?p=367"},"modified":"2020-05-05T10:56:54","modified_gmt":"2020-05-05T08:56:54","slug":"installing-okd-on-centos","status":"publish","type":"post","link":"https:\/\/blog.xoupix.fr\/index.php\/2020\/04\/28\/installing-okd-on-centos\/","title":{"rendered":"Installing OKD on CentOS"},"content":{"rendered":"\n<p>Let&#8217;s see how to install OKD on a CentOS virtual machine !<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">What is OKD?<\/h2>\n\n\n\n<p>OKD is a&nbsp;<strong>distribution of Kubernetes<\/strong>&nbsp;optimized for continuous application development and multi-tenant deployment. OKD adds&nbsp;<strong>developer and operations-centric<\/strong>&nbsp;tools on top of Kubernetes to enable rapid application development, easy deployment and scaling, and long-term lifecycle maintenance for small and large teams. OKD is the upstream Kubernetes distribution embedded in Red Hat OpenShift.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing OKD on CentOS<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<p>Swap should be disabled.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating the docker user<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfunction prerequisites(){\n\tif &#91; \"$(id -u)\" != \"0\" ]; then\n\t\techo \"This script must be run as root\"\n\t\texit 1\n\tfi\n\t\n\t&#91;&#91; -z ${DOCKER_USER} ]] &amp;&amp; { echo \"DOCKER_USER is not set or empty\"; exit 1; }\n\t&#91;&#91; -z ${DOCKER_PASSWORD} ]] &amp;&amp; { echo \"DOCKER_PASSWORD is not set or empty\"; exit 1; }\n}\n\nfunction create_user(){\n\t\n\tid -u ${DOCKER_USER} 2>&amp;1 1>\/dev\/null\n\t\n\tif &#91; $? -ne 0 ] ; then\n\t\t# Adding docker user\n\t\tuseradd ${DOCKER_USER}\n\t\techo ${DOCKER_PASSWORD} | passwd --stdin ${DOCKER_USER}\n\telse\n\t\techo \"The user ${DOCKER_USER} already exist\"\n\tfi\n}\n\nprerequisites\ncreate_user<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Updating CentOS virtual machine and install Docker<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfunction prerequisites(){\n\tif &#91; \"$(id -u)\" != \"0\" ]; then\n\t\techo \"This script must be run as root\"\n\t\texit 1\n\tfi\n\t\n\t&#91;&#91; -z ${YUM_UPDATE} ]] &amp;&amp; { echo \"YUM_UPDATE is not set or empty\"; exit 1; }\n}\n\nfunction install_docker(){\n\t\n\tif &#91; ${YUM_UPDATE} -eq 1 ] ; then\n\t\tyum -y update\n\tfi\n\t\n\tyum install -y yum-utils device-mapper-persistent-data lvm2 wget\n\tyum-config-manager --add-repo https:\/\/download.docker.com\/linux\/centos\/docker-ce.repo\n\tyum install -y  docker-ce docker-ce-cli containerd.io\n}\n\nprerequisites\ninstall_docker<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring Docker<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfunction prerequisites(){\n\tif &#91; \"$(id -u)\" != \"0\" ]; then\n\t\techo \"This script must be run as root\"\n\tfi\n\t\n\t&#91;&#91; -z ${DOCKER_USER} ]] &amp;&amp; { echo \"DOCKER_USER is not set or empty\"; exit 1; }\n}\n\nfunction configure_docker(){\n\t\n\t# Adding Docker user to docker group\n\tusermod -aG docker ${DOCKER_USER}\n\t\n\t# Creating docker directories\n\tmkdir -p \/etc\/docker \/etc\/containers\n\t\n\ttee \/etc\/containers\/registries.conf&lt;&lt;EOF\n&#91;registries.insecure]\nregistries = &#91;'172.30.0.0\/16']\nEOF\n\n\ttee \/etc\/docker\/daemon.json&lt;&lt;EOF\n{\n   \"insecure-registries\": &#91;\n     \"172.30.0.0\/16\"\n   ]\n}\nEOF\n\n\t# Reloading and restarting Docker daemon\n\tsystemctl daemon-reload\n\tsystemctl restart docker\n\n\t# Enabling Docker to start at boot\n\tsystemctl enable docker\n}\n\nprerequisites\nconfigure_docker<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring firewall and network<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfunction prerequisites(){\n\tif &#91; \"$(id -u)\" != \"0\" ]; then\n\t\techo \"This script must be run as root\"\n\t\texit 1\n\tfi\n}\n\nfunction configure_firewall_and_network(){\t\n\t# Enabling port forwarding\n\ttee -a \/etc\/sysctl.conf&lt;&lt;EOF\nnet.ipv4.ip_forward = 1\nEOF\n\tsysctl -p\n\n\t# Configuring Firewalld\n\tDOCKER_BRIDGE=$(docker network inspect -f \"{{range .IPAM.Config }}{{ .Subnet }}{{end}}\" bridge)\n\t# Firewalld for dockerc zone (internal access)\n\tfirewall-cmd --get-active-zones | grep dockerc 2>&amp;1 1>\/dev\/null\n\tif &#91; $? -ne 0 ] ; then \n\t\tfirewall-cmd --permanent --new-zone dockerc\n\t\tfirewall-cmd --permanent --zone dockerc --add-source ${DOCKER_BRIDGE}\n\t\tfirewall-cmd --permanent --zone dockerc --add-port={80,443,8443}\/tcp\n\t\tfirewall-cmd --permanent --zone dockerc --add-port={53,8053}\/udp\n\t\t# Firewalld for public zone (external access)\n\t\tfirewall-cmd --permanent --zone public --add-port={80,443,8443}\/tcp\n\t\tfirewall-cmd --reload\n\tfi\n}\n\nprerequisites\nconfigure_firewall_and_network<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Installing OpenShift<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfunction prerequisites(){\n\tif &#91; \"$(id -u)\" != \"0\" ]; then\n\t\techo \"This script must be run as root\"\n\t\texit 1\n\tfi\n}\n\nfunction install_openshift(){\n\tif &#91; \"$(id -u)\" != \"0\" ]; then\n\t\techo \"This script must be run as root\"\n\tfi\n\t\n\tif &#91; ! -z ${OPENSHIFT_LOCAL_ARCHIVE} ] ; then\n\t\tOPENSHIFT_ARCHIVE_NAME=$(basename ${OPENSHIFT_LOCAL_ARCHIVE})\n\t\tif &#91; ! -f \"${OPENSHIFT_ARCHIVE_NAME}\" ] ; then\n\t\t\tif &#91; ! -f \"${OPENSHIFT_LOCAL_ARCHIVE}\" ] ; then\n\t\t\t\twget -O ${OPENSHIFT_ARCHIVE_NAME} ${OPENSHIFT_GITHUB_ARCHIVE}\n\t\t\telse\n\t\t\t\tcp -f ${OPENSHIFT_LOCAL_ARCHIVE} ${OPENSHIFT_ARCHIVE_NAME}\n\t\t\tfi\n\t\tfi\n\t\t\n\t\ttar xvf ${OPENSHIFT_ARCHIVE_NAME}\n\t\tcd openshift-origin-client*\/\n\t\tmv oc kubectl \/usr\/local\/bin\/\n\telse\n\t\tyum -y install centos-release-openshift-origin\n\t\tyum -y install origin-clients\n\tfi\n}\n\nprerequisites\ninstall_openshift<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring OpenShift<\/h3>\n\n\n\n<p>This script must be executed as non-root user. Because I ran this script many times, my download speed from docker was really slow. I saved the OpenShift docker images locally (using <em>docker save myimage:latest | gzip &gt; myimage_latest.tar.gz<\/em> for each OpenShift required image) and, when installing the virtual machine again, I directly loaded OpenShift images to my local docker instance (using <em>docker load -i myimage_latest.tar.gz<\/em>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfunction prerequisites(){\n\tcd ~\n\t\n\toc version 2>&amp;1 1>\/dev\/null\n\tif &#91; $? -ne 0 ] ; then\n\t\techo \"OpenShift is not installed... Exiting\"\n\t\texit 1\n\tfi\n\t\n\t&#91;&#91; -z ${ETH_INTERFACE_NAME} ]] &amp;&amp; { echo \"ETH_INTERFACE_NAME is not set or empty\"; exit 1; }\n\t\n\texport ETH_INTERFACE_IP=$(ip -4 addr show ${ETH_INTERFACE_NAME} | grep -Po 'inet \\K&#91;\\d.]+')\n}\n\nfunction configure_openshift(){\n\n\t# Installing Docker images from tar.gz archives\n\tif &#91; -d ${OPENSHIFT_DOCKER_ARCHIVES} ] ; then\n\t\n\t\t# Loading OpenShift images to Docker\n\t\tfind ${OPENSHIFT_DOCKER_ARCHIVES} -type f -name \"openshift_origin*.tar.gz\" -exec docker load -i  {} \\;\n\tfi\n\t\n\t# Starting OpenShift Origin local cluster\n\toc cluster up --public-hostname=${ETH_INTERFACE_IP} --routing-suffix=${ETH_INTERFACE_IP}.xip.io\n}\n\nprerequisites\nconfigure_openshift<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing the console<\/h3>\n\n\n\n<p>After the &#8220;oc cluster up&#8221; command, the console output should indicate how to connect to the OKD console.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"379\" height=\"226\" src=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image.png\" alt=\"\" class=\"wp-image-372\" srcset=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image.png 379w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-300x179.png 300w\" sizes=\"auto, (max-width: 379px) 100vw, 379px\" \/><\/figure><\/div>\n\n\n\n<p>When connecting to https:\/\/192.168.99.111:8443\/console using my web browser, the console is displayed, allowing me to enter my credentials.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"412\" src=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-1-1024x412.png\" alt=\"\" class=\"wp-image-373\" srcset=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-1-1024x412.png 1024w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-1-300x121.png 300w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-1-768x309.png 768w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-1-1536x618.png 1536w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-1-500x201.png 500w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-1.png 1737w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>Let&#8217;s try to connect with &#8220;Romain&#8221; as username and &#8220;mysecretpassword&#8221; as password.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"573\" src=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-2-1024x573.png\" alt=\"\" class=\"wp-image-374\" srcset=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-2-1024x573.png 1024w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-2-300x168.png 300w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-2-768x430.png 768w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-2-500x280.png 500w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-2.png 1309w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>YES ! I&#8217;m able to connect to my OpenShift platform with my new credentials. To be sure that all is working fine, create a new project and try to deploy an app (I tried with &#8220;Apache HTTP Server&#8221;). After some network configuration to resolve the httpd route, httpd home page is displayed.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"450\" src=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-3.png\" alt=\"\" class=\"wp-image-375\" srcset=\"https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-3.png 873w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-3-300x155.png 300w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-3-768x396.png 768w, https:\/\/blog.xoupix.fr\/wp-content\/uploads\/2020\/04\/image-3-500x258.png 500w\" sizes=\"auto, (max-width: 873px) 100vw, 873px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s see how to install OKD on a CentOS virtual machine !<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,23],"tags":[19,20],"class_list":["post-367","post","type-post","status-publish","format-standard","hentry","category-docker","category-openshift","tag-docker","tag-openshift"],"_links":{"self":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts\/367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":10,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":391,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts\/367\/revisions\/391"}],"wp:attachment":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}