(12)coredns部署

安装

下载相关安装文件

cd /opt/k8s-playbook
git clone https://github.com/coredns/deployment.git
mv deployment coredns-deployment

开始部署

cd coredns-deployment
./deploy.sh -i 10.254.0.2 -d zhfi.k8s. | kubectl apply -f -

-i: 集群dns地址
-d: 自定义域名

验证

安装nginx

vim my-nginx.yaml
##############################
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    run: nginx
spec:
  selector:
    run: nginx
  ports:
  - name: http
    port: 80
    targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      run: nginx
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80
##############################

kubectl apply -f my-nginx.yaml

安装dnsutils工具

vim my-dnsutils.yaml
##############################
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dnsutils
spec:
  selector:
    matchLabels:
      app: dnsutils
  template:
    metadata:
      labels:
        app: dnsutils
    spec:
      containers:
      - name: my-dnsutils
        image: tutum/dnsutils
        command:
          - sleep
          - "3600"
##############################

kubectl apply -f my-dnsutils.yaml

验证nginx服务名是否能被识别

查看service负载的地址是否正常

展示评论