K8

centos8搭建单机k8s

2022-05-11  本文已影响0人  孙广宁

一、单机安装k8s

[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
swapoff -a
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager -y --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum -y install docker-ce-18.06.3.ce-3.el7 docker-ce-cli-18.06.3.ce-3.el7 containerd.io
systemctl start docker
systemctl enable docker
yum -y install kubelet-1.13* kubeadm-1.13* kubectl-1.13*
systemctl start kubelet
systemctl enable kubelet
docker pull mirrorgooglecontainers/kube-apiserver:v1.13.3
docker pull mirrorgooglecontainers/kube-controller-manager:v1.13.3
docker pull mirrorgooglecontainers/kube-scheduler:v1.13.3
docker pull mirrorgooglecontainers/kube-proxy:v1.13.3
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/etcd:3.2.24
docker pull coredns/coredns:1.2.6
docker tag mirrorgooglecontainers/kube-apiserver:v1.13.3 k8s.gcr.io/kube-apiserver:v1.13.3
docker tag mirrorgooglecontainers/kube-controller-manager:v1.13.3 k8s.gcr.io/kube-controller-manager:v1.13.3
docker tag mirrorgooglecontainers/kube-scheduler:v1.13.3 k8s.gcr.io/kube-scheduler:v1.13.3
docker tag mirrorgooglecontainers/kube-proxy:v1.13.3 k8s.gcr.io/kube-proxy:v1.13.3
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
docker tag coredns/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6
kubeadm init --kubernetes-version=v1.13.3
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')
[root@apollo-db ~]# kubectl get nodes
NAME        STATUS   ROLES    AGE   VERSION
apollo-db   Ready    master   2d    v1.13.12
[root@apollo-db ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                READY   STATUS    RESTARTS   AGE
kube-system   coredns-86c58d9df4-5nxv9            1/1     Running   0          2d
kube-system   coredns-86c58d9df4-grjwn            1/1     Running   0          2d
kube-system   etcd-apollo-db                      1/1     Running   0          2d
kube-system   kube-apiserver-apollo-db            1/1     Running   0          2d
kube-system   kube-controller-manager-apollo-db   1/1     Running   0          2d
kube-system   kube-proxy-x9dd8                    1/1     Running   0          2d
kube-system   kube-scheduler-apollo-db            1/1     Running   0          2d
kube-system   weave-net-mpmzq                     2/2     Running   2          2d
[root@apollo-db ~]#
kubectl taint nodes --all node-role.kubernetes.io/master-

二、 helm测试

wget https://storage.googleapis.com/kubernetes-helm/helm-v2.11.0-linux-amd64.tar.gz
tar -zxvf helm-v2.11.0-linux-amd64.tar.gz
cd linux-amd64/
cp helm /usr/local/bin/
helm repo add apphub https://apphub.aliyuncs.com
[root@apollo-db ~]# helm repo list
NAME    URL
apphub  https://apphub.aliyuncs.com
helm repo remove aliyun  
helm repo update
[root@apollo-db ~]# helm search repo nginx
NAME                            CHART VERSION   APP VERSION             DESCRIPTION
apphub/nginx                    5.1.5           1.16.1                  Chart for the nginx server
apphub/nginx-ingress            1.30.3          0.28.0                  An nginx Ingress controller that uses ConfigMap...
apphub/nginx-ingress-controller 5.3.4           0.29.0                  Chart for the nginx Ingress controller
apphub/nginx-lego               0.3.1                                   Chart for nginx-ingress-controller and kube-lego
apphub/nginx-php                1.0.0           nginx-1.10.3_php-7.0    Chart for the nginx php server
[root@apollo-db ~]# helm install appnginx apphub/nginx
NAME: appnginx
LAST DEPLOYED: Wed May 11 22:08:20 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Get the NGINX URL:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w appnginx'

  export SERVICE_IP=$(kubectl get svc --namespace default appnginx --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
  echo "NGINX URL: http://$SERVICE_IP/"
[root@apollo-db ~]#
[root@apollo-db ~]# helm list
NAME        NAMESPACE   REVISION    UPDATED                                 STATUS      CHART       APP VERSION
appnginx    default     1           2022-05-11 22:08:20.248320947 +0800 CST deployed    nginx-5.1.5 1.16.1
[root@apollo-db ~]#
[root@apollo-db ~]# kubectl get pod
NAME                        READY   STATUS    RESTARTS   AGE
appnginx-65cbf4d8d8-c2vqr   1/1     Running   0          66s
[root@apollo-db ~]# kubectl get svc
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
appnginx     LoadBalancer   10.108.252.26   <pending>     80:31380/TCP,443:31180/TCP   69s
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP                      2d
[root@apollo-db ~]# kubectl get deploy
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
appnginx   1/1     1            1           103s
[root@apollo-db ~]#
[root@apollo-db ~]# helm uninstall appnginx
release "appnginx" uninstalled
[root@apollo-db ~]#
上一篇下一篇

猜你喜欢

热点阅读