Deploy Kubernetes on CentOS7

VMs for kubernetes
# Setup repository for kubernetescat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
Kubernetes Deployment
# Set SELinux in permissive mode (effectively disabling it)setenforce 0
sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/’ /etc/selinux/config
Kubernetes Deployment
# Install kubernetes commandsyum install kubelet kubeadm kubectl -y
Kubernetes Deployment
Kubernetes Deployment
# Start kubelet service when rebootingsystemctl enable --now kubelet
Kubernetes Deployment
# Load the br_netfiler modulemodprobe br_netfilter
lsmod | grep br_netfilter
Kubernetes Deployment
# To make sure traffic is routed correctlycat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
Kubernetes Deployment
# Enable the settingsysctl --system
Kubernetes Deployment
# Add Docker repositoryyum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Kubernetes Deployment
# Install Docker CE
yum install docker-ce -y
Kubernetes Deployment
Kubernetes Deployment
# Enable, start docker and kubelet servicesystemctl enable docker.service
systemctl restart docker
systemctl enable kubelet
systemctl start kubelet
Kubernetes Deployment
# Initial master nodekubeadm init
Kubernetes Deployment
Kubernetes Deployment
# If you are running as root, enter this command in order for kubeadm commands to workexport KUBECONFIG=/etc/kubernetes/admin.conf
Kubernetes Deployment
# Deploy a pod network to the clusterkubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
Kubernetes Deployment
# Install necessary packagesyum install yum-utils device-mapper-persistent-data lvm2
Kubernetes Deployment
Kubernetes Deployment
# Create /etc/docker directory & setup daemon
# Restart docker service
mkdir /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
systemctl daemon-reload
systemctl restart docker
Kubernetes Deployment
# Finally, add worker node to kubernetes cluster by using the command generated from master node after kubeadm init commandkubeadm join 172.31.39.53:6443 --token 2nkiam.xxxxx \
--discovery-token-ca-cert-hash sha256:266c7d0a89f26976fa8b5952f6xxxxx
Kubernetes Deployment
# Get the list and status of nodeskubectl get nodes
Kubernetes Deployment
# Create a container running sample image at port 8080
kubectl run node-hello --image=gcr.io/google-samples/node-hello:1.0 --port=8080
# Expose pod to outside world, external ip is the local ip of node server
kubectl expose deployment.apps/node-hello --type="NodePort" --port 8080 --external-ip=172.31.40.107
Kubernetes Deployment
Kubernetes Deployment

--

--

--

AWS Certified SA, SysOps & Developer Associate, Alibaba Cloud certified SA. Focusing on Azure, Prometheus w/ Grafana, ELK and K8S now.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Managing Application Services and Cloud Infra using Dockers — Part 1

Never, however, have I seen patients as sick as those with COVID-19

READ/DOWNLOAD![

Press Release: Propel Announces Training Records to Maintain Regulatory Compliance and Manage…

Minimal Programming Kit

Programming Kit — VSCode editor.

JVM Architecture and it’s Working

Can Terminal Break?

Building a Questionnaire in Neo4j — part 2/3: A static list

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yst@IT

Yst@IT

AWS Certified SA, SysOps & Developer Associate, Alibaba Cloud certified SA. Focusing on Azure, Prometheus w/ Grafana, ELK and K8S now.

More from Medium

Kubernetes State Of The Union — KubeCon 2019, San Diego

Using AWS EBS Volumes in Kubernetes To Store Persistent Data for Kubernetes Versions < 1.23

Docker Security and K8 Security Contexts

Securing Kubernetes Secrets with HashiCorp Vault