ansible镜像构建使用

js 复制代码
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

再来一个k8s文件

js 复制代码
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

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

js 复制代码
secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: k8s-prod-pem-secret
type: Opaque
data:
  k8s.pem: LS0tLS1CRUdJTiBSU0EgUFJ
  
  #转化密钥
#cat k8.pem | base64 -w 0
或者直接一条命令
shell 复制代码
kubectl create configmap k8s-prod-pem-configmap --from-file=k8s.pem -n devops-tools

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

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

AWS 服务器器使用

js 复制代码
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
相关推荐
SRExianxian1 小时前
kubernetes存储架构之PV controller源码解读
容器·架构·kubernetes
cdg==吃蛋糕3 小时前
docker代理配置
docker·容器·eureka
ether-lin4 小时前
DevOps实战:用Kubernetes和Argo打造自动化CI/CD流程(2)
kubernetes·自动化·devops
web135085886354 小时前
使用docker compose安装gitlab
docker·容器·gitlab
IT机器猫4 小时前
Docker完整技术汇总
运维·docker·容器
董健正4 小时前
Docker安装
docker·容器·docker-compose
gs801405 小时前
替换 Docker.io 的 Harbor 安全部署指南:域名与 IP 双支持的镜像管理解决方案
docker·harbor
coco_1998_25 小时前
nvidia docker, nvidia docker2, nvidia container toolkits区别
docker·容器
团儿.5 小时前
Docker服务发现新纪元:探索Consul的无限魅力
运维·docker·云计算·服务发现·consul
vvw&6 小时前
Docker Build 命令详解:在 Ubuntu 上构建 Docker 镜像教程
linux·运维·服务器·ubuntu·docker·容器·开源