• ansible镜像构建使用


    cat << EOF >Dockerfile
    
    FROM alpine:latest
    
    RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories \
        && echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories \
        && apk add --no-cache ansible openssh sshpass bash-doc \
        && apk update \
        && apk add tzdata \
        && mkdir /etc/ansible \
        && echo "StrictHostKeyChecking no" > /etc/ssh/ssh_config
     
    #如何你是AWS账号就要copy密钥(不是的话就忽略)
    #COPY k8s.pem /opt/k8s.pem
    EOF
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    再来一个k8s文件

    cat << EOF > config.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: ansible-hosts-configmap
    data:
      hosts: |
        [aws]
        57.11.11.11    ansible_ssh_private_key_file=/opt/k8s.pem
        57.11.11.11    ansible_ssh_user=admin
    EOF
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    如果你不是AWS的服务器可以跳过这里

    secret.yaml
    apiVersion: v1
    kind: Secret
    metadata:
      name: k8s-prod-pem-secret
    type: Opaque
    data:
      k8s.pem: LS0tLS1CRUdJTiBSU0EgUFJ
      
      #转化密钥
    #cat k8.pem | base64 -w 0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    或者直接一条命令
    kubectl create configmap k8s-prod-pem-configmap --from-file=k8s.pem -n devops-tools
    
    • 1

    不是AWS服务器使用这个yaml运行

    cat << EOF > test.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: ansible
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: ansible
      template:
        metadata:
          labels:
            app: ansible
        spec:
          volumes:
            - name: ansible-hosts
              configMap:
                name: ansible-hosts-configmap
            - name: k8s-prod-pem
              configMap:
                name: k8s-prod-pem-configmap
          containers:
            - name: ansible
              image: registry.cn-shenzhen.aliyuncs.com/jbjb/dockers:ansible-v01
              command: ["sleep", "3333"]
              volumeMounts:
                - name: ansible-hosts
                  mountPath: /etc/ansible/hosts
                  subPath: hosts
                - name: k8s-prod-pem
                  mountPath: /opt/k8s.pem
                  subPath: k8s.pem
                  readOnly: true
    EOF
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    AWS 服务器器使用

    cat << EOF > test.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: ansible
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: ansible
      template:
        metadata:
          labels:
            app: ansible
        spec:
          volumes:
            - name: ansible-hosts
              configMap:
                name: ansible-hosts-configmap
          containers:
            - name: ansible
              image: registry.cn-shenzhen.aliyuncs.com/jbjb/dockers:ansible-v01
              command: ["sleep", "3333"]
              volumeMounts:
                - name: ansible-hosts
                  mountPath: /etc/ansible/hosts
                  subPath: hosts
    EOF
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
  • 相关阅读:
    Vue数据响应Object.defineProperty
    [ECCV2022]Language-Driven Artistic Style Transfer
    适用于医美行业的微信管理系统
    【Python爬虫】第二课 网络编程基础
    shell
    MySQL常用字符串函数
    自动控制原理8.4---描述函数法
    Redis 分布式锁过期了,还没处理完怎么办?
    C++ 语法基础课 习题1 —— 变量、输入输出、顺序语句
    freertos源码下载和目录结构分析
  • 原文地址:https://blog.csdn.net/weixin_42562106/article/details/134065995