【k8s】单节点部署k8s

单节点部署k8s

1. 内网系统中建议关闭防火墙服务
systemctl disable firewalld
systemctl stop firewalld
2. 安装etcd和Kubernetes (自动安装Docker)
yum install -y etcd kubernetes
3. 修改两个配置文件
vi /etc/sysconfig/docker

将OPTIONS设置为:OPTIONS=’–selinux-enabled=false --insecure-registry gcr.io’

vi /etc/kubernetes/apiserver

将 --admission_control 参数中的 ServiceAccount 删除

若不修改这个配置文件,后续创建pod的时候会报错

Error from server (ServerTimeout): error when creating "nginx_pod.yaml": No API token found for service account "default", retry after the token is automatically created and added to the service account
4. 按顺序启动如下服务
systemctl start etcd
systemctl start docker
systemctl start kube-apiserver
systemctl start kube-controller-manager
systemctl start kube-scheduler
systemctl start kubelet
systemctl start kube-proxy
5. 执行

安装python-rhsm-certificates

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
rpm2cpio /mnt/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64 | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
6. 创建nginx_pod.yaml

创建pod相应目录

mkdir k8s
cd k8s
mkdir pod
cd pod
vim nginx_pod.yaml

编辑nginx_pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: web
spec:
  containers:
    - name: nginx
      image: nginx:1.13
      ports:
        - containerPort: 80

:wq退出保存

7. 创建pod并验证

创建pod

kubectl create -f nginx_pod.yaml 

查看已创建pod

kubectl get pod
NAME      READY     STATUS    RESTARTS   AGE
nginx     1/1       Running   0          10h

查看组件状态

kubectl get componentstatus
NAME                 STATUS    MESSAGE             ERROR
etcd-0               Healthy   {"health":"true"}   
controller-manager   Healthy   ok                  
scheduler            Healthy   ok  

查看node

kubectl get node
NAME        STATUS    AGE
127.0.0.1   Ready     10h
8. 创建replicationController
kubectl create -f nginx-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-controller
spec:
  replicas: 2
  selector:
    name: nginx
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
9. 创建service
kubectl create -f nginx-service-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service-nodeport
spec:
  ports:
    - port: 8000
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    name: nginx
10. 最终验证
kubectl get service
NAME                     CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes               10.254.0.1       <none>        443/TCP          10h
nginx-service-nodeport   10.254.167.216   <nodes>       8000:32683/TCP   6m
kubectl describe service nginx-service-nodeport
Name:			nginx-service-nodeport
Namespace:		default
Labels:			<none>
Selector:		name=nginx
Type:			NodePort
IP:			10.254.167.216
Port:			<unset>	8000/TCP
NodePort:		<unset>	32683/TCP
Endpoints:		172.17.0.3:80,172.17.0.4:80
Session Affinity:	None
No events.
curl 10.0.16.2:32683
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

至此表明单节点k8s部署nginx成功

参考文献

【1】k8s部署nginx集群

【2】单节点安装k8s

【3】[Kubernetes(k8s)常用资源的使用、Pod的常用操作

【4】Kubernetes3-kubectl管理Kubernetes容器平台-1

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值